/*
	javascript development
	============================
	website 	: 	Grace Beijing
	date 		: 	14-7-2010		
	author 		: 	mayra metaxa / developer
	company		: 	mozaik creative business solutions
	url			:	http://www.mozaik.com

*/



function acc_descr(what)
{
	document.getElementById('acc_descr').innerHTML = what;
}


function openWindowPopup(page,name,width,height,scrollbars,resizable,callInit,centered) 
{	
	var configWidthHeight="";
	if(width!=-1 && height!=-1) {
		//new_window.resizeTo(width,height);
		configWidthHeight='height=' + height + ',width=' + width + ',';
	}
	var new_window = window.open (page, 'PopUp' + name, configWidthHeight + 'toolbar=no, menubar=no, scrollbars=' + scrollbars + ', resizable=' + resizable + ',location=no, directories=no, status=no');
	
}

/*
function intro_banners(id, url)
{
	if (id==1)
		var tracktag = '/virtual/banner-visit-group';
	else if (id==2)
		var tracktag = '/virtual/banner-visit-us-hotels';

	track_ga('', tracktag);
	
	window.open (url);
}*/


function track_ga(trackercat, tracktag)
{
	//category, action, opt_label, opt_value
	if (trackercat!="")
		_gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
		
	if (tracktag!="")
		_gaq.push(['_trackPageview', tracktag]);		
}


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

function show_error(id)
{
	document.getElementById(id).style.background="#B1E1F3";
	//document.getElementById(id).style.borderBottom="solid 1px #f62946";
	//f5f3ef
}

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="#ece9e4";
			//document.forms[which].elements[i].style.border="none";
		}
	}
}


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;
			}
		}
	}
	
	if (document.getElementById('flag_track'))
	{
		//var flag_track = document.getElementById('flag_track').value;
		//track_ga('', flag_track);
	}
	
	document.getElementById(formid).submit();
}


function aj_map()
{
	$.ajax({
		url: websiteURL+'ajax_map.php',
		type: 'GET',
		dataType: 'html',
		data: '',
		cache: false,
		beforeSend: function(){
			$('.embeded_map').html('<div style="text-align:center;"><img src="'+websiteURL+'images/loading.gif" alt="loading" /></div>');
		},
		error: function(){
			alert('Error triggered.');
		},
		success: function(reply) {
			$('.embeded_map').html(reply);
		}
	});
}
		
function show_map(action) 
{
	if (action==1)
	{					
		$('.slide_div, .sliding_overlay, .google_map').fadeOut(330);
	
		var c = $('.embeded_map').html();
		if (c=="")
			aj_map();
		
		$('.embeded_map, .map_back_btn').fadeIn(250);					
	}
	else
	{
		$('.embeded_map, .map_back_btn').fadeOut(200);			
		$('.slide_div, .sliding_overlay, .google_map').fadeIn(330);		
	}
}	

