
function enterkey(e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13)
	{
		if(!validateField(1))
		{
			return false;
		}
		
		
	}	
	return true;
}

var a1=0;
var a2=0;
var a3=0;
var e1=0;
var e2=0;
function filedReset()
{
	document.getElementById("nameid").innerHTML="";
	document.getElementById("mobileid").innerHTML='';
	document.getElementById("emailidid").innerHTML='';
	document.getElementById("creditcardno_error").innerHTML='';
	document.frmngncardpaylt.reset();
	return false;
}

function trimSpace(x)
{
   var emptySpace = / /g;
   var trimAfter = x.replace(emptySpace,"");
   return(trimAfter);
}
function textValidate(incomingString, defaultValue)
{
	if(trimSpace(incomingString).length == 0 || incomingString.search(/[^a-zA-Z ]/g) != -1 || incomingString==defaultValue)
		return false;
	else
		return true;
}
function numberValidate(incomingString, defaultValue)
{
	if(trimSpace(incomingString).length == 0 || incomingString.search(/[^0-9]/g) != -1)
		return false;
	else
		return true;	
}
function Name_validate(focusValue)
{
	if(trimSpace(document.frmngncardpaylt.name.value)=='')
	{
		
			if(focusValue==1)
			{
		document.frmngncardpaylt.name.focus()
		document.frmngncardpaylt.name.select()
		}
		document.getElementById("nameid").innerHTML='(Please enter your Name)';
		return false;
	}
	if(!textValidate(document.frmngncardpaylt.name.value,''))
	{
		
			if(focusValue==1)
			{
		document.frmngncardpaylt.name.focus()
		document.frmngncardpaylt.name.select()
		}
		document.getElementById("nameid").innerHTML='(Please enter your Name - Alphabets only)';
		return false;
	}	
	document.getElementById("nameid").innerHTML="";
	return true;
}

function creditcardNo_validate(focusValue)
{
	if(!Name_validate(focusValue))
	{
		return false;
	}
	if(trimSpace(document.frmngncardpaylt.creditcardno.value)=='')
	{
		if(focusValue==1)
			{
				document.frmngncardpaylt.creditcardno.focus()
				document.frmngncardpaylt.creditcardno.select()
			}
			document.getElementById("creditcardno_error").innerHTML='(Please enter your Credit Card Number)';
			return false
	}
	if(!numberValidate(document.frmngncardpaylt.creditcardno.value,''))
		{
			if(focusValue==1)
			{
				document.frmngncardpaylt.creditcardno.focus()
				document.frmngncardpaylt.creditcardno.select()
			}
			document.getElementById("creditcardno_error").innerHTML='(Please enter a valid Credit Card Number)';
			return false
		} 
		if(document.getElementById("creditcardno").value.charAt(0)!=3 && document.getElementById("creditcardno").value.charAt(0)!=4 && document.getElementById("creditcardno").value.charAt(0)!=5 )
	{
	  		if(focusValue==1){
			document.getElementById("creditcardno").focus();
			document.getElementById("creditcardno").select();
			}
	
	document.getElementById("creditcardno_error").innerHTML = 'Please enter a valid Credit Card Number';
		return false;
	}
	
	if(document.getElementById("creditcardno").value.charAt(0)==3 && document.getElementById("creditcardno").value.length!=14)
	{
		if(focusValue==1){
	 		document.getElementById("creditcardno").focus();
			document.getElementById("creditcardno").select();
			}
	
	document.getElementById("creditcardno_error").innerHTML ='Please enter a valid Credit Card Number';
		return false;
	}

		if(document.getElementById("creditcardno").value.charAt(0)==4 || document.getElementById("creditcardno").value.charAt(0)==5 )
	{
		if(document.getElementById("creditcardno").value.length<16)
		{
	 		if(focusValue==1){
			document.getElementById("creditcardno").focus();
			document.getElementById("creditcardno").select();
			}
	
	document.getElementById("creditcardno_error").innerHTML ='Please enter a valid Credit Card Number';
		return false;
		}
	}
		if(trimSpace(document.frmngncardpaylt.creditcardno.value)==0)
		{	
			if(focusValue==1)
			{
				document.frmngncardpaylt.creditcardno.focus()
				document.frmngncardpaylt.creditcardno.select()
			}
			document.getElementById("creditcardno_error").innerHTML ='Please enter a valid Credit Card Number';
			return false
		}
	
	document.getElementById("creditcardno_error").innerHTML='';
	return true;
}

