// JavaScript Document
popup=0;
/*-------------------------------------
Feedback
---------------------------------------*/

function showFeedback(whichForm,id){
	popup=1;
	//OpenTestPopup();
	var windowSize = getWindowSize();
	
	var totalHeight = Window.getScrollHeight();
	var totalWidth = window.screen.width;
	if(windowSize.X <978){
		totalWidth = 1000;
	}
	
	var feedbackX = (totalWidth/2 - 770/2);
	if(whichForm=="trips"){
		var feedbackY = (totalHeight/2 - 480/2);
	}else{
		var feedbackY = (totalHeight/2 - 500/2);
	}
	//var feedbackY = feedbackY - 100;
	
	
	document.getElementById("fade").style.height = totalHeight + "px";
	document.getElementById("fade").style.width = totalWidth + "px";
	document.getElementById("fade").style.display='block';
	
	leftPos = ((Window.getWindowWidth() / 2) - 365)+Window.getScrollLeft();
	topPos = ((Window.getWindowHeight() / 2) - 220)+Window.getScrollTop();
	
	document.getElementById("lightBox").style.top = topPos + 'px';
	document.getElementById("lightBox").style.left = leftPos + 'px';
	
	

	document.getElementById("lightBox").style.display='block';
	document.getElementById("formLoader").style.display='block';
   
	
	generateForm(whichForm,id)

}

function hideFeedback(){
	var myform = window.parent.document.getElementById("formLoader");
	var mydiv = window.parent.document.getElementById("lightBox");
	var fader = window.parent.document.getElementById("fade");
	myform.innerHTML=""
	myform.style.display='none';
	mydiv.style.display='none';
	fader.style.display='none';
	
	
}

function generateForm(whichForm,id){
	var myform = document.getElementById("formLoader");
	var mydetailsbox= document.getElementById("detailsBox");
	var returnmessage = document.getElementById("backmessage");
	
	
	
	if(whichForm=="trips"){
	//alert(whichForm);
	myform.innerHTML="<iframe id='myframe' src='trips_details.php?id="+id+"' height=480 width=770 frameborder=0 scrolling=no marginheight=0 marginwidth=0></iframe>";
	return false;
	}
	
	else if(whichForm=="reisvoorwaarden"){
	myform.innerHTML="<iframe id='myframe' src='reisvoorwaarden.php' height=520 width=770 frameborder=0 scrolling=auto marginheight=0 marginwidth=0></iframe>";
	//alert(whichForm);
	//returnmessage.innerHTML="back to gallery";
	}
	
	else if(whichForm=="verzekeringsmogelijkheden"){
	myform.innerHTML="<iframe id='myframe' src='verzekeringsmogelijkheden.php' height=520 width=770 frameborder=0 scrolling=auto marginheight=0 marginwidth=0></iframe>";
	//alert(whichForm);
	//returnmessage.innerHTML="back to gallery";
	}
	
	else if(whichForm=="guestbook"){
	myform.innerHTML="<iframe id='myframe' src='includes/guestbookForm.php' height=520 width=770 frameborder=0 scrolling=auto marginheight=0 marginwidth=0></iframe>";
	//alert(whichForm);
	//returnmessage.innerHTML="back to gallery";
	}
	
   //alert(mydiv.innerHTML);
}

function resetSize(what){
	//alert(what);
	if(what=="trips"){
		document.getElementById("detailsBox").style.height = 380 + "px";
		
	}
	
	else if(what=="gallery"){
	
		document.getElementById("detailsBox").style.height = 420 + "px";
		
	}
}
//To get window size
function getWindowSize()
{
  var myWidth = 0, myHeight = 0;
 
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
       //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth ;
        myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
  }
 
  var X= myWidth;
  var Y= myHeight;
 
  return {X:X, Y:Y};
}

Window = {	
	//Returns an integer representing the width of the browser window (without the scrollbar).
	getWindowWidth : function() {
	return (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	},
	
	//Returns an integer representing the height of the browser window (without the scrollbar).
	getWindowHeight : function() {	
	return window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
	},	
	
	//Returns an integer representing the scrollWidth of the window. 
	getScrollWidth : function() {
		return document.all ? Math.max(Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth), Math.max(document.body.offsetWidth, document.body.scrollWidth)) : (document.body ? document.body.scrollWidth : ((document.documentElement.scrollWidth != 0) ? document.documentElement.scrollWidth : 0));
	},
	
	//Returns an integer representing the scrollHeight of the window. 
	getScrollHeight : function(){		
		return document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0));
	},			
	
	//Returns an integer representing the scrollLeft of the window (the number of pixels the window has scrolled from the left).
	getScrollLeft : function() {
		return document.all ? (!document.documentElement.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft) : ((window.pageXOffset != 0) ? window.pageXOffset : 0);
	},
	
	//Returns an integer representing the scrollTop of the window (the number of pixels the window has scrolled from the top).
	getScrollTop : function() {
		return document.all ? (!document.documentElement.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) : ((window.pageYOffset != 0) ? window.pageYOffset : 0);
	}
}
		
//Test function		
function OpenTestPopup() {
	alert("Window Width : " + Window.getWindowWidth() + " px\n"
		+ "Window Height : " + Window.getWindowHeight() + " px\n"
		+ "Scroll Width : " + Window.getScrollWidth() + " px\n"
		+ "Scroll Height : " + Window.getScrollHeight() + " px\n"
		+ "Scroll Left : " + Window.getScrollLeft() + " px\n"
		+ "Scroll Top : " + Window.getScrollTop() + " px");
}

