// JavaScript Document
function loginPageLoad() {
	if(document.getElementById('hdLoginError').value=='ok') {
		document.getElementById('hdLoginError').value='';
		loginError(1);
	}
	else if(document.getElementById('hdLoginError').value=='ok2') {
		document.getElementById('hdLoginError').value='';
		loginError(2);
	}
	else if(document.getElementById('hdLoginError').value=='ok3') {
		document.getElementById('hdLoginError').value='';
		loginError(3);
	}	
}
function loginError(n) {
	var objDivError;
	var objTdDiv=document.getElementById('tdDivError');
	var objTable;
	var objTr;
	var objTd;
	var attr;
	var index;
	var indexText;
	var errorHtml='';
	if(objTdDiv.childNodes[0]!=null)
		objTdDiv.removeChild(objTdDiv.childNodes[0]);
	objTable=document.createElement('table');
	objTr=document.createElement('tr');
	objTd=document.createElement('td');
	objTable.setAttribute('border','0');
	objTable.setAttribute('cellPadding','5');
	objTable.setAttribute('cellSpacing','0');
	objTable.setAttribute('style','visibility: visible;');
	objTd.setAttribute('align','left');
	objTr.appendChild(objTd);
	objTable.appendChild(objTr);
	//
	objDivError=document.createElement('div');
	objDivError.setAttribute('style','width: 400px; visibility: visible; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 9px; color: #FF0000;');
	errorHtml="<span style='font-size: 10px;'>Following errors were found while filling the form:</span>";
	errorHtml+="<ul>";
	if(n==2) {
		errorHtml+="<li>Email address exists, please login!</li>";
	}
	else if(n==3) {
		errorHtml+="<li>Invalid validation code</li>";
	}
	else {
		errorHtml+="<li>Invalid userid or password</li>";
	}
	errorHtml+="</ul>";
	if(errorHtml.indexOf('<li>')>=0) {
		if(document.all) {
			objTdDiv.innerHTML = "<table border='0' cellpadding='5' cellspacing='0'>" +
				"<tr><td align='left' valign='top' style='font-family: Verdana, Arial, Helvetica,"+
				" sans-serif; font-weight: bold; font-size: 9px; color: #FF0000; color: red;'>" +
				errorHtml + "</td></tr></table>";
		}
		else {
			objDivError.innerHTML=errorHtml;
			objTd.appendChild(objDivError);
			objTdDiv.appendChild(objTable);
		}
	}
}
function loginPageSubmit() {
	var status=true;
	var objDivError;
	var objTdDiv=document.getElementById('tdDivError');
	var objTable;
	var objTr;
	var objTd;
	var attr;
	var index;
	var indexText;
	var errorHtml='';
	var emailRegExp=/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	if(objTdDiv.childNodes[0]!=null)
		objTdDiv.removeChild(objTdDiv.childNodes[0]);
	objTable=document.createElement('table');
	objTr=document.createElement('tr');
	objTd=document.createElement('td');
	objTable.setAttribute('border','0');
	objTable.setAttribute('cellPadding','5');
	objTable.setAttribute('cellSpacing','0');
	objTable.setAttribute('style','visibility: visible;');
	objTd.setAttribute('align','left');
	objTr.appendChild(objTd);
	objTable.appendChild(objTr);
	//
	objDivError=document.createElement('div');
	objDivError.setAttribute('style','width: 400px; visibility: visible; position: relative; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 9px; color: #FF0000;');
	//
	//Checking for errors
	errorHtml="<span style='font-size: 10px;'>Following errors were found while filling the form:</span>";
	errorHtml+="<ul>";
	//Start checking Errors
	if(trim(document.getElementById('strUserId').value)=='') {
		errorHtml+="<li>Userid can not be left blank</li>";
		status=false;
	}
	else {
		if(!emailRegExp.test(document.getElementById('strUserId').value)) {
			errorHtml+="<li>Invalid userid</li>";
			status=false;
		}
	}
	if(trim(document.getElementById('strPassword').value)=='') {
		errorHtml+="<li>Password can not be left blank</li>";
		status=false;
	}
	var vValidationCode;
	vValidationCode=trim(document.getElementById('strValidationCode').value);
	if(vValidationCode.length<6) {
		errorHtml+="<li>Validation Code must be six characters</li>";
		status=false;
	}
	//End checing Errors
	errorHtml+="</ul>";
	//
	if(errorHtml.indexOf('<li>')>=0) {
		if(document.all) {
			objTdDiv.innerHTML = "<table border='0' cellpadding='5' cellspacing='0'>" +
				"<tr><td align='left' valign='top' style='font-family: Verdana, Arial, Helvetica,"+
				" sans-serif; font-weight: bold; font-size: 9px; color: #FF0000; color: red;'>" +
				errorHtml + "</td></tr></table>";
			}
			else {
				objDivError.innerHTML=errorHtml;				
				objTd.appendChild(objDivError);
				objTdDiv.appendChild(objTable);
			}
	}
	document.documentElement.scrollTop='0px';
	if(status) {
 		document.getElementById('loginForm').submit();
	}
}
//for order login
function orderLoginPageSubmit(n) {
	var status=true;
	var objDivError;
	var objTdDiv=document.getElementById('tdDivError');
	var objTable;
	var objTr;
	var objTd;
	var attr;
	var index;
	var indexText;
	var errorHtml='';
	var emailRegExp=/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	if(objTdDiv.childNodes[0]!=null)
		objTdDiv.removeChild(objTdDiv.childNodes[0]);
	objTable=document.createElement('table');
	objTr=document.createElement('tr');
	objTd=document.createElement('td');
	objTable.setAttribute('border','0');
	objTable.setAttribute('cellPadding','5');
	objTable.setAttribute('cellSpacing','0');
	objTable.setAttribute('style','visibility: visible;');
	objTd.setAttribute('align','left');
	objTr.appendChild(objTd);
	objTable.appendChild(objTr);
	//
	objDivError=document.createElement('div');
	objDivError.setAttribute('style','width: 400px; visibility: visible; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 9px; color: #FF0000;');
	//
	//Checking for errors
	errorHtml="<span style='font-size: 10px;'>Following errors were found while filling the form:</span>";
	errorHtml+="<ul>";
	//Start checking Errors
	if(trim(document.getElementById('strUserId').value)=='') {
		errorHtml+="<li>Userid can not be left blank</li>";
		status=false;
	}
	else {
		if(!emailRegExp.test(document.getElementById('strUserId').value)) {
			errorHtml+="<li>Invalid userid</li>";
			status=false;
		}
	}
	if(n==1) {
		if(trim(document.getElementById('strPassword').value)=='') {
			errorHtml+="<li>Password can not be left blank</li>";
			status=false;
		}
	}
	//End checing Errors
	errorHtml+="</ul>";
	//
	if(errorHtml.indexOf('<li>')>=0) {
		if(document.all) {
			objTdDiv.innerHTML = "<table border='0' cellpadding='5' cellspacing='0'>" +
				"<tr><td align='left' valign='top' style='font-family: Verdana, Arial, Helvetica,"+
				" sans-serif; font-weight: bold; font-size: 9px; color: #FF0000; color: red;'>" +
				errorHtml + "</td></tr></table>";
		}
		else {
			objDivError.innerHTML=errorHtml;
			objTd.appendChild(objDivError);
			objTdDiv.appendChild(objTable);
		}
	}
	document.documentElement.scrollTop='0px';
	if(status) {
		if(n==1) {
			document.getElementById('orderLoginForm').action='includePages/orderLoginCheckMatter.php?ol=1';
		}
		else if(n==2) {
			document.getElementById('orderLoginForm').action='includePages/orderLoginCheckMatter.php?ol=2';
		}
		else { }
 		document.getElementById('orderLoginForm').submit();
	}
}