/**********************************************/
function emailcheck(email) {
    if (email != null && email != "") {
        a = email.lastIndexOf("@");
        b = email.lastIndexOf(".");
        c = email.indexOf(":");
        d = email.indexOf("/");
        e = email.substring(0,a);
        f = e.indexOf("@");
        g = email.substring(a+1,email.length);
        h = g.indexOf("[");
        i = g.indexOf("]");
        j = g.indexOf("<");
        k = g.indexOf(">");
        l = email.substring(a+1,b);
        m = email.substring(b+1,email.length);
        n = email.substring(0,a);
        o = 0;
        if (a > b) {o++};
        if (c != -1) {o++};
        if (d != -1) {o++};
        if (f != -1) {o++};
        if (h != -1) {o++};
        if (i != -1) {o++};
        if (j != -1) {o++};
        if (k != -1) {o++};
        if (l.length < 2) {o++};
        if (m.length < 2) {o++};
        if (n.length < 1) {o++};
        if (o == 0) { return true; }
        else { return false; }
    }
    else { return false; }
}

/**********************************************/
function firstfocus(field)
{
	eval ("document.frm."+field+".focus();");
}

/**********************************************/
function popup(url,name,w,h) {
		var winW = (screen.width - w) / 2;
		var winH = (screen.height - h) / 2;
 		var popwin1 = window.open(url,name,'width='+w+',height='+h+',top='+winH+',left='+winW+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
		popwin1.focus();
	}
	
/**********************************************/
function sendfriend(){
	if(!emailcheck(document.frmsendfriend.email.value) || document.frmsendfriend.fromname.value=="your name") {
		alert("Please enter your name and a valid email address\n");
		return false;
		}
}

/**********************************************/
function bookmark(burl,btitle) {
	if (document.all)
		window.external.AddFavorite(burl,btitle)
}

/**********************************************/
function checkdate(fieldname,dependent_field) {
	eval ("day = document.frm."+fieldname+"_day.options[document.frm."+fieldname+"_day.selectedIndex].value;");
	eval ("month = document.frm."+fieldname+"_month.options[document.frm."+fieldname+"_month.selectedIndex].value;");
	eval ("year = document.frm."+fieldname+"_year.options[document.frm."+fieldname+"_year.selectedIndex].value;");

	if ((month == '4' || month == '6' || month == '9' || month == '11' ) && (day == '31'))
	{
   	eval ("document.frm."+fieldname+"_day.selectedIndex --;");
   	eval ("day = document.frm."+fieldname+"_day.options[document.frm."+fieldname+"_day.selectedIndex].value;");

	}
	if ((month == '2') && (day == '29' || day == '30' || day == '31') && ((year%4) == 0))
	{
	eval ("document.frm."+fieldname+"_day.selectedIndex = 28;");
	eval ("day = document.frm."+fieldname+"_day.options[document.frm."+fieldname+"_day.selectedIndex].value;");
	}
	else if ((month == '2') && (day == '29' || day == '30' || day == '31'))
	{
	eval ("document.frm."+fieldname+"_day.selectedIndex = 27;");
	eval ("day = document.frm."+fieldname+"_day.options[document.frm."+fieldname+"_day.selectedIndex].value;");
	}

    eval ("document.frm."+fieldname+"_day.value = day;");
	eval ("document.frm."+fieldname+".value = document.frm."+fieldname+"_year.value + \"-\" + document.frm."+fieldname+"_month.value + \"-\" + document.frm."+fieldname+"_day.value;");

	// set dependent_field
	if (dependent_field != "") {
    eval ("document.frm."+dependent_field+"_day.value = day;");
    eval ("document.frm."+dependent_field+"_month.value = month;");
    eval ("document.frm."+dependent_field+"_year.value = year;");
	eval ("document.frm."+dependent_field+".value = document.frm."+dependent_field+"_year.value + \"-\" + document.frm."+dependent_field+"_month.value + \"-\" + document.frm."+dependent_field+"_day.value;");

	}
	return new Date(year,month,day,00,00,00);
}


/**********************************************/
function checkdatetop(fieldname,dependent_field) {
	eval ("day = document.frmtop."+fieldname+"_day.options[document.frmtop."+fieldname+"_day.selectedIndex].value;");
	eval ("month = document.frmtop."+fieldname+"_month.options[document.frmtop."+fieldname+"_month.selectedIndex].value;");
	eval ("year = document.frmtop."+fieldname+"_year.options[document.frmtop."+fieldname+"_year.selectedIndex].value;");
	
	if ((month == '4' || month == '6' || month == '9' || month == '11' ) && (day == '31'))
	{
   	eval ("document.frmtop."+fieldname+"_day.selectedIndex --;");
   	eval ("day = document.frmtop."+fieldname+"_day.options[document.frmtop."+fieldname+"_day.selectedIndex].value;");

	}
	if ((month == '2') && (day == '29' || day == '30' || day == '31') && ((year%4) == 0))
	{
	eval ("document.frmtop."+fieldname+"_day.selectedIndex = 28;");
	eval ("day = document.frmtop."+fieldname+"_day.options[document.frmtop."+fieldname+"_day.selectedIndex].value;");

	}
	else if ((month == '2') && (day == '29' || day == '30' || day == '31'))
	{
	eval ("document.frmtop."+fieldname+"_day.selectedIndex = 27;");
	eval ("day = document.frmtop."+fieldname+"_day.options[document.frmtop."+fieldname+"_day.selectedIndex].value;");
	}

    eval ("document.frmtop."+fieldname+"_day.value = day;");
	eval ("document.frmtop."+fieldname+".value = document.frmtop."+fieldname+"_year.value + \"-\" + document.frmtop."+fieldname+"_month.value + \"-\" + document.frmtop."+fieldname+"_day.value;");

	// set dependent_field
	if (dependent_field != "") {
    eval ("document.frmtop."+dependent_field+"_day.value = day;");
    eval ("document.frmtop."+dependent_field+"_month.value = month;");
    eval ("document.frmtop."+dependent_field+"_year.value = year;");
	eval ("document.frmtop."+dependent_field+".value = document.frmtop."+dependent_field+"_year.value + \"-\" + document.frmtop."+dependent_field+"_month.value + \"-\" + document.frmtop."+dependent_field+"_day.value;");
	}
	return new Date(year,month,day,00,00,00);
}

/**********************************************/
function check2dates(date_from,date_to) {
	to = checkdate(date_to,"");
	from = checkdate(date_from,"");
	diff = to - from;
	
	// if dates are not in the correct order
	if (diff <= 0)	{ return false; }
	// if dates are in the correct order
	else { return true; }
}

/**********************************************/
function get_radio_value(field_name)
{
	eval("for (var i=0; i < document.frm."+field_name+".length; i++) { if (document.frm."+field_name+"[i].checked) var radio_val = document.frm."+field_name+"[i].value; }");
	return radio_val;
}

/**********************************************/

function checkformtop() {
	msg = "";

	if (!check2dates("arrival_date_top","depart_date_top")) msg = msg + "- Dates from and to\n";
	if (document.frmtop.num_adults_top.value == "0" && document.frmtop.num_children_top.value == "0" )  msg = msg + "- No of adults and children\n";

	// display the form check	
	if (msg!="")
		{
		alert ("Please complete the following:\r\n\r\n"+msg);
		return false;
		}
}