// JavaScript Document
function checkEmail()
	{
	var strEmail, strError, countAtRate, countDot, i;
	var checkAtRate, checkDot;
	var ValidChars,CountValidChars;
	ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	strEmail = checkEmail.arguments[0];

	countAtRate=0;
	countDot=0;
	CountValidChars=0;
	if (strEmail.length >= 7)
		{
		for(i=0;i<strEmail.length;i++)
			{
			if(strEmail.charAt(i)=="@")
				countAtRate++;
			if(strEmail.charAt(i)==".")
				countDot++;
			CountValidChars=0;
			for(j=0;j<ValidChars.length;j++)
				{
				if(strEmail.charAt(i)==ValidChars.charAt(j))
					{
					CountValidChars++;
					}
				}
			if(CountValidChars==0)
				{
				strError=0;
				break;
				}
			}
		}
	checkAtRate=strEmail.indexOf("@",1);
	checkDot=strEmail.indexOf(".",1);
	for(i=1;i<countDot;i++)
		checkDot=strEmail.indexOf(".",checkDot+1);
	if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
		strError=1;
	else
		strError=0;
	if(checkDot>=strEmail.length-2)
		strError=0;
	if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
		strError=0;
	if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
		strError=0;
	if(checkDot < checkAtRate)
		strError=0;

	return strError;
}


function isBlank(C) {
	for (i=0;i<C.length;i++) {if (C.charAt(i) != " ") return false}
	return true;
}

function keyCheck(eventObj, obj)
{
	var keyCode	
	
	// Check For Browser Type
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}

	var str=obj.value
	if(keyCode==46){ 
		if (str.indexOf(".")>0){
			return false
		}
	}
	
	if((keyCode<48 || keyCode >58)){ // Allow only integers
		return false
	}
	
	return true
}


function frmcvalidate(dm) {
	alert('test');
	return;


}

function frmvalidatelogin(dm)
{
var strError="";

	if(isBlank(dm.emailaddress.value)){
		strError+="Email Address\n";
	}else if(checkEmail(dm.emailaddress.value)==0){
		strError += "Invalid Email Address\n";
	}
	if(isBlank(dm.city.value))
		strError+="City\n";
			
		if(strError!=""){
		alert("Please Enter Following  Field(s)\n--------------------------\n"+strError);
		return false;
		}
		return true;
}

function validatec(dm)
{
var strError="";
	if(isBlank(dm.fname.value))
		strError+="Name\n";
	if(isBlank(dm.email.value)){
		strError+="Email Address\n";
		}else if(checkEmail(dm.email.value)==0){
		strError+="Invalid Email Address\n";
		}
	if(isBlank(dm.message.value))
		strError+="Message\n";
		
		if(strError!=""){
		alert("Please Enter Following Field(s)\n--------------------------------\n"+strError);
		return false;
		}
		return true;
		
}

/*function frmvalidatesignup(dm){
var strError="";
country=dm.country.value;	
	if(isBlank(dm.fname.value))
		strError+="First Name\n";
	if(isBlank(dm.fname.value))
		strError+="Last Name\n";
	if(isBlank(dm.address1.value))
		strError+="Address1\n";
	if(country=="")
	strError+="Select Country\n";
	if(isBlank(dm.newpass.value))
		strError+="Password\n";
	
	if(isBlank(dm.emailaddress.value)){
	strError+="Email Address\n";
	}else if(checkEmail(dm.emailaddress.value)==0){
		strError += "Invalid Email Address\n";
	}
		if(strError!=""){
		alert("Please Enter Following Field(s)\n--------------------------\n"+strError);
		return false;
		}
		return true;	
}
*/
function  newUser(){
location.href='signup.php';
}

function logout()
{
location.href='logout.php';
}
function OpenWindow(pid){
window.open("productdetail.php?pid="+pid,"ProductDetail","width=800,height=600,scrollbars=yes,resizable=yes,menubar=0,status=0,top=0,left=0");
}


function viewOutlets()
{
	with (window.document.frmoutlets) {
	
		if (cmbcities.selectedIndex == 0) {
			window.location.href = 'outlets.php';
		} else {
			window.location.href = 'outlets.php?cid=' + cmbcities.options[cmbcities.selectedIndex].value;
		}
		
	}
}

function showimage()
{
	window.open('stores.php','StoreImage','width=800,height=600,resizable=yes,scrollbars=yes');
}