function Emailid_validate(focusValue)
{
	if(!creditcardNo_validate(focusValue))
	{
		return false;
	}	
	var emailexp = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9\-]+)\.(([a-zA-Z]{2,}|[0-9]{2,})|([a-zA-Z]{2,}\.[a-zA-Z]{2,})|([a-zA-Z]{2,}\.[a-zA-Z]{2,}\.[a-zA-Z]{2,}))$/;
	if(trimSpace(document.frmngncardpaylt.emailid.value)=="")
	{
		
			if(focusValue==1)
			{
		document.frmngncardpaylt.emailid.focus()
		document.frmngncardpaylt.emailid.select()
		}
		document.getElementById("emailidid").innerHTML='(Please enter your E-mail ID)';
		return false;
	}
	if(!emailexp.test(document.frmngncardpaylt.emailid.value))
	{
		
			if(focusValue==1)
			{
		document.frmngncardpaylt.emailid.focus()
		document.frmngncardpaylt.emailid.select()
		}
		document.getElementById("emailidid").innerHTML='(Please enter a valid E-mail ID)';
		
		return false
	}
	if(trimSpace(document.frmngncardpaylt.emailid.value).length<6)
	{
		
			if(focusValue==1)
			{
		document.frmngncardpaylt.emailid.focus()
		document.frmngncardpaylt.emailid.select()
		}
		document.getElementById("emailidid").innerHTML='(Please enter a valid E-mail ID)';
		return false
	}
	document.getElementById("emailidid").innerHTML='';
	return true;
}
function Mobile_No_validate(focusValue)
{
	if(!Emailid_validate(focusValue))
	{
		return false;
	}
	if(trimSpace(document.frmngncardpaylt.mobileno.value)=='')
	{
		if(focusValue==1)
			{
				document.frmngncardpaylt.mobileno.focus()
				document.frmngncardpaylt.mobileno.select()
			}
			document.getElementById("mobileid").innerHTML='(Please enter your Mobile Number)';
			return false
	}
	if(!numberValidate(document.frmngncardpaylt.mobileno.value,''))
		{
			if(focusValue==1)
			{
				document.frmngncardpaylt.mobileno.focus()
				document.frmngncardpaylt.mobileno.select()
			}
			document.getElementById("mobileid").innerHTML='(Please enter numbers only)';
			return false
		} 
		if(document.frmngncardpaylt.mobileno.value.length!=10)
		{
			if(focusValue==1)
			{
				document.frmngncardpaylt.mobileno.focus()
				document.frmngncardpaylt.mobileno.select()
			}
			document.getElementById("mobileid").innerHTML='(Please enter a valid Mobile Number)';
			return false
		}
		if(trimSpace(document.frmngncardpaylt.mobileno.value)==0)
		{	
			if(focusValue==1)
			{
				document.frmngncardpaylt.mobileno.focus()
				document.frmngncardpaylt.mobileno.select()
			}
			document.getElementById("mobileid").innerHTML='(Please enter a valid Mobile Number)';
			return false
		}
		if((document.frmngncardpaylt.mobileno.value.charAt(0))!='7' && (document.frmngncardpaylt.mobileno.value.charAt(0))!='8' && (document.frmngncardpaylt.mobileno.value.charAt(0))!='9')
		{	
			if(focusValue==1)
			{
				document.frmngncardpaylt.mobileno.focus()
				document.frmngncardpaylt.mobileno.select()
			}
			document.getElementById("mobileid").innerHTML='(Please enter a valid Mobile Number)';
			return false
		}
	document.getElementById("mobileid").innerHTML='';
	return true;
}
function validateField(focusValue)
{
	document.frmngncardpaylt.Agency_Code.value=getParameter("agencyCode");
document.frmngncardpaylt.Campaign_Code.value=getParameter("campaignCode");
document.frmngncardpaylt.Creative.value=getParameter("creative");
document.frmngncardpaylt.Product_Code.value=getParameter("productCode");
document.frmngncardpaylt.Section.value=getParameter("section");
document.frmngncardpaylt.Site.value=getParameter("site");
document.frmngncardpaylt.externalOfferCode.value=getParameter("eOfferCode");
	if(!Mobile_No_validate(focusValue))
	{
		return false;
	}	
document.frmngncardpaylt.submit();
	return true;
}
