//Front end Java Script File


/* error color variable showed in form fields*/
err_color = "#000";
var err_msg='';
var temp_value='';
var majorVersion='';
var bodyId='';

jQuery(document).ready(function() 
{

	//call to body background image
	$('#supersize').resizenow(); 

	//call to rounded corners 
	jQuery('li.demo').each(function() {
		jQuery(this).corner("10px");
	});	
	
	jQuery('a.demo').each(function() {
		jQuery(this).corner("10px");
	});	
	
	   		
});

//for getting the traiangles as of title width
jQuery(window).load(function(){
	
	if(document.getElementById("page_title"))
	{
		titleWidth=document.getElementById("page_title").offsetWidth;
		newWidth=Math.round(titleWidth/14)*14;
//		alert("new"+newWidth);
		if(newWidth>306)
			newWidth=306;
		
		jQuery(".heading_image").css("width",newWidth+"px");
	}
	
	if(document.getElementById("right_title"))
	{
		titleWidth=document.getElementById("right_title").offsetWidth;
		newRightWidth=Math.round(titleWidth/14)*14;
		
//		alert("right"+newRightWidth);
		
		if(newRightWidth>672)
			newRightWidth=672;
		
//		alert(newRightWidth);
		jQuery(".right_image").css("width",newRightWidth+"px");
	}
});

function showSpots(id)
{	
// //adding the selected class to wow-spots menu
	jQuery(".footer_menu").find("a").each(function(){
		jQuery(this).removeClass("selected");
	})
	jQuery("#wow_spots_card").addClass('selected');
	
	//checking the wow spots browsers wise	
	if (navigator.userAgent.indexOf("Opera")!=-1 ||  navigator.userAgent.indexOf("Safari")!=-1 ||  navigator.userAgent.indexOf("Firefox")!=-1)
	{
		if(document.getElementById("spots_overlay_s_o"))
		document.getElementById('spots_overlay_s_o').style.display="block";
		//document.getElementById('wow_spots_card').style.display="none";
	}
	else
	{
		if(document.getElementById("spots_overlay"))
		document.getElementById('spots_overlay').style.display="block";
		//document.getElementById('wow_spots_card').style.display="none";
	}
	
	bodyId=jQuery('body').attr("id");
	jQuery('body').attr("id","wow_spots");
}

//Front end Java Script File
function hidemap(id)
{
	
//	document.getElementById('main_video').style.display="block";
	//alert(navigator.userAgent);
	if (navigator.userAgent.indexOf("Opera")!=-1 ||  navigator.userAgent.indexOf("Safari")!=-1 ||  navigator.userAgent.indexOf("Firefox")!=-1)
		{
			document.getElementById('spots_overlay_s_o').style.display="none";
			//document.getElementById('wow_spots_card').style.display="block";
		}
	else
		{
			document.getElementById('spots_overlay').style.display="none";
			//document.getElementById('wow_spots_card').style.display="block";
		}
	
		jQuery('body').attr("id",bodyId);

}


jQuery(document).ready(function()
	{
		var spid='';
		var location_id='';
		var prev_spot='';
		//for getting the sub spot description
		jQuery(".sub").click(function(){
		jQuery(".sub").removeClass("spot_selected");						  
		//alert(jQuery(this).attr("innerHTML"));
		if(jQuery(this).attr("innerHTML")=="Algemeen")
		{
			cat=jQuery(this).attr("innerHTML");
			location_id=jQuery(this).attr("id");
			spid='';
			//getSubSpot(spid,location_id);
		}
		else
		{
		spid=jQuery(this).attr("id");
		spid=spid.split("_");
		//getSubSpot(spid[1],location_id);

		}
		prev_spot=this;
		jQuery(this).addClass("spot_selected");						  
		//return false;
		});
	
		
		var nVer = navigator.appVersion;
		var nAgt = navigator.userAgent;
		if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
		 browserName  = "Firefox";
		 fullVersion  = parseFloat(nAgt.substring(verOffset+8));
		 majorVersion = parseInt(''+fullVersion);
		}

		
		var imgAlt='';
		
		jQuery("img").attr({  
          alt: ""  
        }); 

		alphaBackgrounds();
		jQuery(".required").click(function()
			{
				elementid=this.id;
				temp_value=document.getElementById(elementid).value;
				if(temp_value=='Naam' || temp_value=='Email')
				document.getElementById(elementid).value='';
			});
		
			jQuery(".required").blur(function()
			{
			elementid=this.id;								
		
			if(document.getElementById(elementid).value=='')
			{
				if(temp_value=='Naam' || temp_value=='Email')
				document.getElementById(elementid).value=temp_value;
			}
			
		
		});
			
		if(document.getElementById("div_container"))
		{
			var objwidth=jQuery(".video object").attr("width");
			//for IE
			if(objwidth==undefined)
			objwidth=jQuery(".video embed").attr("width");
			
			if(objwidth>536)
			 {
				 jQuery("object").attr({"width":"536"});
				 jQuery("embed").attr({"width":"536"});
			 }
		}
		
		
	
	});

