// SETTING UP OUR POPUP  
// 0 means disabled; 1 means enabled;  
var popupStatus = 0;  

function hoverMouse(item, cursorPosition)
{
	if (cursorPosition=='on')
	{
		item.style.cursor = 'pointer';
	}
	else
	{
		item.style.cursor = 'default';
	}
}
function loadPopup(){  
	//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#backgroundPopup").css({  
		 "opacity": "0.7"  
		});  
	$("#backgroundPopup").fadeIn("slow");  
	$("#popupForm").fadeIn("slow");  
	popupStatus = 1;  
	}  
} 

function disablePopup(){  
	//disables popup only if it is enabled  
	if(popupStatus==1){  
		$("#backgroundPopup").fadeOut("slow");  
		$("#popupForm").fadeOut("slow");  
		popupStatus = 0;  
	}  
} 

//centering popup  
function centerPopup(){  
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#popupForm").height();  
	var popupWidth = $("#popupForm").width();  
	//centering  
	$("#popupForm").css({  
	 "position": "absolute",  
	 "top": windowHeight/2-popupHeight/2,  
	 "left": windowWidth/2-popupWidth/2  
	});  
	
	//only need force for IE6  	
	$("#backgroundPopup").css({  
	 "height": windowHeight  
	});  
} 

$(document).ready(function() {
	//LOADING POPUP  
	//Click the button event!  
	$("#butAssess").click(function(){  
		//centering with css  
		centerPopup();  
		//load popup  
		loadPopup();  
		$("#frmConsult").validate({
			rules:{
				txtName: "required",
				txtEmail: {
					required: true,
					email: true
				},
				age: {
					selectNone: true
				},
				skinType: {
					selectNone: true
				}
			}
			
		});
		
	jQuery.validator.addMethod(   
   "selectNone",   
   function(value, element) {   
     if (element.value == "")   
     {   
       return false;   
     }   
     else return true;   
   },   
   "<br/>Please select an option."  
	);  

	});  
	
	//CLOSING POPUP  
  //Click the x event!  
  $("#butClosePop").click(function(){  
		disablePopup();  
  });  
  
	//Click out event!  
  $("#backgroundPopup").click(function(){  
		disablePopup();  
  });  
  
	//Press Escape event!  
  $(document).keypress(function(e){  
		if(e.keyCode==27 && popupStatus==1){  
			disablePopup();  
		}  
  });  
	
	// Cancel button click
	$("#butCancel").click(function(){
		// Hide the form first
		disablePopup();
		//Clear the form
		$("form")[0].reset();
		$("#imgPopBack").attr("src", "images/popup/popBack1.jpg"); 
		$("#imgPage1").attr("src", "images/popup/markActive.gif"); 
		$("#imgPage5").attr("src", "images/popup/markInactive.gif"); 
		$("#consultPage1").css("display", "inline");
		$("#consultPage5").css("display", "none");
		
	});
});

function processForm(pageToDisplay) {
	// Depending on the page of the form that the user is on, we want to validate the data and move to the 
	// next page.
	$("#frmConsult").validate();
	switch (pageToDisplay) 
	{
		case 'page2':
			// Validate Page 1 items
			$("#frmConsult").validate().element("#skinType");
			
			$("#imgPopBack").attr("src", "images/popup/popBack2.jpg"); 
			$("#imgPage1").attr("src", "images/popup/markInactive.gif"); 
			$("#imgPage2").attr("src", "images/popup/markActive.gif"); 
			$("#consultPage1").css("display", "none");
			$("#consultPage2").css("display", "inline");
			break;
		case 'page3':
			$("#imgPopBack").attr("src", "images/popup/popBack3.jpg"); 
			$("#imgPage2").attr("src", "images/popup/markInactive.gif"); 	
			$("#imgPage3").attr("src", "images/popup/markActive.gif"); 
			$("#consultPage2").css("display", "none");
			$("#consultPage3").css("display", "inline");
			break;
		case 'page4':
			$("#imgPopBack").attr("src", "images/popup/popBack4.jpg"); 
			$("#imgPage3").attr("src", "images/popup/markInactive.gif"); 
			$("#imgPage4").attr("src", "images/popup/markActive.gif"); 
			$("#consultPage3").css("display", "none");
			$("#consultPage4").css("display", "inline");
			break;
		case 'page5':
			$("#imgPopBack").attr("src", "images/popup/popBack5.jpg"); 
			$("#imgPage4").attr("src", "images/popup/markInactive.gif"); 
			$("#imgPage5").attr("src", "images/popup/markActive.gif"); 
			$("#consultPage4").css("display", "none");
			$("#consultPage5").css("display", "inline");
			break;
		/*
		if(($("#frmConsult").validate().element("#txtName") == false)
			 || ($("#frmConsult").validate().element("#txtEmail") == false)
			 || ($("#frmConsult").validate().element("#age") == false))
			{
			return false;
			}
		*/
	}
}