function BlurPage(flg){
		var bDiv=document.getElementById("blurdiv");
		if(flg=='on'){
			bDiv.style.display="block";
			//setTimeout('BlurPage("off")',2000);
		}else{
			bDiv.style.display="none";
			//fnAfterAjax(result);
		}
		//bDiv.style.display="none";
	}
function ShowForm(){
	var wrapobject = document.getElementById("wrap");
	var tleft=findPosX(wrapobject);
	tleft=tleft+45;
	var ttop=findPosY(wrapobject);
	ttop=ttop+50;
	document.getElementById("needquote-main").style.left=tleft+"px";
	document.getElementById("needquote-main").style.top=ttop+"px";
	BlurPage('on');
	document.getElementById("needquote-main").style.display="block";
}
function HideForm(){
	BlurPage('off');
	document.getElementById("needquote-main").style.display="none";
}
function findPosX(obj)	{
	var curleft = 0;
	if(obj.offsetParent)
	while(1){
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.x)
	curleft += obj.x;
	return curleft;
}
function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	while(1){
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.y)
	curtop += obj.y;
	return curtop;
}


function validateOnlineBooking(){
	var bval=true;
	var company=document.book_online.company.value;
	var contact=document.book_online.contact_name.value;
	var phone=document.book_online.company_phone.value;
	var location=document.book_online.location.value;
	var job_contact=document.book_online.job_contact.value;
	var job_phone=document.book_online.job_phone.value;
	var len=document.book_online.urgency.length;
	var urgency=document.book_online.urgency;
	var comments=document.book_online.comments.value;
	
	if(company == '' || company == null){
		bval=false;
		alert('Please Fill Company Field');
	}
	if((contact == '' || contact == null) && bval == true){
		bval=false;
		alert('Please Fill Contact Name Field');
	}
	if((phone == '' || phone == null) && bval == true){
		bval=false;
		alert('Please Fill Telephone Field');
	}
	if((location == '' || location == null) && bval == true){
		bval=false;
		alert('Please Fill Location Field');
	}
	if((job_contact == '' || job_contact == null) && bval == true){
		bval=false;
		alert('Please Fill Job Contact Field');
	}
	if((job_phone == '' || job_phone == null) && bval == true){
		bval=false;
		alert('Please Fill Job Telephone Field');
	}
		
	if(bval){
		var flag = 0;
		for(var i=0 ; i < len; i++){
			
			if(urgency[i].checked == true ){
				flag = 1;
			}				
		}
		
		if(flag == 0){
			bval=false;
			alert('Please Specify Your Urgency');
		}
	}
	
	if((comments == '' || comments == null) && bval == true){
		bval=false;
		alert('Please Fill Comments Field');
	}
	return bval;
}


function creat_Object(){ 
	var xmlhttp;
	// This if condition for Firefox and Opera Browsers 
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
		try 
		{
			xmlhttp = new XMLHttpRequest();
		} 
		catch (e) 
		{
			alert("Your browser is not supporting XMLHTTPRequest");
			xmlhttp = false;
		}
	}
	// else condition for ie
	else
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

var request = creat_Object();

function changecode(){
	var d = new Date();
	var curr_msec = d.getMilliseconds();

	request.open("GET", "getCaptcha.php?msec=" + curr_msec); 
	request.onreadystatechange = sever_interaction_change;
	request.send('');
}
function sever_interaction_change(){
	if(request.readyState==1){
		document.getElementById("captchaspan").innerHTML='<img src="images/ajax-loader.gif" style="margin-left:30px;">';
	}
	
	if(request.readyState==4){
		var answer=request.responseText;
		if(answer!=""){
			document.getElementById("captchaspan").innerHTML=answer;
			document.getElementById("txtcaptcha").focus();
		}
	}
}

function validateContact(){
	var bval=true;
	var name=document.contact_us.txtname.value;
	var email=document.contact_us.txtemail.value;
	//var address=document.contact_us.txtaddress.value;
	//var zip=document.contact_us.txtzip.value;
	var phone=document.contact_us.txtphone.value;
	var captcha=document.contact_us.txtcaptcha.value;
	
	if(name == '' || name == null){
		bval=false;
		alert('Please Fill Up Name Field');
	}
	if(bval){
		bval = emailCheck(email);
	}
	
	if((phone == '' || phone == null) && bval == true){
		bval=false;
		alert('Please Fill Up Phone Field');
	}
	if((captcha == '' || captcha == null) && bval == true){
		bval=false;
		alert('Please Enter Shown Code');
	}
	return bval;	
}

function emailCheck(iVal) 
{
   	var emailPat=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
    var matchArray; 
    var emailStr = iVal; 
    if(emailStr.length > 1)
    {    
		matchArray = emailStr.match(emailPat);
		if (matchArray == null) 
			{
				alert("Please Enter Correct Email Address"); 
				return false;
			} 
		else
			return true;
	}
	else
	{
		alert("Please Fill Up Email Field"); 
		return false;
	}
	return true;

}