	var w=0;

function validatePOS(lang)
{
	
	//GET FORM VARIABLES (FROM SOBEYS)
	/*
	var storecode = zeroPad(document.form1.tf_store.value,6);
	var visitdate = removeNL(document.form1.sl_date.value);
	var visithour = document.form1.sl_hour.value;
	var visitmin = document.form1.sl_min.value;
	var trannumber = zeroPad(document.form1.tf_tran.value,4);
	*/
	var storeNum = zeroPad(document.form1.tf_store.value,5);
	var regNum = zeroPad(document.form1.tf_reg.value,3);
	var tranNum = zeroPad(document.form1.tf_tran.value,4);
	var visitDate = removeNL(document.form1.sl_date.value);

	var result = true;
	var cCode = "";

	var clientid = "93";
	var surveyid = "5";

	//validate for future dates
	if (document.form1.sl_date != null)
	{
		var message = "";
		var userDate = document.form1.sl_date.value;
		var strYear = userDate.substring(0,4);
		var strMonth = userDate.substring(5,7);
		var strDay = userDate.substring(8,10);
	
		if (strMonth.length < 2)
		{
			strMonth = "0"+ strMonth;
		}
		if (strDay.length < 2)
		{
			strDay = "0"+ strDay;
		}
		
		var now = new Date();	

		var currentYear = now.getFullYear();
		var currentMonth = now.getMonth() + 1;
		var currentDay = now.getDate();	

		//date validation MM
		if((strDay > currentDay && strDay < 31 && strMonth == currentMonth && strMonth < 12 && strYear == currentYear) || (strMonth > currentMonth && strMonth < 12 && strYear == currentYear) || (strYear > currentYear)) 
		{
			if (strDay < 1 || strDay > 31) 
			{	
				if(lang == "french")
				{
					message += "Le jour doit être entre 1 et 31.\n";
				}else{
					message += "Day must be between 1 and 31.\n";
				}
			}
			else if (strMonth < 1 || strMonth > 12 ) 
			{
				if(lang == "french")
				{
					message += "Le mois doit être entre 1 et 12.\n";
				}else{
					message += "Month must be between 1 and 12.\n";
				}
			}
			else
			{
				if(lang == "french")
				{
					message += "Vous avez entrer une date du futur.\nVeuillez choisir la date correcte de votre visite.\n";
				}else{
					message += "You have entered a date from the future.\nPlease select the correct date of your visit.\n";
				}
			}
			if (w!=3)
				alert(message);
			
			result = false;
                	w+=1;
		}
	}

	if(validStore(storeNum) == "false" || storeNum.length != 5 || isNaN(storeNum) || regNum.length != 3 || isNaN(regNum) || tranNum.length != 4 || isNaN(tranNum) || visitDate.length != 8)
	//if(storeNum.length != 5 || isNaN(storeNum) || regNum.length != 3 || isNaN(regNum) || tranNum.length != 4 || isNaN(tranNum) || visitDate.length != 8)
	{
		if(lang == "french")
		{
			if(validStore(storeNum) == "false" || storeNum == -1 || storeNum == 0)
				alert("Ce n'est pas le numéro du magasin.");
			else if(regNum.length != 3 || isNaN(regNum))
				alert("Ce n'est pas le numéro de caisse.");
			else if(tranNum.length != 4 || isNaN(tranNum))
				alert("Ce n'est pas le numéro de transaction.");
			else if(visitDate.length != 8)
				alert("Ce n'est pas la date de votre visite chez Sears.");
		}
		else
		{
			//if(storeNum == -1 || storeNum == 0 || isNaN(storeNum))
			if(validStore(storeNum) == "false" || storeNum == -1 || storeNum == 0)
			{
				alert("That does not appear to be a vaild store number.\nPlease try again.");
				document.form1.tf_store.select();
			}
			else if(regNum.length != 3 || isNaN(regNum))
			{
				alert("That does not appear to be a valid register number.\nPlease try again.");
				document.form1.tf_reg.select();
			}
			else if(tranNum.length != 4 || isNaN(tranNum))
			{
				alert("That does not appear to be a valid transaction number.\nPlease try again.");
				document.form1.tf_tran.select();
			}
			else if(visitDate.length != 8)
			{
				alert("That does not appear to be a valid date of visit.\nPlease try again.");
				document.form1.sl_date.select();
			}
		}
		result = false;
		w+=1;
	}

	if(result)
	{
		cCode = "" + storeNum + regNum + tranNum + visitDate;
		document.form1.action = "xmlloaderPos.jsp?certcode="+cCode+"&clientid="+clientid+"&surveyid="+surveyid+"&storeNum="+storeNum;
		document.form1.submit();
	}
	else if (w==3)
	{
		//document.location.href="../../Email/EmailErrorPage.jsp?callingPage="+document.URL+"";
		document.form1.action = "../Email/EmailErrorPage.jsp?callingPage="+document.URL+"";
		document.form1.submit();
	}
	
}

