/*
	javascript development
	============================
	website 	: 	Fantasy Travel
	date 		: 	23-12-2009		
	author 		: 	mayra metaxa / developer
	company		: 	mozaik creative business solutions
	url			:	http://www.mozaik.com

*/


function tab_blocks(id, howmany)
{
	for (i=1; i<=howmany; i++)
	{
		document.getElementById("tab_content_"+i).style.display = "none";
		document.getElementById("tablink_"+i).className = "";
	}
		
	document.getElementById("tab_content_"+id).style.display = "block";
	document.getElementById("tablink_"+id).className = "loc";	
	
}


/* ========= FORM functions ========= */

function show_error(id)
{
	document.getElementById(id).style.background="#ECE5DC";
}

function clear_errors(which)
{
	for (i=0;i<document.forms[which].elements.length;i++)
	{
		if ( (document.forms[which].elements[i].type != "button") && (document.forms[which].elements[i].type != "reset") && (document.forms[which].elements[i].id!="fieldset") && (document.forms[which].elements[i].type!="textarea") )
			document.forms[which].elements[i].style.background="#EEEEEE";
	}
}


function checkEmail(elem)
{
   var field = document.getElementById(elem);
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   if (field.value.length ==0)
		return false;

   if(field.value.match(emailExp))
		return true;
   else 
		return false;
   
}


function check_form(formid, whichform, mandatory_fields, numericfields, emailid)
{
	clear_errors(whichform);
	
	//check mandatory fields
	var man = mandatory_fields.split(",");
	for (i=0;i<man.length;i++)
	{
		if (document.getElementById(man[i]).value == "")
		{
			show_error(man[i]);
			alert ("You must fill all the mandatory fields (*)");
			return false;
		}
	}		

	if (emailid!="")
	{
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			alert ("Your email address is not valid.");
			return false;
		}
	}
	
	//check numeric fields
	if (numericfields != "")
	{
		var numeric = numericfields.split(",");
		for (i=0;i<numeric.length;i++)
		{
			document.getElementById(numeric[i]).value = document.getElementById(numeric[i]).value.replace(/,/,".");
			
			if (isNaN (document.getElementById(numeric[i]).value))
			{
				show_error(numeric[i]);
				alert (numeric[i]+": should be a number. Plase check and try again!");
				return false;
			}
		}
	}
	
	document.getElementById(formid).submit();
}


/*
function printPage(printWindow) 
{
	if(window.frames[printWindow].location != '' && (window.frames[printWindow].document.readyState == 'complete' || window.frames[printWindow].document.readyState == undefined)) 
	{
		window.frames[printWindow].focus();
		window.frames[printWindow].print();

	}
	else {
		alert('The page is still loading. Please wait until the transfer is completed.'); 
	}
}

*/


/* ============================= */

function chgFnt(x) 
{
	x = Number(x);
    var bodyID = document.body;
    setCookie(x);
	
	for (i=1; i<=3; i++)
		document.getElementById('tsdd_'+i).className = '';
	
    switch(x) 
	{
        case 1:
            bodyID.style.fontSize="9px";
			document.getElementById('menuid').style.fontSize = '11px';
			document.getElementById('topmenuid').style.fontSize = '9px';
            break;
        case 2:
            bodyID.style.fontSize="11px";
			document.getElementById('menuid').style.fontSize = '13px';
			document.getElementById('topmenuid').style.fontSize = '11px';
            break;
        case 3:
            bodyID.style.fontSize="13px";
			document.getElementById('menuid').style.fontSize = '15px';
			document.getElementById('topmenuid').style.fontSize = '13px';
            break;
    }
	
	document.getElementById('tsdd_'+x).className = 'dd_sel';
		
    return false;
}


//saves the font size preference to a cookie, expires in one year
function setCookie(x) {
    var nextyear = new Date();
    nextyear.setFullYear(nextyear.getFullYear() + 1);
    document.cookie = "iukbtext=" + x + "; expires=" + nextyear.toGMTString() + "; path=/";
}

//sets the font size according to the cookie value, called by onload
function setFontSize() {
    var allCookies = document.cookie;
    var pos = allCookies.indexOf("iukbtext=");
    if (pos != -1) {
        var start = pos + 9;
        var end = allCookies.indexOf(";", start);
        if (end == -1) end = allCookies.length;
        var value = allCookies.substring(start, end);
        chgFnt(value);
    }
}

