// JavaScript Document

/*Detect browser information start here*/
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);



//+++++++++  This function return the page height and width start here ++++++++++++++++++++//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
//+++++++++  This function return the page height and width end here ++++++++++++++++++++//

/*===============================================================*/
//=== 		This code for float the div		======================

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}
/*===============================================================*/




function openEnqPopUp(divId, enqId){
	
	//alert(divId);
	//alert(enqId);
	var divVal = '#'+divId;	
	
	var pageDet = getPageSize();
	
	var winWid = pageDet[2];
	var winHei = pageDet[3];
	
	var popUpWidth 		= $(divVal).width();
	var popUpHeight		= $(divVal).height();
	
	var topposition 	= (winHei / 2) - (popUpHeight / 2);
	var leftposition 	= (winWid / 2) - (popUpWidth / 2);
	
	//document.getElementById(divId).style.top = topposition+'px';
	//document.getElementById(divId).style.left = leftposition+'px';/
	
	
	$('#bpId').val(enqId);
	$('#txtName').val('');
	$('#txtEmail').val('');
	$('#message').val('');
	
	$('#country').val('');
	$('#telCoun').val('Coun');
	$('#telCity').val('City');
	$('#telPhone').val('Phone & Mobile');
		
	//document.getElementById('txtName').value= '';
	//document.getElementById('message').value= '';
	//document.getElementById('txtEmail').value= '';
	
	$(divVal).show('slow');
	JSFX_FloatDiv(divId, leftposition,topposition).floatIt();
}


function closePopUP(divId){
		
	var divVal = '#'+divId;	
	$(divVal).hide('slow');
}


function limitText(limitField, showDivId, limitNum)
{
		
	if (limitField.value.length > limitNum)
		limitField.value = limitField.value.substring(0, limitNum);
	else	
		document.getElementById(showDivId).innerHTML = limitNum - limitField.value.length;
	
}


function sendEnquiry(divId){

	var divVal = '#'+divId;
	

	var sirName = $('#nameTitle').val();	
	var txtName1 = $('#txtName').val();
	
	if(txtName1 == ''){
		alert('Please enter your full name');
		$('#txtName').focus();
		return false;
	}
	
	var txtEmail = $('#txtEmail').val();
	if(txtEmail == ''){
		alert('Please enter your email id');
		$('#txtEmail').focus();
		return false;
	}else{
		
		if(!isEmail(txtEmail)){			
			alert('Please enter correct email id');
			$('#txtEmail').focus();
			return false;
		}
	}
	
	var txtCoun = $('#country').val();
	if(txtCoun == ''){
		alert('Please select a country');
		$('#country').focus();
		return false;
	}
	
	var txtPhone = $('#telPhone').val();
	if(txtPhone == 'Phone & Mobile' || txtPhone == ''){
		alert('Please enter phone number');
		$('#telPhone').val('');
		$('#telPhone').focus();
		return false;
	}	
	
	var txtMess = $('#message').val();
	if(txtMess == ''){
		alert('Please enter message');
		$('#message').focus();
		return false;
	}
	
	
	var telCoun = $('#telCoun').val();
	var telCity = $('#telCity').val();
	var txtBpId = $('#bpId').val();
	
	
	var queryStr = 'txt1='+sirName+'&txt2='+txtName1+'&txt3='+txtEmail+'&txt4='+txtCoun+'&txt5='+telCoun+'&txt6='+telCity+'&txt7='+txtPhone+'&txt8='+txtMess+'&txt9='+txtBpId;
	
	//alert(queryStr);
	
	$.ajax({
		   
		type: "GET",
		url: "bp-enquiry.php", 
		data: queryStr,
		success: function(msg){
			//alert( "Data Saved: " + msg );
			
			if(msg > 0){
				alert('Your enquiry has been submitted succssfully.');
				$(divVal).hide('slow');
				return true;
				
			}else{
				alert('Some error has occured, please try again.');
				return false;
			}
		},
		start: function(){		
			//alert('Ajax has been started');
		},
		complete: function(){
			//alert('Ajax has been completed');
		},
		error: function(){
			//alert('Some error has occured: ');		
		}
		
	});

}


/*This code snippet is for display pop up message on home page*/
function showHomePagePopUpMessage(divId){
	
	var divVal = '#'+divId;
	
	
	var pageDet = getPageSize();
	
	var winWid = pageDet[2];
	var winHei = pageDet[3];
	
	var popUpWidth 		= $(divVal).width();
	var popUpHeight		= $(divVal).height();
	
	
	var topposition 	= (winHei / 4) - (popUpHeight / 3);
	
	if(browser == 'Microsoft Internet Explorer'){
		//var leftposition 	= (winWid / 3) - (popUpWidth / 2);
		var leftposition 	= 300;
	}else{
		var leftposition 	= (winWid / 2) - (popUpWidth / 2);	
	}
	
	var topposition = 200;
	
	$(divVal).show('slow');
	
	JSFX_FloatDiv(divId, leftposition,topposition).floatIt();
}
