﻿

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopupus(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContactus").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

function disablePopupus(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContactus").fadeOut("slow");
		popupStatus = 0;
	}
	clearpopup();
}
function callfastcontact()
{
centerPopupus();
		loadPopupus();
}
//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
function centerPopupus(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContactus").height();
	var popupWidth = $("#popupContactus").width();
	//centering
	$("#popupContactus").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		
		centerPopup();
		if(searchIndex())
		//load popup
		{loadPopup();}
	});
		$("#divinquiry").click(function(){
		//centering with css
		
		centerPopupus();
		loadPopupus();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
		disablePopupus();
	});
		$("#popupContactCloseus").click(function(){

		disablePopupus();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
		disablePopupus();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopupus();
		}
	});

});

function clearpopup()
{
document.formcontact.cname.value=" ";;
document.formcontact.cphone.value=" ";
document.formcontact.cemailid.value=" ";
document.formcontact.ccomment.value=" ";
document.formcontact.cpolicyno.value=" ";

}

function checkNewpop()
{

var Name=document.formcontact.cname.value;
var PhoneNo=document.formcontact.cphone.value;
var EmailID=document.formcontact.cemailid.value;
var Feedback=document.formcontact.ccomment.value;
var PolicyNo = document.formcontact.cpolicyno.value;
var ContactType=document.formcontact.ctype.value;
var Productname;
var reg = new RegExp("^[A-Za-z0-9_-]{1,}[.]?[A-Za-z0-9_-]{1,}@{1}([A-Za-z0-9_-]+[.]{1})+[A-Za-z0-9_-]{1,}$");
if((Name=="") ||!isNaN(Name) || (Name=="Name"))
{
alert("Please enter your name.");
document.formcontact.cname.focus();
return false;
}
else if(containsdigit(Name)==true)
{
alert("Name contains characters.");
document.formcontact.cname.focus();
return false;
}	
else if (Name.charAt(0)==" ")
{
alert("Name can not start with blank.")
document.formcontact.cname.focus();
return false;
}
 if(PhoneNo=="")
{
alert("Please enter your contact number.");
document.formcontact.cphone.focus();
return false;
}

if(EmailID=="")
{
alert("Please enter your email id.");
//document.formcontact.emailid.focus();
return false;
}
 else if(!reg.test(EmailID)) 
{
alert("Invalid email id. Please enter your correct email id.");
//document.formcontact.emailid.focus();
return false;
}	
 
 if(Feedback=="")
{
alert("Please enter your enquiry/feedback/suggestion.");
document.formcontact.ccomment.focus();
return false;
}
if(document.formcontact.ctype.value=="Claim")
{
 if(PolicyNo=="")
{
alert("Please enter your policy number.");
document.formcontact.cpolicyno.focus();
return false;
}
}
else
{
PolicyNo="";
}
if(document.formcontact.ctype.value=="other")
{
Productname ="";
PolicyNo="";
}
else
{
Productname =document.formcontact.Productslist.value;
}

 if ((document.formcontact.ccomment.value!="")&&(document.formcontact.ccomment.length>1000))
	 {
	 alert("Feedback cannot be greater than 1000 character.")
	 document.formcontact.ccomment.focus();
	 return false;
	 } 
	 else
	{ 
makeRequestClaim("Name="+Name+"&PhoneNo="+PhoneNo+"&Products="+Productname+"&EmailID="+EmailID+"&Feedback="+Feedback+"&PolicyNo="+PolicyNo+"&ContactType="+ContactType);
disablePopupus();
}
}