//function to validate the home page newsbrief form

function validateForm(obj)
{
	err_msg='';	
/*
	if(document.getElementById("name").value=='Naam' || document.getElementById("email_id").value=='Email')
	{
		err_msg="Please fill all the fields";
	}
	else if()
	
	if(err_msg!='')
	{
		document.getElementById("err_msg").style.display="block";
		return false;
	}
	else
	{
		document.getElementById("err_msg").style.display="none";
	}*/
	
	var form_valid 	= 10;  // 1 = valid , 0 =  invalid
	/* array of form fields which should be validated*/	
	var empty_fields=new Array("name","email_id");
	/* default values for form fields*/
	var empty_fields_value=new Array("Naam","Email");	
	for (i=0;i<empty_fields.length;i++)
	{
		fname=empty_fields[i];
		
		/* if field is empty or default value*/
		document.getElementById(fname).value = document.getElementById(fname).value.replace(/^\s+|\s+$/g, '') ;
		if (document.getElementById(fname).value=='' || document.getElementById(fname).value==empty_fields_value[i])
		{	
			//document.getElementById(fname).style.borderColor = err_color; 
			form_valid--; 
			err_msg="Vul a.u.b. het hele formulier in";
		}
		
		if (document.getElementById(fname).value!='' || document.getElementById(fname).value!=empty_fields_value[i])
		{
			if(fname=="email_id")
			{
					var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
					if(!document.getElementById("email_id").value.toUpperCase().match(regEmail))
					{	
						err_msg="Vul a.u.b. het hele formulier in";
						form_valid --;	
					}
			}
		}
			
	}
	
	
	if(form_valid!=10)
	{
		document.getElementById("err_msg").innerHTML=err_msg;
		return false;
	}
	
	if(err_msg=='')
	{
		return true;
	}

}


//function for validating the contact form	
function validateContactForm(obj)
{
	err_msg='';	

	if(document.getElementById("name").value=='' || document.getElementById("email_id").value=='' || document.getElementById("comments").value=="")
	{
		err_msg="Vul a.u.b. het hele formulier in";
	}
	
		if (document.getElementById("email_id").value!='')
		{
					var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
					if(!document.getElementById("email_id").value.toUpperCase().match(regEmail))
					{	
						err_msg+="<br/>"+"Vul een geldig e-mailadres in";
					}
		}
	
	if(err_msg!='')
	{
		document.getElementById("err_msg").innerHTML=err_msg;
		return false;
	}
	else
	{
		document.getElementById("err_msg").innerHTML="";
	}
	

}

/*------------------ png transparent script	----------------------*/

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) 
{
//window.onload("onload", alphaBackgrounds);
}

function alphaBackgrounds()
{
	var bname = navigator.appName;
	if (bname == "Microsoft Internet Explorer")
	{
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
		for (i=0; i<document.all.length; i++)
		{
			var cls=document.all[i].className;
			if(cls.indexOf("trans_png")==-1)
			{
			}
			else
			{
				var bg = document.all[i].currentStyle.backgroundImage;
				if (itsAllGood && bg)
				{
					if (bg.match(/\.png/i) != null)
					{
					var mypng = bg.substring(5,bg.length-2);
					document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
					document.all[i].style.backgroundImage = "url('')"; // change this to your own gif
					}
				}
			}
		}
	}
}
/*------------------ end of png transparent script	----------------------*/

var last_selected_sub_spot='';
//function for getting the sub spots details
function getSubSpot(sub_location_id,location_id)
{
	//updating the url
	//var spot_url=jQuery("#subspot_"+sub_location_id).attr("href");
	//jQuery("#subspot_"+sub_location_id).attr("href")=spot_url;
	//removing the class for the previous selected item
	//if (document.getElementById(last_selected_sub_spot))
		//jQuery("#"+last_selected_sub_spot).removeClass('spot_selected');
	
	//Checking if the div exists.  Check if the same exists, and continue..
	if(document.getElementById("spot_detail"))
	{
		jQuery.ajax({
				url: $w3_fe_url+"_includes/subspots.inc.php",
				type:'POST',
				data:{location_id:location_id,sub_location_id:sub_location_id},
				success: function(res) 
				{
					//adding selected class
					//jQuery("#subspot_"+sub_location_id).addClass("spot_selected");
					main_spot_desc=document.getElementById('spot_detail').innerHTML;
					document.getElementById('spot_detail').innerHTML = res;
					//alert("res"+res);
					//storing the id for the current selected for further use'
					last_selected_sub_spot="subspot_"+sub_location_id;
				},
				error: function (){ 
				//alert('something went wrong');
				}
				});	
	
	}
}

jQuery(document).ready(function() {
    //jQuery('#mycarousel').jcarousel();
});


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 5,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});