/*
Function to validate guest book form
*/		

function valContactForm(){
	var name = document.getElementById("name").value;
	var emailid = document.getElementById("emailid").value;
	var captchCode = document.getElementById("recaptcha_response_field").value;
	
	if(name==""){
		showError("The Name cannot be left blank");
		document.getElementById("name").focus();
		changeError('name')
		return false;
	}else{
		changeProper('name')
	}
	
	if(emailid==""){
		showError("The Email Id cannot be left blank");
		document.getElementById("emailid").focus();
		changeError('emailid');
		return false;
	}else{
		changeProper('emailid')
	} 
	
	if(!isValidEmail(emailid))
	{
		showError("Invalid email address.");
		document.getElementById("emailid").focus();
		changeError('emailid')
		return false;
	}else{
		changeProper('emailid')
	}
	
	if(captchCode==""){
		showError("Captch code cannot be left blank");
		document.getElementById("recaptcha_response_field").focus();
		changeError('recaptcha_response_field')
		return false;
	}else{
		changeProper('recaptcha_response_field')
	}
	
	return true;
	//document.guest_form.submit();
}
//Function to opem guestbookForm

function openGuestBookForm(){
	var screenWidth = window.screen.width;
	var screenHeight = window.screen.height;
	
	var windowWidth = 450;
	var windowHeight = 500;
	
	var leftPos = (screenWidth/2 - windowWidth/2);
	var topPos = (screenHeight/2 - windowHeight/2);
	
	url="includes/guestbookForm.php";
	pune_mumbai_window= window.open (url,"guestForm","'titlebar=no,toolbar=no,status=0,menubar=0,scrollbars=0,width="+windowWidth+",height="+windowHeight+",left="+leftPos+",top="+topPos+""); 
}

/*
Function to validate guest book form
*/		

function valGuestBook(){
	var name = document.getElementById("name").value;
	var emailid = document.getElementById("emailid").value;
	var captchCode = document.getElementById("recaptcha_response_field").value;
		
	if(name==""){
		showError("The Name cannot be left blank");
		document.getElementById("name").focus();
		changeError('name')
		return false;
	}else{
		changeProper('name')
	}
	
	if(emailid==""){
		showError("The Email Id cannot be left blank");
		document.getElementById("emailid").focus();
		changeError('emailid');
		return false;
	}else{
		changeProper('emailid')
	} 
	
	if(!isValidEmail(emailid))
	{
		showError("Invalid email address.");
		document.getElementById("emailid").focus();
		changeError('emailid')
		return false;
	}else{
		changeProper('emailid')
	}
	
	if(captchCode==""){
		showError("Captch code cannot be left blank");
		document.getElementById("recaptcha_response_field").focus();
		changeError('recaptcha_response_field')
		return false;
	}else{
		changeProper('recaptcha_response_field')
	}
	
	return true;
	//document.guest_form.submit();
}

/*
Common Function to validate contact form
*/	
function trim(str)
{ 
	return((""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}

function isSpchar(value){
  var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isNumber(str){
	
//	var filter=/^[\d]+$/;
	var filter=/^[0-9]+$/;
	if(filter.test(trim(str)))
	return true;
	else
	return false;
}

function isNum(value){
  var iChars = "0123456789";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isValidEmail(value){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(trim(value)))
		return true;
	else
		return false;
	
}

function toogleElement(EleName,style){
	var objEle = document.getElementById(EleName);
	if(objEle)
		objEle.style.display=style;
}

function showNotification(msg){
	showStatus(msg,'statusMsg');
}
function showError(msg){
	showStatus(msg,'statusErr');
}
function showStatus(msg,type){

	var ele = document.getElementById('msg');
	ele.innerHTML = msg;
	ele.className = type;

	toogleElement('msg','block');
	try{
	increaseHeight()
	}catch(e){}
}

function changeError(id){
	document.getElementById(id).style.borderStyle="solid";
	document.getElementById(id).style.borderColor="red";
	}
function changeProper(id){
	document.getElementById(id).style.borderStyle="";
	document.getElementById(id).style.borderColor="";
	}

function showThanks(formdiv){
	toogleElement(formdiv,'none');
	toogleElement('thanks','block');
}
function showform(url){
//alert(parent.popup);
	if(parent.popup==1)
	{
	//	alert("calling show form");
		hideFeedback();
		popup=false;
	}else{
	location=url;
	}
}

function close_Thanks(){
	
	var count=0;
    var myInt = setInterval(function(){
									 count ++;
									 if(count==5){
										 clearInterval(myInt);
										 toogleElement('doneMsg','none');
										 //window.close();
									 }
									 },1000);
}

function showGuestForm(isShow){	
		
		if(isShow){
			toogleElement('myguestbook','block');
			toogleElement('showGuestBtn','block');
			
			toogleElement('guestDetails','none');
			toogleElement('signupBtn','none');
			toogleElement('guestlisting','none');
			
		}else{
			toogleElement('guestDetails','block');
			toogleElement('signupBtn','block');
			toogleElement('guestlisting','block');
			
			toogleElement('myguestbook','none');
			toogleElement('showGuestBtn','none');
		}
		
}