function validStore(storeNum)
{
	//ADDED STORE 99999 FOR ALL LEVELS FOR TESTING (DUMMY CERT) - CF - FEB-09-07
	var validStores = "99999|00317|01010|01011|01012|01013|01014|01015|01016|01017|01018|01019|01020|01022|01027|01029|01031|01032|01033|01034|01035|01036|01037|01039|01040|01041|01045|01047|01049|01057|01060|01080|01081|01082|01083|01084|01085|01086|01087|01088|01093|01094|01095|01096|01097|01098|01110|01111|01112|01113|01114|01115|01238|01241|01244|01305|01308|01309|01310|01311|01312|01315|01317|01318|01319|01320|01321|01322|01323|01325|01328|01329|01330|01331|01335|01336|01338|01341|01342|01343|01344|01345|01346|01347|01348|01349|01350|01351|01352|01353|01354|01355|01356|01357|01359|01360|01361|01362|01364|01365|01366|01367|01368|01369|01370|01372|01373|01374|01375|01376|01378|01379|01380|01381|01382|01383|01384|01385|01387|01391|01393|01394|01395|01396|01398|01410|01411|01413|01414|01416|01417|01418|01422|01423|01424|01425|01426|01427|01428|01429|01430|01431|01432|01434|01435|01436|01448|01449|01487|01512|01526|01549|01553|01611|01616|01618|01622|01623|01624|01626|01627|01639|01646|01647|01655|01678|01811|01812|01816|01818|01819|01821|01822|01823|01827|01828|01835|01836|01839|01862|01883|07052|07055|07062|07072|07134|07135|07136|07171|07175|07183|07205|07216|07222|07238|07311|07313|07321|07350|07361|07378|07398|07455|07458|07460|07463|07470|07471|07496|07502|07510|07513|07515|07517|07518|07519|07520|07521|07522|07523|07524|07525|07526|07527|07528|07529|07530|07531|07532|07533|07534|07535|07536|07537|07538|07539|07540|07541|07542|07543|07545|07546|07548|07549|07550|07551|07552|07553|07558|07559|07562|07563|07564|07569|07570|07571|07572|07573|07575|07576|07577|07580|07581|07582|07583|07584|07585|07586|07587|07588|07589|07591|07592|07593|07596|07597|07599|07600|07611|07613|07615|07617|07622|07624|07626|07633|07634|07636|07638|07642|07643|07644|07648|07650|07657|07658|07661|07663|07664|07665|07666|07667|07668|07669|07670|07671|07673|07675|07676|07677|07678|07679|07680|07681|07687|07689|07690|07691|07692|07697|07699|07703|07782|07833|07847|07855|07860|07872|07879|07890|07893|07898|07909|07944|07957|07992|07994|07995|07996|07997|01102|07005|07009|07028|07040|07064|07073|07090|07099|07176|07184|07231|07514|07516|07574|07509";

	

	if(validStores.indexOf(storeNum) > -1)
		return "true";
	else
		return "false";
}

function removeNL(s)
{
	var r = "";

	for (i=0; i < s.length; i++)
	{
		if (s.charAt(i) != '-')
			r += s.charAt(i);
    	}
	return r;
}

function zeroPad(oString,tLength)
{
	var nString = oString;
	if(oString.length < tLength)
	{
		for(var i=oString.length;i<tLength;i++)
			nString = "0"+nString;
	}
	return nString;
}

function sendmail(){
	document.form1.action="sendmail.jsp";
	document.form1.submit();
}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
   	{
   		validate();
   		return false;
   	}
	else
   		return true;
}