// JavaScript Document


// validation for login
function validLogin(frm)
{
	if(!isValidEmail(frm.txtemail, 'yes'))
	{
		frm.txtemail.focus();
		return false;
	}
	return true;
}

// validation for register
function validRegister(frm)
{
	if(!isValidAlphabet(frm.txtname, 'Name', 'yes'))
	{
		frm.txtname.focus();
		return false;	
	}
	if(trim(frm.txtprofession.value) == '')
	{
		alert("Profession should not be empty, enter your Profession");
		frm.txtprofession.focus();
		return false;	
	}
	if(!isValidEmail(frm.txtemail, 'yes'))
	{
		frm.txtemail.focus();
		return false;
	}
return true;
}

// validate feedback form
function validFeedback(frm)
{
	if(!isValidAlphabet(frm.txtname, 'Name', 'yes') == '')
	{
		frm.txtname.focus();
		return false;	
	}
	if(trim(frm.txtprofession.value) == '')
	{
		alert("Profession should not be empty, enter your Profession");
		frm.txtprofession.focus();
		return false;	
	}
	if(!isValidEmail(frm.txtemail, 'yes'))
	{
		frm.txtemail.focus();
		return false;
	}
	if(trim(frm.txtcomments.value) == '')
	{
		alert("Comments should not be empty, enter your Comments");
		frm.txtcomments.focus();
		return false;
	}
return true;
}

//validate subscription form
function validSubscription(frm)
{
	if(trim(frm.txtname.value) == '')
	{
		alert("Name should not be empty, enter your Name");
		frm.txtname.focus();
		return false;	
	}
	if(trim(frm.txtaddress.value) == '')
	{
		alert("Address should not be empty, enter your Address");
		frm.txtaddress.focus();
		return false;
	}
	if(trim(frm.txtcity.value) == '')
	{
		alert("City should not be empty, enter your City");
		frm.txtcity.focus();
		return false;
	}
		
	if(trim(frm.txtpostal.value) == '' || isNaN(frm.txtpostal.value))
	{
		alert("Invalid Postal Code, enter your Postal Code");
		frm.txtpostal.focus();
		return false;	
	}
	if(trim(frm.txtcountry.value) == '')
	{
		alert("Country should not be empty, enter your Country");
		frm.txtcountry.focus();
		return false;
	}
	if(isValidPhone(frm.txtphone, 'Phone Number', 'yes') == '')
	{
		frm.txtphone.focus();
		return false;	
	}
	
	if(!isValidEmail(frm.txtemail, 'yes'))
	{
		frm.txtemail.focus();
		return false;
	}
return true;
}

// validate submit query form
function validFeedback(frm)
{
	if(!isValidAlphabet(frm.txtname, 'Name', 'yes') == '')
	{
		frm.txtname.focus();
		return false;	
	}
	if(trim(frm.txtprofession.value) == '')
	{
		alert("Profession should not be empty, enter your Profession");
		frm.txtprofession.focus();
		return false;	
	}
	if(!isValidEmail(frm.txtemail, 'yes'))
	{
		frm.txtemail.focus();
		return false;
	}
	if(trim(frm.txtquery.value) == '')
	{
		alert("Query should not be empty, enter your Query");
		frm.txtquery.focus();
		return false;
	}
	return true;
}




//function to show or hide a div
function fnToggleDisplay(showdiv,hidediv)
{
	if(hidediv != '' && typeof(document.getElementById(hidediv)) != 'undefined' && document.getElementById(hidediv) != null)
		document.getElementById(hidediv).style.display = 'none';
	if(showdiv != '' && typeof(document.getElementById(showdiv)) != 'undefined' && document.getElementById(showdiv) != null)
		document.getElementById(showdiv).style.display = 'block';
}

function centerOfTheScreen(){
	if(window.innerWidth)
		scwidth = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		scwidth = document.documentElement.clientWidth;
	else if (document.body)
		scwidth = document.body.clientWidth;
	
	var scro = getScrollXY();
	if(window.innerHeight)
		scheight = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		scheight = document.documentElement.clientHeight;
	else if (document.body)
		scheight = document.body.clientHeight;	
	var scdimensions = {'width':scwidth, 'height':parseInt(scro[1])+parseInt(scheight/2)};
	return scdimensions;
}


function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	var scrollArray = [scrOfX, scrOfY];
	
	return scrollArray;
}

var ZINDEX = 100;

// to show message for login or registration
function showLoginRegMessage(page)
{
	var divMain = document.getElementById("divPopup");
	var divHeader = document.getElementById("divPopupTitle");
	var divContent = document.getElementById("contentDivPopup");
	divHeader.innerHTML = "Email Information Box";
	document.getElementById("divPopup").style.width = '500px';
	divContent.innerHTML = "<strong>Loading.....</strong>";
	var winCoordinates = centerOfTheScreen();
	divMain.style.left = (winCoordinates['width']/2-250)+"px";
	divMain.style.top = "200px";
	divMain.style.display = "block";
	hajax("loginRegConfirmMessage.php", respShowLoginRegMessage, "page="+page, divContent);
}

function respShowLoginRegMessage(server_response, contObj)
{
	contObj.innerHTML = server_response;
	document.loginajaxfrm.txtemail.focus();
}

// to send portfolio form
function sendPortfolioForm(frm)
{
	var divContent = document.getElementById("contentDivPopup");
	if(frm.elements['portfolio[name]'].value == '')
	{
		alert("Please Enter a Your Name");
		frm.elements['portfolio[name]'].focus();
		return false;
	}
	if(frm.elements['portfolio[mobile]'].value == '')
	{
		alert("Please Enter a Your Mobile Number");
		frm.elements['portfolio[mobile]'].focus();
		return false;
	}
	var qrySrt = "doact=send&portfolio[name]="+encodeURIComponent(frm.elements['portfolio[name]'].value);
	qrySrt += "&portfolio[mobile]="+encodeURIComponent(frm.elements['portfolio[mobile]'].value);

	divContent.innerHTML = "<strong>Sending........</strong>";
	
	hajax('portfolio.php', respShowPortfolioForm, qrySrt, divContent);	
	
return false;
}
