/*
===============================
  NLIS JavaScript Functions
===============================
*/

/* Cleans a multiline text field for spaces and breaks. */
function fCleanText35(arguments)
{
	var final_value = "";
	var temp_value = "";
	var brk = "";
	var arr = new Array();
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		arr = arguments.split('\r\n');
		brk = '\r\n';
	}
	else
	{
		arr = arguments.split('\n');
		brk = '\n';
	}
	for (var i=0; i<arr.length; i++)
	{
		temp_value = TrimString(arr[i]);
		
		//format RFID (16 numeric digit)
		if(temp_value.length == 15 && validateNumber(temp_value))
		{
		     temp_value = temp_value.substring(0,3) + " " + temp_value.substring(3,15);
	    }		
		//format RFID (16 numeric digit)
		
		if (temp_value.length > 0)
		{		
			if (final_value.length > 0)
				final_value += brk + temp_value;
			else
				final_value += temp_value;
		}
	}
	return final_value;
}


/* Cleans a multiline text field for spaces and breaks. */
function fCleanText(_control)
{
	var final_value = "";
	var temp_value = "";
	var brk = "";
	var arr = new Array();
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		arr = _control.value.split('\r\n');
		brk = '\r\n';
	}
	else
	{
		arr = _control.value.split('\n');
		brk = '\n';
	}
	for (var i=0; i<arr.length; i++)
	{
		temp_value = TrimString(arr[i]);
		
		//format RFID (16 numeric digit)
		if(temp_value.length == 15 && validateNumber(temp_value))
		{
		     temp_value = temp_value.substring(0,3) + " " + temp_value.substring(3,15);
	    }		
		//format RFID (16 numeric digit)
		
		if (temp_value.length > 0)
		{
			if (final_value.length > 0)
				final_value += brk + temp_value;
			else
				final_value += temp_value;
		}
	}
	_control.value = final_value;
}

/* Disables postback of control elements. */
function DisablePostback(evt)
{
	var whichkey;
	if (navigator.appName != "Microsoft Internet Explorer")
	{
		whichkey = evt.which;
	}
	else
	{
		whichkey = evt.keyCode;
	}
	
	if (whichkey == 13)
	{
		if (navigator.appName != "Microsoft Internet Explorer")
			evt.preventDefault();
		else
			evt.returnValue = false;
		return false;
	}
	else
	{
		return true;
	}
}

/* Shows or Hides an Element. */
function ShowHideElement(id)
{
	var obj = document.getElementById(id);
	if (obj.className == 'displayed')
	{
		obj.className = 'hidden';
	}
	else
	{
		obj.className = 'displayed';
	}
}

/* Validates for numbers. */
function validateNumber(str)
{
	var charset = "0123456789";
	for (var i=0; i<str.length; i++)
	{
		if (charset.indexOf(str.substr(i,1))<0)
		{
			return false;
		}
	}
	return true;
}
/* Validates for Characters. */
function validateChar(str)
{
	var charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	for (var i=0; i<str.length; i++)
	{
		if (charset.indexOf(str.substr(i,1))<0)
		{
			return false;
		}
	}
	return true;
}

/* Validates for Characters for FirstName and LastName. */
function ValCharForName(source, arguments)
{
    arguments = TrimString(arguments);
    var charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', ";
	if (arguments == "")
		return false;
	else
		{
			for (var i=0; i<arguments.length; i++)
			{
				if (charset.indexOf(arguments.substr(i,1))<0)
				{
					return false;
				}
			}
			return true;
		}

}


/* Validates old password (). */
function validateOldPassword(source, arguments)
{
	var result = true;
	if (arguments.length > 0)
	{
		if (arguments.indexOf(" ") >= 0)
		{
			result = false;
		}
	}
	else
	{
		result = false;
	}
	return result;
}

/* Validates a Required Field. */
function validateRequiredField(source, arguments)
{
	var result = true;
	if (arguments.length > 0)
	{
		if (arguments.indexOf(" ") >= 0)
		{
			result = false;
		}
		
		//the name can be alphanumeric with spaces and hyphens (-)
		var pattern = /^[a-zA-Z0-9&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#216;&#217;&#218;&#219;&#220;&#221;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#241;&#242;&#243;&#244;&#245;&#246;&#248;&#249;&#250;&#251;&#252;&#253;&#255;\.\,\-\/\']+[a-zA-Z0-9&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#216;&#217;&#218;&#219;&#220;&#221;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#241;&#242;&#243;&#244;&#245;&#246;&#248;&#249;&#250;&#251;&#252;&#253;&#255;\.\,\-\/\' ]+$/; 
				
		if(arguments.search(pattern)== -1)
		{
			return false;
		}
		
		//XML well-formed validation
		if (arguments.indexOf(">") >= 0 || arguments.indexOf("<") >= 0 || arguments.indexOf("&") >= 0 || arguments.indexOf("'") >= 0)
		{
			result = false;
		}		
	}
	else
	{
		result = false;
	}
	return result;
}

function validateCSVComment(source, arguments) {
    var result = true;
    //remove blank spaces
    arguments = TrimString(arguments);

    if (arguments.length > 255) {
        arguments = arguments.substring(0, 255);
    }

    if (arguments.length > 0) {
	    var pattern = /^[a-zA-Z0-9 ]+$/; 	
	    return (arguments.search(pattern) != -1);        
    }
    return result;
}

	function validateComment(source, arguments)
	{
		var result = true;
		var txtComment = document.getElementById("BaseMP_BaseMasterPageContent_txtComment");
		//remove blank spaces
		arguments = txtComment.value =  TrimString(txtComment.value);
		
		if(arguments.length > 255)
		{
			arguments = txtComment.value =  txtComment.value.substring(0,255);
		}
		
		if (arguments.length > 0)
		{
			return validateTextAndCharacters(source, arguments)
		}
		else
		{
			result = true;
		}
		return result;		
	}


/* Validates a Text. */
function validateText(source, arguments)
{
	var result = true;
	if (arguments.length > 0)
	{
		return validateTextAndCharacters(source, arguments)
	}
	else
	{
		result = false;
	}
	return result;
}

function validateTextAndCharacters(source, arguments)
{
	var result = true;
	if (arguments.charAt(0) == " ")
	{
		result = false;
	}
	
	//the name can be alphanumeric with spaces and hyphens (-)
	var pattern = /^[a-zA-Z0-9&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#216;&#217;&#218;&#219;&#220;&#221;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#241;&#242;&#243;&#244;&#245;&#246;&#248;&#249;&#250;&#251;&#252;&#253;&#255;\.\,\-\/\']+[a-zA-Z0-9&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#216;&#217;&#218;&#219;&#220;&#221;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#241;&#242;&#243;&#244;&#245;&#246;&#248;&#249;&#250;&#251;&#252;&#253;&#255;\.\,\-\/\' ]+$/; 
	
	if(arguments.lenght>0 &&  arguments.search(pattern)== -1)
	{
		return false;
	}
	
	//XML well-formed validation
	if (arguments.indexOf(">") >= 0 || arguments.indexOf("<") >= 0 || arguments.indexOf("&") >= 0 || arguments.indexOf("'") >= 0)
	{
		result = false;
	}
	return result;
}

//////////GLOBAL VARIABLES//////////////
//The variables for the valid first chareacters for all state's pics
var newvicpicfirstchar = "3";	//New victorian
var oldvicpicfirstchar = "V";	//Old victorian
var taspicfirstchar = "M";		//Tasmanian
var nswpicfirstchar = "N";		//New South Wales
var qldpicfirstchar = "Q";		//Queensland
var sapicfirstchar = "S";		//South Australia
var ntpicfirstchar = "T";		//Northern Territory
var wapicfirstchar = "W";		//Western Australia
var firstCharValueEMER	= "Z";	// Emergency
var firstCharValueTEST	= "P";	// Testing Propeties
var firstCharValueAbattoir = "E"; // Abattoirs
var firstCharValueIndonesiaPIC = "D"; // Indonesia Feedlot

//Ascii values for the state's first characters
var asciivaluefornewvicpicfirstchar = "3";
var asciivalueforoldvicpicfirstchar = oldvicpicfirstchar.charCodeAt(0);
var asciivaluefortaspicfirstchar = taspicfirstchar.charCodeAt(0);
var asciivaluefornswpicfirstchar = nswpicfirstchar.charCodeAt(0);
var asciivalueforqldpicfirstchar = qldpicfirstchar.charCodeAt(0);
var asciivalueforsapicfirstchar = sapicfirstchar.charCodeAt(0);
var asciivalueforntpicfirstchar = ntpicfirstchar.charCodeAt(0);
var asciivalueforwapicfirstchar =  wapicfirstchar.charCodeAt(0);

//The variables for holding the submitted PIC value
var picvalue;
//The variable to hold the results of the modulus algrithm 
var modulusequationresults;
//The constants for processing
var charuppercaseletterA = "A";
var charuppercaseletterZ = "Z";
var charuppercaseletterM = "M";
var charuppercaseletterB = "B";
var charuppercaseletterX = "X";
var charuppercaseletterK = "K";
var charuppercaseletterD = "D";
var charuppercaseletterG = "G";
var charuppercaseletterR = "R";
var charuppercaseletterC = "C";
var charuppercaseletterE = "E";
var charuppercaseletterF = "F";
var charuppercaseletterH = "H";
var charuppercaseletterI = "I";
var charuppercaseletterJ = "J";
var digit0 = "0".charCodeAt(0);
var digit9 = "9".charCodeAt(0);
var asciivalueofcapitalA = charuppercaseletterA.charCodeAt(0);
var asciivalueofcapitalZ = charuppercaseletterZ.charCodeAt(0);
var asciivalueofcapitalM = charuppercaseletterM.charCodeAt(0);
var asciivalueofcapitalB = charuppercaseletterB.charCodeAt(0);
var asciivalueofcapitalX = charuppercaseletterX.charCodeAt(0);
var asciivalueofcapitalK = charuppercaseletterK.charCodeAt(0);
var asciivalueofcapitalD = charuppercaseletterD.charCodeAt(0);
var asciivalueofcapitalG = charuppercaseletterG.charCodeAt(0);
var asciivalueofcapitalR = charuppercaseletterR.charCodeAt(0);
var asciivalueofcapitalC = charuppercaseletterC.charCodeAt(0);
var asciivalueofcapitalE = charuppercaseletterE.charCodeAt(0);
var asciivalueofcapitalF = charuppercaseletterF.charCodeAt(0);
var asciivalueofcapitalH = charuppercaseletterH.charCodeAt(0);
var asciivalueofcapitalI = charuppercaseletterI.charCodeAt(0);
var asciivalueofcapitalJ = charuppercaseletterJ.charCodeAt(0);
var asciivalueofcapitalS = asciivalueforsapicfirstchar;
var asciivalueofcapitalT = asciivalueforntpicfirstchar;
var asciivalueofcapitalV = asciivalueforoldvicpicfirstchar;
var asciivalueofdigit0 = digit0;
var asciivalueofdigit9 = digit9;

///////////////MAIN FUNCTION/////////////////
function checksinglepic4CompGrp(source, arguments)
{
	var piclen = arguments.length;
	if (piclen == 0)
		return true;
	else
		return checksinglepic(source, arguments);
	
}

function CheckNLISID_RFID4CompGrp(source, arguments)
{
	var TagLen = arguments.length;
	if (TagLen == 0)
		return true;
	else
		return CheckNLISID_RFID(source, arguments);
	
}
function CheckDestPIC4LiveX(source, arguments)
{
	if (arguments.toUpperCase() == 'EEEEEEEE')
		return true;
	else
		return checksinglepic(source, arguments);
}

//same as checksinglepic but OPTIONAL
function checksinglepic_ISNULL(source, arguments)
{
	var tmp =  TrimString(arguments);
	if (tmp == "")
	{
		arguments.IsValid=true;
		return true;
	}
	else
	{
		return checksinglepic(source, arguments);
	}
}

function checksinglepic(source, arguments)
{
// 05.01.2010 hugo rodriguez
// MLA-1830 NOT show the error alert FOR MANUALMOBBASEDKILL webform
	var hidealert = false;
	if (source != null)
		if (source.id=="ManualMobBasedKilltxtOtherPICS")
			hidealert = true;
	var piclen = arguments.length;
	if (piclen != 8)
		{
			arguments.IsValid=false;
			return false;
		}
	else
		{
			//Get the value for the PIC submitted and the first character
			picvalue = arguments;
			//Convert all the characters submitted into upper case
			picvalue = picvalue.toUpperCase();
			if (picvalue=='DECEASED' || picvalue=='AAAAAAAA' )
			{
				arguments.IsValid=true;
				return true;	
			}
			//alert(picvalue);
			//Get the first character from the submitted value
			var firstpichar = picvalue.substr(0,1);
			
			//Check to see if the first character is a valid for the first character of a PIC
			if (!(isvalidfirstchar(firstpichar, hidealert)))
				{
					//it isnt no processing
					arguments.IsValid=false;
					return false;
				}
			else
				{
					//we have a valid first character so we must check the whole PIC code
					//based on which state they belong to
					//var asciivalueforfirstchar = picvalue.charCodeAt(0)
					var asciivalueforfirstchar = picvalue.substr(0,1);
					//We can only do switches on numbers not strings
					
					switch(asciivalueforfirstchar)
					{
					
							case asciivaluefornewvicpicfirstchar:
							
								//Do VIC PIC check
								if (!(checknewvicpic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid New Victorian Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case oldvicpicfirstchar:
								//Do VIC PIC check
								if (!(checkoldvicpic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid Old Victorian Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case taspicfirstchar:
								//Do TAS PIC check
								if (!(checktaspic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid Tasmanian Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case nswpicfirstchar:
								//Do NSW PIC check
								if (!(checknswpic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid New South Wales Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case qldpicfirstchar:
								//Do QLD PIC check
								if (!(checkqldpic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid Queensland Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case sapicfirstchar:
								//Do south australia PIC check
								if (!(checksapic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid South Australian Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case ntpicfirstchar:
								//Do NT PIC check
								if (!(checkntpic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid Northern Territory Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case wapicfirstchar:
								//Do WA PIC check
								if (!(checkwapic(picvalue)))
									{
										if (!hidealert)
											alert(picvalue+": Invalid Western Australian Property Identification Code");
										arguments.IsValid=false;
										return false;
										break;
									}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case firstCharValueEMER:
								if (!isEmergencyTag(picvalue))
								{
									arguments.IsValid=false;
									return false;
									break;
								}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
								break;
							case firstCharValueTEST:
								if (!validTESTPIC(picvalue))
								{
									arguments.IsValid=false;
									return false;
									break;
								}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
							case firstCharValueAbattoir:
								if (!validAbattoirPIC(picvalue))
								{
									arguments.IsValid=false;
									return false;
									break;
								}
								else
									{
										arguments.IsValid=true;	
										return true;
										break;
									}
						        break;
						    case firstCharValueIndonesiaPIC:
		                        if (!validIndonesiaPIC(picvalue)) {
		                            arguments.IsValid = false;
		                            return false;
		                            break;
		                        }
		                        else {
		                            arguments.IsValid = true;
		                            return true;
		                            break;
		                        }
		                        break;                                	
							default:
								//Error in processing
								if (!hidealert)
									alert(picvalue+": ERROR IN PROCESSING - PLEASE CALL 1800 NLISID OR 1800 654 742 AND INFORM THE HELPDESK OF THIS ERROR");
								arguments.IsValid=false;
								return false;
								return;
						}
				}
		}
}


function checkmultiplepic(source, arguments)
{
	var tmp =  TrimString(arguments);
	if (tmp == "")
		{
			arguments.IsValid=false;
			return false;
		}
	var result=true;	
	var message="";	
	var arrpics = new Array();
	
	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer")
		arrpics = arguments.split('\r\n');
	else
		arrpics = arguments.split('\n');
	
	for (var i = 0; i< arrpics.length ; i++)
        {
            //If the length of the value in the input is not equal to eight then return
            
            var trimedPIC = TrimString(arrpics[i])
            var piclen = trimedPIC.length;
            if (arrpics.length>0 && piclen == 0)
            {
				alert("Please remove any blank lines in the provided list");
				return false;
            }
			//var piclen = arrpics[i].length;
			if (piclen != 8)
				{
					//alert(piclen);
					//arguments.focus();
					message=message+arrpics[i]+": invalid PIC!\r\n";
					result=false;
					//arguments.IsValid=false;
					//return false;
				}
			else
				{
					//Get the value for the PIC submitted and the first character
					picvalue = arrpics[i];
					//Convert all the characters submitted into upper case
					picvalue = picvalue.toUpperCase();
					//alert(picvalue);
					//Get the first character from the submitted value
					var firstpichar = picvalue.substr(0,1);
					
					//Check to see if the first character is a valid for the first character of a PIC
					if (!(isvalidfirstchar(firstpichar, false)))
						{
							//it isnt no processing
							//arguments.IsValid=false;
							//return false;
							message=message+arrpics[i]+": invalid first character\r\n";
							result=false;
						}
					else
						{
							//we have a valid first character so we must check the whole PIC code
							//based on which state they belong to
							//var asciivalueforfirstchar = picvalue.charCodeAt(0)
							var asciivalueforfirstchar = picvalue.substr(0,1);
							//We can only do switches on numbers not strings
							
							switch(asciivalueforfirstchar)
							{
							
									case asciivaluefornewvicpicfirstchar:
									
										//Do VIC PIC check
										if (!(checknewvicpic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid New Victorian Property Identification Code!\r\n";
												result=false;
												
												//alert("Line(" + (i+1) + ") Invalid New Victorian Property Identification Code");
												//arguments.IsValid=false;
												//return false;
												
											}
										break;
									case oldvicpicfirstchar:
										//Do VIC PIC check
										if (!(checkoldvicpic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid Old Victorian Property Identification Code!\r\n";
												result=false;
												
											}
										break;
									case taspicfirstchar:
										//Do TAS PIC check
										if (!(checktaspic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid Tasmanian Property Identification Code!\r\n";
												result=false;
											}
										break;
									case nswpicfirstchar:
										//Do NSW PIC check
										if (!(checknswpic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid New South Wales Property Identification Code!\r\n";
												result=false;
											}
										break;
									case qldpicfirstchar:
										//Do QLD PIC check
										if (!(checkqldpic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid Queensland Property Identification Code!\r\n";
												result=false;
											}
										break;
									case sapicfirstchar:
										//Do south australia PIC check
										if (!(checksapic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid South Australian Property Identification Code!\r\n";
												result=false;
											}
										break;
									case ntpicfirstchar:
										//Do NT PIC check
										if (!(checkntpic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid Northern Territory Property Identification Code!\r\n";
												result=false;
											}
										break;
									case wapicfirstchar:
										//Do WA PIC check
										if (!(checkwapic(picvalue)))
											{
												message=message+arrpics[i]+": Invalid Western Australian Property Identification Code!\r\n";
												result=false;
											}
										break;
									case firstCharValueEMER:
										if (!isEmergencyTag(picvalue))
											{
												message=message+arrpics[i]+": Invalid Western Australian Property Identification Code!\r\n";
												result=false;
												break;
											}
										else
											break;
							case firstCharValueTEST:
								if (!validTESTPIC(picvalue))
								{
									message=message+arrpics[i]+": Invalid Test PIC!\r\n";
									result=false;
								}
								break;
							case firstCharValueAbattoir:
								if (!validAbattoirPIC(picvalue))
								{
									message=message+arrpics[i]+": Invalid Abattoir PIC!\r\n";
									result=false;
								}
					            break;
					        case firstCharValueIndonesiaPIC:
					            if (!validIndonesiaPIC(picvalue)) {
	                                message = message + arrpics[i] + ": Invalid Indonesia PIC!\r\n";
	                                result = false;
	                            }
	                            break;
							default:
										//Error in processing
										message=message+arrpics[i]+": ERROR IN PROCESSING - PLEASE CALL 1800 NLISID OR 1800 654 742 AND INFORM THE HELPDESK OF THIS ERROR!\r\n";
										result=false;
								}
						}
				}
		}
		
		if(result)
			return true;
		else
			{
				alert(message);
				return false;
			}	
				
}

function CheckMultipleRFID(source, arguments)
	{
		
		var tmp =  TrimString(arguments);
		if (tmp == "")
			{
				return false;
			}
		var result=true;	
		var arrRFID = new Array();
		
		var browserName=navigator.appName; 
		if (browserName=="Microsoft Internet Explorer")
			arrRFID = arguments.split('\r\n');
		else
			arrRFID = arguments.split('\n');
	
		var DefectedRFID="";
		for (var i = 0; i< arrRFID.length ; i++)
			{
				if (arrRFID[i].length == 0)
				{
					alert("Please remove any blank lines in your RFID list.");
					return false;
				}
				else if (!CheckRFID(source,arrRFID[i]))
				{
					DefectedRFID += arrRFID[i]+"\n";
					//alert("RFID(s) you have inserted is(are) not Valid");
					result=false;
				}
			}
		if (!result)
		{
			alert("The following RFID(s) you have entered are not valid \n" + DefectedRFID);
		}
		return result;
	}

	/*Validates PBT serial number format and to check if this is paid already (server process)*/
	function ValidatePBT(textValue)
	{
		//alert(textValue.value);
		var val = TrimString(textValue.value).toUpperCase();
		textValue.value = val;
		var len = val.length;
		var isOK = true;
		
		if (len == 0)
		{
			return;
		}
		
		if (len <= 10)
		{
			if (val.indexOf(" ") >= 0)
			{
				alert("The PBT Serial Number " + val + " must have alphanumeric characters only.");
				textValue.value = "";
				isOK = false;
				document.getElementById("mControlGenerator_1_mTextBox").focus();
			}
			
			var pattern = "^[a-zA-Z0-9]+$"; //Alphanumeric pattern
			if(val.search(pattern)== -1)
			{
				alert("The PBT Serial Number " + val + "  must have alphanumeric characters only.");
				textValue.value = "";
				isOK = false;
				document.getElementById("mControlGenerator_1_mTextBox").focus();
			}						
		}
		else
		{
			alert("The PBT Serial Number should not have more than 10 alphanumeric characters.");
			textValue.value = "";
			isOK = false;
			document.getElementById("mControlGenerator_1_mTextBox").focus();
		}		
		
		if(isOK)
		{
			//var btn = document.getElementById("btnServerEvent");
			//if (btn) btn.click();						    
			__doPostBack('BaseMP$BaseMasterPageContent$btnServerEvent','');
            event.keyCode = 0			
		}
	}
	
	/*Validates PBT serial number format and to check if this is paid already (server process)*/
	function ValidatePBT_NWA(textValue)
	{
		//alert(textValue.value);
		var val = TrimString(textValue.value).toUpperCase();
		textValue.value = val;
		var len = val.length;
		var isOK = true;
		
		if (len == 0)
		{
			return;
		}
		
		if (len <= 10)
		{
			if (val.indexOf(" ") >= 0)
			{
				alert("The PBT Serial Number " + val + " must have alphanumeric characters only.");
				textValue.value = "";
				isOK = false;
				document.getElementById("BaseMP_BaseMasterPageContent_txtPBTSerialNumber").focus();
			}
			
			var pattern = "^[a-zA-Z0-9]+$"; //Alphanumeric pattern
			if(val.search(pattern)== -1)
			{
				alert("The PBT Serial Number " + val + "  must have alphanumeric characters only.");
				textValue.value = "";
				isOK = false;
				document.getElementById("BaseMP_BaseMasterPageContent_txtPBTSerialNumber").focus();
			}						
		}
		else
		{
			alert("The PBT Serial Number should not have more than 10 alphanumeric characters.");
			textValue.value = "";
			isOK = false;
			document.getElementById("BaseMP_BaseMasterPageContent_txtPBTSerialNumber").focus();
		}		
		
		if(isOK)
		{
			//var btn = document.getElementById("btnServerEvent");
			//if (btn) btn.click();						    
			__doPostBack('BaseMP$BaseMasterPageContent$btnServerEvent','');
            event.keyCode = 0			
		}
	}		


	/*Validates PBT serial number is an alphanumeric field of length 10*/
	function CheckPBT(source, arguments)
	{
		var val = TrimString(arguments);
		var len = val.length;
		var result = true;
		
		if (len <= 10)
		{
			if (val.indexOf(" ") >= 0)
			{
				result = false;
				return result;
			}
			
			var pattern = "^[a-zA-Z0-9]+$"; //Alphanumeric pattern
			if(val.search(pattern)== -1)
			{
				result = false;
				return result;
			}			
		}
		else
		{
			result = false;
		}
		return result;		
	}

	/*Validates Establishment number is an alphanumeric field of length 7*/
	function CheckEstabNo(source, arguments)
	{
		var val = TrimString(arguments);
		var len = val.length;
		var result = true;
		
		if (len <= 7)
		{
			if (val.indexOf(" ") >= 0)
			{
				result = false;
				return result;
			}
			
			var pattern = "^[a-zA-Z0-9]+$"; //Alphanumeric pattern
			if(val.search(pattern)== -1)
			{
				result = false;
				return result;
			}			
		}
		else
		{
			result = false;
		}
		return result;		
	}

	/* Validates the Saleyard ID. */
	function CheckSaleyardID(source, arguments)
	{
		
		var len = arguments.length;
		var val = arguments;
		var val_upper = arguments.toUpperCase();
		var digitcount = 0;
		var result = true;
		if (len > 0)
		{
			if (val.indexOf(" ") >= 0)
			{
				result = false;
				return result;
			}
			if (val_upper.indexOf("EUSY") == 0 || val_upper.indexOf("NLSY") == 0)
			{
				for (var i=4; i<len; i++)
				{
					var current = val.charAt(i);
					if (current != "")
					{
						if (validateNumber(current))
						{
							digitcount = digitcount + 1;
						}
					}
				}
				if (digitcount != 4)
				{
					result = false;
				}
			}
			else
			{
				result = false;
			}
		}
		else
		{
			result = false;
		}
		return result;
		
	}
	
	/* Validates the Saleyard ID or Saleyard PIC. */
	function CheckSaleyardIDorPIC(source, arguments)
	{
		
		var len = arguments.length;
		var val = arguments;
		var val_upper = arguments.toUpperCase();
		var digitcount = 0;
		var result = true;
		if (len > 0)
		{
			if (val.indexOf(" ") >= 0)
			{
				result = false;
				return result;
			}
			if (val_upper.indexOf("EUSY") == 0 || val_upper.indexOf("NLSY") == 0)
			{
				for (var i=4; i<len; i++)
				{
					var current = val.charAt(i);
					if (current != "")
					{
						if (validateNumber(current))
						{
							digitcount = digitcount + 1;
						}
					}
				}
				if (digitcount != 4)
				{
					result = false;
				}
			}
			else
			{
				return checksinglepic(source, arguments);						
			}
		}
		else
		{
			result = false;
		}
		return result;
		
	}	

/* Validates the RFID. */
	function CheckRFID(source, arguments)
	{
		var len = arguments.length;
		var val = arguments;
		var val_upper = arguments.toUpperCase();
		var current;
		var i;
		
			if (len == 0 || len != 16)
			{
				return false;
			}
			if (val.indexOf(" ") != 3)
			{
				return false;
			}
			for (i=0; i<3; i++)
			{
				current = val.charAt(i);
				if (current != "")
				{
					if (!isNum(current.charCodeAt(0)))
					{
						return false;
					}
				}
			}
			
			for (i=4; i<len; i++)
			{
				current = val.charAt(i);
				if (current != "")
				{
					if (!isNum(current.charCodeAt(0)))
					{
						return false;
					}
				}
			}
	return true;
}
/* Validates the RFID. */
function CheckNLISID(source, arguments)
{
	var len = arguments.length;
	var i;
	if ( !validateChar(arguments) || (len != 16 && len != 15) || arguments.indexOf(" ") != -1)
	{
		return false;
	}	
	return true;
	
}

/* Validates the RFID. */
function CheckNLISID_RFID(source, arguments)
{
	if(CheckNLISID(source,arguments) || CheckRFID(source,arguments))
	{
		return true;
	}	
	return false;
}

//same as CheckMultipleNLISID_RFID but OPTIONAL
function CheckNLISID_RFID_ISNULL(source, arguments)
{
	var tmp =  TrimString(arguments);
	if (tmp == "")
	{
		arguments.IsValid=true;
		return true;
	}
	else
	{
		return CheckMultipleNLISID_RFID(source, arguments);
	}
}

function CheckMultipleNLISID_RFID(source, arguments)
	{
		var tmp =  TrimString(arguments);
		if (tmp == "")
			{
				return false;
			}
		var result=true;	
		var arrNLISID_RFID = new Array();

		var browserName=navigator.appName; 
		if (browserName=="Microsoft Internet Explorer")
			arrNLISID_RFID = arguments.split('\r\n');
		else
			arrNLISID_RFID = arguments.split('\n');
		
		var DefectedNLISID_RFID="";
		
		for (var i = 0; i< arrNLISID_RFID.length ; i++)
			{
				if (arrNLISID_RFID[i].length == 0)
				{
					alert("Please remove any blank lines in your NLISID/RFID list.");
					return false;
				}
				else if (!CheckNLISID_RFID(source,arrNLISID_RFID[i]))
				{
					DefectedNLISID_RFID += arrNLISID_RFID[i]+"\n";
					result=false;
				}
			}
		if (!result)
		{
			alert("The following NLISID/RFID(s) you have entered are not valid \n" + DefectedNLISID_RFID);
		}
		return result;
	}

/* Validates the PhoneNumber. */
function CheckPhoneNumber(source, arguments)
{
	var len = arguments.length;
	if (len != 10)
	{
		return false;
	}
	return validateNumber(arguments);
}

/* Validates the Number. */
function CheckIsNumeric(source, arguments)
{
	var len = arguments.length;
	if (len == 0)
	{
		return false;
	}
	return validateNumber(arguments);
}
/* Validates the control is null or integer. */
function CheckIsNullOrNumeric(source, arguments)
{
	var len = arguments.length;
	if (len == 0)
	{
		return true;
	}
	else
	{
		return validateNumber(arguments);
	}
}


/* Validates the Number. */
function CheckIsPercentage(source, arguments)
{
	var len = arguments.length;
	if (len == 0 || !validateNumber(arguments))
	{
		return false;
	}
	 if (arguments > 100)
		return false
	
	return true;	
	
}


//Function to check that the first character submitted is a valid PIC first character
function isvalidfirstchar(firstchar,hidealert)
{
    if (firstchar == newvicpicfirstchar || firstchar == oldvicpicfirstchar || firstchar == taspicfirstchar || firstchar == nswpicfirstchar || firstchar == qldpicfirstchar || firstchar == sapicfirstchar || firstchar == ntpicfirstchar || firstchar == wapicfirstchar || firstchar == firstCharValueEMER || firstchar == firstCharValueTEST || firstchar == firstCharValueAbattoir || firstchar == firstCharValueIndonesiaPIC)
	{
		return true;
	}
	else
	{
		if (!hidealert)
			alert("The Property Identification Code entered has an invalid first character = "+ firstchar );
		return false;
	}   
}
//We currently do not have any algorithm for the Northern territory - all are considered valid
function checkntpic(pic)
{
	var pos2;
	var pos34;
		
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
	//first character is a 'T' then alpha <=K, alpha, alpha, numeric, numeric, numeric, numeric
	if( (pic.charCodeAt(0) != asciivalueforntpicfirstchar)||
		(pic.charCodeAt(1) < asciivalueofcapitalA || pic.charCodeAt(1) > asciivalueofcapitalK) ||
		(pic.charCodeAt(2) < asciivalueofcapitalA || pic.charCodeAt(2) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(3) < asciivalueofcapitalA || pic.charCodeAt(3) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(4) < asciivalueofdigit0 || pic.charCodeAt(4) > asciivalueofdigit9) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9) )
	{
		return false;
	}
	else //PIC has first char correct and the correct alphanumeric structure
	{
		//alert("in else statement");
		//2nd char must be between a and k
		switch(pic.charCodeAt(1))
		{
			case asciivalueofcapitalA:
				pos2 = 90;
				break;
			case asciivalueofcapitalB:
				pos2 = 0;
				break;
			case asciivalueofcapitalC:
				pos2 = 9;
				break;
			case asciivalueofcapitalD:
				pos2 = 18;
				break;
			case asciivalueofcapitalE:
				pos2 = 27;
				break;
			case asciivalueofcapitalF:
				pos2 = 36;
				break;
			case asciivalueofcapitalG:
				pos2 = 45;
				break;
			case asciivalueofcapitalH:
				pos2 = 54;
				break;
			case asciivalueofcapitalI:
				pos2 = 63;
				break;
			case asciivalueofcapitalJ:
				pos2 = 72;
				break;
			case asciivalueofcapitalK:
				pos2 = 81;
				break;
			default:
				return false;
		}
		
		//3rd and 4th char must be AS, DG, BT, or VR
		switch(pic.charCodeAt(2))
		{
			case asciivalueofcapitalA:
				if(pic.charCodeAt(3) == asciivalueofcapitalS)
				{
					pos34 = 179;
				}
				else
				{
					return false;
				}
				break;
			
			case asciivalueofcapitalD:
				if(pic.charCodeAt(3) == asciivalueofcapitalG)
				{
					pos34 = 94;
				}
				else
				{
					return false;
				}
				break;
			case asciivalueofcapitalB:
				if(pic.charCodeAt(3) == asciivalueofcapitalT)
				{
					pos34 = 84;
				}
				else
				{
					return false;
				}
				break;
			case asciivalueofcapitalV:
				if(pic.charCodeAt(3) == asciivalueofcapitalR)
				{
					pos34 = 164;
				}
				else
				{
					return false;
				}
				break;
			default:
				return false;
		}
		
		//Run the check to certify the PIC code	
		var compareval = (pos2 + pos34) + ((pic.charCodeAt(4)-48)*8 + (pic.charCodeAt(5)-48)*4 + (pic.charCodeAt(6)-48)*2 + (pic.charCodeAt(7)-48)*1);
		//alert("step 3:  " + compareval);
		var finalresult = Math.round(compareval / 11);
		finalresult = 11 * finalresult;
		//alert("final: " + finalresult);
		if(finalresult == compareval)
		{
				return true;
		}
	return false;
	}
	
}
//Function to check that the submitted Tasmanian Property Identification Code is a valid PIC code
function checktaspic(pic)
{
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
	if ( (pic.charCodeAt(1) < asciivalueofcapitalA || pic.charCodeAt(1) > asciivalueofcapitalK) ||
		(pic.charCodeAt(2) < asciivalueofcapitalA || pic.charCodeAt(2) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(3) < asciivalueofcapitalA || pic.charCodeAt(3) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(4) < asciivalueofdigit0 || pic.charCodeAt(4) > asciivalueofdigit9) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9) )
		{
			return false;
		}
	//Run the modular check to certify the PIC code	
	modulusequationresults = (2816+(pic.charCodeAt(1)-55)*64+(pic.charCodeAt(2)-55)*32+(pic.charCodeAt(3)-55)*16+(pic.charCodeAt(4)-48)*8+(pic.charCodeAt(5)-48)*4+(pic.charCodeAt(6)-48)*2+(pic.charCodeAt(7)-48))%11;
	//alert(modulusequationresults);
	if (modulusequationresults == 0)
		{
				return true;
		}
	return false;
}
//Function to check that the submitted Queensland Property Identification Code is a valid PIC code
function checkqldpic(pic)
{
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
	if ( (pic.charCodeAt(1) < asciivalueofcapitalA || pic.charCodeAt(1) > asciivalueofcapitalK) ||
		(pic.charCodeAt(2) < asciivalueofcapitalA || pic.charCodeAt(2) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(3) < asciivalueofcapitalA || pic.charCodeAt(3) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(4) < asciivalueofdigit0 || pic.charCodeAt(4) > asciivalueofdigit9) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9) )
		{
			return false;
		}
	//Run the modular check to certify the PIC code	
	modulusequationresults = (128*(pic.charCodeAt(0)-asciivalueofcapitalA+10)+64*(pic.charCodeAt(1)-asciivalueofcapitalA+10)+32*(pic.charCodeAt(2)-asciivalueofcapitalA+10)+16*(pic.charCodeAt(3)-asciivalueofcapitalA+10)+8*(pic.charCodeAt(4)-asciivalueofdigit0)+4*(pic.charCodeAt(5)-asciivalueofdigit0)+2*(pic.charCodeAt(6)-asciivalueofdigit0)+(pic.charCodeAt(7)-asciivalueofdigit0))%11;
	//alert(modulusequationresults);
	if (modulusequationresults == 0)
		{
				return true;
		}
	return false;
}
//Function to check that the submitted New South Wales Property Identification Code is a valid PIC code
function checknswpic(pic)
{
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
	if ( (pic.charCodeAt(1) < asciivalueofcapitalA || pic.charCodeAt(1) > asciivalueofcapitalK) ||
		(pic.charCodeAt(2) < asciivalueofdigit0 || pic.charCodeAt(2) > asciivalueofdigit9) ||
		(pic.charCodeAt(3) < asciivalueofdigit0 || pic.charCodeAt(3) > asciivalueofdigit9) ||
		(pic.charCodeAt(4) < asciivalueofdigit0 || pic.charCodeAt(4) > asciivalueofdigit9) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9) )
		{
			return false;
		}
	//Run the modular check to certify the PIC code	
	modulusequationresults = (128*12+64*(pic.charCodeAt(1)-asciivalueofcapitalA+10)+32*(pic.charCodeAt(2)-asciivalueofdigit0)+16*(pic.charCodeAt(3)-asciivalueofdigit0)+8*(pic.charCodeAt(4)-asciivalueofdigit0)+4*(pic.charCodeAt(5)-asciivalueofdigit0)+2*(pic.charCodeAt(6)-asciivalueofdigit0)+(pic.charCodeAt(7)-asciivalueofdigit0))%11;
	//alert(modulusequationresults);
	if (modulusequationresults == 0)
		{
			return true;
		}
	return false;
}
//Function to check that the submitted New Victorian Property Identification Code is a valid PIC code
function checknewvicpic(pic)
{
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
	if ( (pic.charCodeAt(1) < asciivalueofcapitalA || pic.charCodeAt(1) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(2) < asciivalueofcapitalA || pic.charCodeAt(2) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(3) < asciivalueofcapitalA || pic.charCodeAt(3) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(4) < asciivalueofcapitalA || pic.charCodeAt(4) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9) )
		{
			return false;
		}
	//Run the modular check to certify the PIC code		
	modulusequationresults = (128*(pic.charCodeAt(0)-48)+64*(pic.charCodeAt(1)-55)+32*(pic.charCodeAt(2)-55)+16*(pic.charCodeAt(3)-55)+8*(pic.charCodeAt(4)-55)+4*(pic.charCodeAt(5)-48)+2*(pic.charCodeAt(6)-48)+(pic.charCodeAt(7)-48))%23;
	//alert(modulusequationresults);
	if (modulusequationresults == 0)
		{
			return true;
		}
	return false;
}
//Function to check that the submitted Old Victorian Property Identification Code is a valid PIC code
function checkoldvicpic(pic)
{
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
	if ( (pic.charCodeAt(1) < asciivalueofcapitalA || pic.charCodeAt(1) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(2) < asciivalueofcapitalA || pic.charCodeAt(2) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(3) < asciivalueofcapitalA || pic.charCodeAt(3) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(4) < asciivalueofdigit0 || pic.charCodeAt(4) > asciivalueofdigit9) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9) )
		{
			return false;
		}
	//Run the modular check to certify the PIC code
	modulusequationresults = (128*(pic.charCodeAt(0)-55)+64*(pic.charCodeAt(1)-55)+32*(pic.charCodeAt(2)-55)+16*(pic.charCodeAt(3)-55)+8*(pic.charCodeAt(4)-48)+4*(pic.charCodeAt(5)-48)+2*(pic.charCodeAt(6)-48)+(pic.charCodeAt(7)-48))%11;
	//alert(modulusequationresults);
	if (modulusequationresults == 0)
		{
			return true;
		}
	return false;
}
//Function to check that the submitted South Australian Property Identification Code is a valid PIC code
function checksapic(pic)
{
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
		
	if  ((pic.charCodeAt(1) < asciivalueofcapitalA) || (pic.charCodeAt(1) > asciivalueofcapitalK) ||
		(pic.charCodeAt(2) < asciivalueofdigit0 || pic.charCodeAt(2) > asciivalueofdigit9) ||
		(pic.charCodeAt(3) < asciivalueofdigit0 || pic.charCodeAt(3) > asciivalueofdigit9) ||
		(pic.charCodeAt(4) < asciivalueofdigit0 || pic.charCodeAt(4) > asciivalueofdigit9) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9))
		{
			return false;
		}
	
	//alert("Past the first check");
	//Run the modular check to certify the PIC code	
	modulusequationresults = (128*(6)+64*(pic.charCodeAt(1))+32*(pic.charCodeAt(2)-asciivalueofdigit0)+16*(pic.charCodeAt(3)-asciivalueofdigit0)+8*(pic.charCodeAt(4)-asciivalueofdigit0)+4*(pic.charCodeAt(5)-asciivalueofdigit0)+2*(pic.charCodeAt(6)-asciivalueofdigit0)+(pic.charCodeAt(7)-asciivalueofdigit0))%11;
	//alert(modulusequationresults);
	if (modulusequationresults == 0)
		{
			return true;
		}
	return false;
}
//Function to check that the submitted Western Australia Property Identification Code is a valid PIC code
function checkwapic(pic)
{
	if ((checkemergencytags(pic)))
	{
		alert("This is an Emergency TailTag");
		return true;
	}
	var changedvalueforsecondcharacter;
	var changedvalueforthirdcharacter;
	var changedvalueforfourthcharacter;
	if ( (pic.charCodeAt(1) < asciivalueofcapitalA || pic.charCodeAt(1) > asciivalueofcapitalK) ||
		(pic.charCodeAt(2) < asciivalueofcapitalA || pic.charCodeAt(2) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(3) < asciivalueofcapitalA || pic.charCodeAt(3) > asciivalueofcapitalZ) ||
		(pic.charCodeAt(4) < asciivalueofdigit0 || pic.charCodeAt(4) > asciivalueofdigit9) ||
		(pic.charCodeAt(5) < asciivalueofdigit0 || pic.charCodeAt(5) > asciivalueofdigit9) ||
		(pic.charCodeAt(6) < asciivalueofdigit0 || pic.charCodeAt(6) > asciivalueofdigit9) ||
		(pic.charCodeAt(7) < asciivalueofdigit0 || pic.charCodeAt(7) > asciivalueofdigit9) )
		{
			return false;
		}
	//alert("We are past the Char Check");
	//Check the second character value and change according to the algo.
	if (pic.charCodeAt(1) == asciivalueofcapitalA)
		{
			changedvalueforsecondcharacter = 10;
		}
	else if (pic.charCodeAt(1) < asciivalueofcapitalM)
		{
			changedvalueforsecondcharacter = pic.charCodeAt(1)-asciivalueofcapitalB;
		}
	else if (pic.charCodeAt(1) < asciivalueofcapitalX)
		{
			changedvalueforsecondcharacter = pic.charCodeAt(1)-asciivalueofcapitalM;
		}
	else
		{
			changedvalueforsecondcharacter = pic.charCodeAt(1)-asciivalueofcapitalX;
		}
	//Check the third character value and change according to the algo.
	if (pic.charCodeAt(2) == asciivalueofcapitalA)
		{
			changedvalueforthirdcharacter = 10;
		}
	else if (pic.charCodeAt(2) < asciivalueofcapitalM)
		{
			changedvalueforthirdcharacter = pic.charCodeAt(2)-asciivalueofcapitalB;
		}
	else if (pic.charCodeAt(2) < asciivalueofcapitalX)
		{
			changedvalueforthirdcharacter = pic.charCodeAt(2)-asciivalueofcapitalM;
		}
	else
		{
			changedvalueforthirdcharacter = pic.charCodeAt(2)-asciivalueofcapitalX;
		}
	//Check the fourth character value and change according to the algo.
	if (pic.charCodeAt(3) == asciivalueofcapitalA)
		{
			changedvalueforfourthcharacter = 10;
		}
	else if (pic.charCodeAt(3) < asciivalueofcapitalM)
		{
			changedvalueforfourthcharacter = pic.charCodeAt(3)-asciivalueofcapitalB;
		}
	else if (pic.charCodeAt(3) < asciivalueofcapitalX)
		{
			changedvalueforfourthcharacter = pic.charCodeAt(3)-asciivalueofcapitalM;
		}
	else
		{
			changedvalueforfourthcharacter = pic.charCodeAt(3)-asciivalueofcapitalX;
		}
	//Run the modular check to certify the PIC code
	modulusequationresults = (128*(pic.charCodeAt(0))+64*(changedvalueforsecondcharacter)+32*(changedvalueforthirdcharacter)+16*(changedvalueforfourthcharacter)+8*(pic.charCodeAt(4)-asciivalueofdigit0)+4*(pic.charCodeAt(5)-asciivalueofdigit0)+2*(pic.charCodeAt(6)-asciivalueofdigit0)+(pic.charCodeAt(7)-asciivalueofdigit0))%11;
	//alert(modulusequationresults);
	if (modulusequationresults == 0)
		{
			return true;
		}
	return false;
}
// check to see if the pic is an emergency pic
function isEmergencyTag(pic)
{
	if(pic.charCodeAt(1) != firstCharValueEMER)
		return false;
	else
		return true;
}

// Function to check that the submitted TEST Property Identification Code is a valid PIC code
function validTESTPIC(pic)
{
	if ((isAlpha(pic.charCodeAt(1)) && isAlpha(pic.charCodeAt(2)) &&
		isAlpha(pic.charCodeAt(3)) && isAlpha(pic.charCodeAt(4)) &&
		isAlpha(pic.charCodeAt(5)) && pic.charCodeAt(0) == firstCharValueTEST.charCodeAt(0)))
	{
		return true;
	}
	else
	{	
		return false;
	}
}

function validAbattoirPIC(pic)
{	
	if(pic.substring(0,4)=="EUAB"  &&
		 isNum(pic.charCodeAt(4)) && isNum(pic.charCodeAt(5)) &&
		 isNum(pic.charCodeAt(6)) && isNum(pic.charCodeAt(7)))
		 {
		 	return true;
		}
	else
	{	
			return false;
		}
}

function validIndonesiaPIC(pic) {
    picvalue = picvalue.toUpperCase();

    var firstSection = pic.charCodeAt(0); //Must be D - Denotes Indonesia
    var secondSection = pic.charCodeAt(1); //Character between A-K
    var thirdSection = pic.substring(2, 4); //PT=PORT, FL=FEEDLOT, AB=ABATTOIR
    var fourthSection = pic.substring(4, 8); //Numeric value

    if (
         firstSection == asciivalueofcapitalD && 
         (asciivalueofcapitalA <= secondSection && secondSection <= asciivalueofcapitalK) &&
         (thirdSection == "PT" || thirdSection == "FL" || thirdSection == "AB") &&
		 isNum(fourthSection.charCodeAt(0)) && isNum(fourthSection.charCodeAt(1)) &&
         isNum(fourthSection.charCodeAt(2)) && isNum(fourthSection.charCodeAt(3))
         ) {
        return true;
    }
    else {
        return false;
    }
}

function checkemergencytags(pic)
{
	//alert("inside the emergency tag check");
	if (pic.charCodeAt(1) == asciivalueofcapitalZ) return true;
	return false;
}
// Function to check if the charater is alphabetic
// Warning: chr MUST be a ascii value rather than a string
function isAlpha(chr)
{
	return asciivalueofcapitalA <= chr && chr <= asciivalueofcapitalZ;
}

// Function to check if the charater is numeric
// Warning: chr MUST be a ascii value rather than a string
function isNum(chr)
{
	return digit0 <= chr && chr <= digit9;
}

//////////Extra Functions

function CheckddlToSelectItem(source, arguments)
{

	if (arguments == "Empty" || arguments == "")
	{
		return false;
	}
	else
	{
		return true;
	}
}

function CheckIsNull4CompGrp(source, arguments)
{
	var tmp =  TrimString(arguments);
	if (tmp == "")
		return true;
	else
		return CheckIsNull(source, arguments);
}

function CheckIsNull(source, arguments)
{
	var tmp =  TrimString(arguments);
	
	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer")
		tmp = tmp.replace(/\r\n/g,'');
	else
		tmp = tmp.replace(/\n/g,'');
	if (tmp != "" && validateChar(tmp))
	{
		arguments.IsValid = true;
		return true;
	}
	else
	{
		arguments.IsValid = false;
		return false;
	}
}

// Deletes the selected items of supplied list.
function deleteSelectedItemsFromList(SourceList,hiddenField) 
{
	var List = fGetElementById (SourceList);
	var maxCnt = List.options.length;
	for(var i = maxCnt - 1; i >= 0; i--) 
		if ((List.options[i] != null) && (List.options[i].selected == true))
				List.options[i] = null;
	
	UpdateHiddenItems(SourceList,hiddenField)

}

 function fKeyPress (evt,CInput,CList) {
		var whichkey;
		if (navigator.appName != "Microsoft Internet Explorer")
			{
			whichkey = evt.which; 
			}
		else
			{
			whichkey = evt.keyCode;
			}	
			
		if (whichkey == 13) {
		
			var CattleInput = fGetElementById (CInput)
			var CattleList = fGetElementById (CList)
			
			var msInput = CattleInput.value;
				
			if (msInput != "*" && msInput.split(" ").join ("") != "") 
			{
				var text = CattleList.value.split("\r\n")
				for(var i = text.length - 1; i >= 0; i--) 
				{
					if ((text[i] != null))
						{
							if (TrimString(text[i])== TrimString(msInput))
								{
									CattleInput.focus();
									DisablePostback(evt);
									return;
								}
						}
				}	
				
				CattleList.value = msInput;
				for(var i = text.length - 1; i >= 0; i--) 
				{
					if ((text[i] != null))
						{
							if (TrimString(text[i])!="")
								{
									CattleList.value = CattleList.value + "\r\n" + TrimString(text[i]);
								}
						}
				}	
						
				CattleInput.value = "";
				CattleInput.focus();
				DisablePostback(evt);
			}
			CattleInput.focus();
			DisablePostback(evt);
		}
	}

function UpdateHiddenItems(CList,Chidden)
{
	var ListItems = fGetElementById (CList)
	var TextHidden = fGetElementById (Chidden)
	var maxCnt = ListItems.options.length;
	
	TextHidden.value ="";
	for(var i = maxCnt - 1; i >= 0; i--) 
		{
			if (ListItems.options[i] != null)
					if (TextHidden.value=="")
						TextHidden.value = ListItems.options[i].text;		
					else	
						TextHidden.value = TextHidden.value+"\r\n"+ListItems.options[i].text;		
		}				
}	

function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

//getElementById
fGetElementById = function (tsElementName)
 {
	if (document.getElementById) {
		return document.getElementById (tsElementName);
	} else if (document.all) {
		return document.all [tsElementName];
	} else if (document.layers) {
		return document.layers [tsElementName];
	}
}

/* Old validation function (Net framework 1.1) before upgrating date & datetime user control - */
function Validate_date(source, arguments)
{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
	var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
	var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

	var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
	var inpDate = arguments;
	
	//Date was disabled by another control
	//Validation must be ignored
	if(inpDate.indexOf("Disabled")!=-1)
	{
		return true;
	}
	
	var PDay = inpDate.substring(0, 2);	
	var PMonth = inpDate.substring(2, 4);
	var PYear = inpDate.substring(4, 8);
	
	//Check ddmmyyyy date supplied
	if (! filter.test(inpDate))
	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
		return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
	/* Check Valid Month */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
	filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
	if (! filter.test(PMonth))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
		return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
	/* Check For Leap Year */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
	var N = Number(PYear);
	if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
		DayArray[1]=29;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
  	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
	/* Check for valid days for month */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
	for(var ctr=0; ctr<=11; ctr++)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
		if (MonthArray[ctr]==PMonth)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
   		{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
			if (PDay<= DayArray[ctr] && PDay >0 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
			{
				inpDate = PDay + '/' + PMonth + '/' + PYear;       
				return inpDate;
			}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
			else                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
			{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
				return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
			}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
   		}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
}
/* New validation function (Net Framework 3.5)after upgrating date & datetime user control */
function Validate_date35(source, arguments)
{                                          
  var varDate=source;            
  var Days=30;            
  if(arguments.length==0)            
      return true;   
  else if (arguments.length != 10)
    {                
        varDate.style.borderColor="red";                
        return false;            
    }            

    var DateSplit= arguments.split('/');  
    try               
    {               
       if(DateSplit[1] == 1 || DateSplit[1] == 3 || DateSplit[1]==5 || DateSplit[1]==7 || DateSplit[1]==8 || DateSplit[1]==10 || DateSplit[1]==12)                    
            Days=31;               
       else if (DateSplit[1]==2 & DateSplit[2]%4 !=0)                     
            Days=28;               
            else if (DateSplit[1]==2 & DateSplit[2]%4 ==0)                    
                Days=29;               
                else if (DateSplit[1] == 4 || DateSplit[1] == 6 || DateSplit[1]==9 || DateSplit[1]==11)                    
                    Days=30; 
        if(DateSplit[0]>Days || DateSplit[0]<1)               
        {                   
            varDate.style.borderColor="red";                    
            return false;               
        }                   
        if(DateSplit[1]>12 || DateSplit[1]<1)               
        {                    
            varDate.style.borderColor="red";                    
            return false;               
        }               
        if(DateSplit[2].length != 4 || DateSplit[2]<1900  || DateSplit[2]>2020)               
        {                    
            varDate.style.borderColor="red";                    
            return false;               
        }               
        varDate.style.borderColor="";                
    }
    catch(ex)               
    {                
        //alert("Validate_date35: " + ex);
        return false;
    }            

    return true;
}
function CheckShireCode(source, arguments)
{
	var Shirelen = arguments.length;
	if (Shirelen == 0 || Shirelen > 2 || validateChar(arguments)==false )
		return false;
	
	return true;
	
}

function CheckAccID(source, arguments)
{
	var len = arguments.length;
	if (len == 0)
	{
		return true;
	}
	return validateNumber(arguments);
}

function fSetPageKey(PageKey)
{
	var elem = document.getElementById("_pagekey");
	if (elem == null)
	{
		elem = document.getElementsByName("_pagekey")[0];
	}
	if(elem != null)
		elem.value = PageKey;
}

function fSetFieldValue(FieldID,Value)
{
	var elem = document.getElementById(FieldID);
	if (elem == null)
	{
		elem = document.getElementsByName(FieldID)[0];
	}
	elem.value = Value;
}

function fGetFieldValue(FieldID)
{    
	var elem = document.getElementById(FieldID);
	if (elem == null)
	{
		elem = document.getElementsByName(FieldID)[0];
	}
	return elem.value;
}

//MultipleselectionControl.ascx
function multiSelectionControlPopUpOpen(tagId,tableName,popUpAttr, formName, controlName, maxQty)						
{  
	if(tagId=='') //For scalars
	{
		for (z=0; z<document.forms.length; z++) {
			if(document.forms[z].name==formName)
				form = document.forms[z];
		}

		for (i=0; i<form.elements.length; i++) {		
			//if(form.elements[i].name.indexOf(controlName + ':txtMulSelResult')!=-1){
			if(form.elements[i].name.indexOf(controlName + '$txtMulSelResult')!=-1){
				fResult = form.elements[i].value;
			}
		}
        
		window.open('../General/MultipleSelectionPopUp.aspx?TableName='+tableName+'&TagId=&SelectionList='+fResult+'&FormName='+formName+'&ControlName='+controlName+'&MaxQty='+maxQty,null,popUpAttr);											  
		return false;
	}
	else //For Grids
	{
		for (z=0; z<document.forms.length; z++) {
			if(document.forms[z].name==formName)
				form = document.forms[z];
		}

		flag=0;
		for (i=0; i<form.elements.length; i++) {
			//if(form.elements[i].name.indexOf(controlName + ':txtMulSelTagId')!=-1
			if(form.elements[i].name.indexOf(controlName + '$txtMulSelTagId')!=-1
				&& form.elements[i].value.indexOf(tagId)!=-1){
				flag=1;
			}
		for (j=i; j<form.elements.length && flag==1; j++) {	
			//if(form.elements[j].name.indexOf(controlName + ':txtMulSelResult')!=-1) { 
			if(form.elements[j].name.indexOf(controlName + '$txtMulSelResult')!=-1) { 
				fResult = form.elements[j].value;
				window.open('../General/MultipleSelectionPopUp.aspx?TableName='+tableName+'&TagId='+tagId+'&SelectionList='+fResult+'&FormName='+formName+'&ControlName='+controlName+'&MaxQty='+maxQty,null,popUpAttr);							
				return false;
			}	
		}
	}				
	}
	return false;
}

//CLICK TRACKING AUDIT FUNCTIONS (HelpTools.aspx and Reports.aspx)
function clickTrackerAudit(obj)
{
	clickTrackerAudit(obj);
}

function clickTrackerAudit(obj)
{
	var linkPage = document.getElementById("BaseMP_BaseMasterPageContent_txtClickTrackerLinkPage");
	if (linkPage) linkPage.value = obj.href;
	var itemId = document.getElementById("BaseMP_BaseMasterPageContent_txtClickTrackerItemId");
	if (itemId) itemId.value = "-1";
	var clientDateTime = document.getElementById("BaseMP_BaseMasterPageContent_txtClickTrackerClientDateTime");
	if (clientDateTime) clientDateTime.value = getCurrentClientDateForAnyBrowser();
	var clientBrowser = document.getElementById("BaseMP_BaseMasterPageContent_txtClickTrackerBrowser");
	if (clientBrowser) clientBrowser.value = navigator.appName;
	
	//var btn = document.getElementById("btnClickTracker");
	//if (btn) btn.click();	 
	__doPostBack('BaseMP$BaseMasterPageContent$btnClickTracker','');
    event.keyCode = 0
	
	if (navigator.appName == "Microsoft Internet Explorer")
	{	
		return false;
	}
} 

function getCurrentClientDateForAnyBrowser()
{
	da = new Date(); 	// Create a Date Object set to the last modifed date
	dy = da.getFullYear(); 	// Get full year (as opposed to last two digits only)
	dm = da.getMonth() + 1; 	// Get month and correct it (getMonth() returns 0 to 11)
	dd = da.getDate(); 	// Get date within month
	if ( dy < 1970 ) dy = dy + 100; 	// We still have to fix the millennium bug
	ys = new String(dy); 	// Convert year, month and date to strings
	ms = new String(dm); 	 
	ds = new String(dd); 	 
	if ( ms.length == 1 ) ms = "0" + ms; 	// Add leading zeros to month and date if required
	if ( ds.length == 1 ) ds = "0" + ds; 	 
	db = da.toString(); 	// Convert to a String in "predictable formt"
	dc = db.split(" "); 	// Split the string on spaces
	//vTime = new String(dc[4]);	//Get time HH:mm:ss
	vTime = "GMT";
	if ( vTime.indexOf(":")<0 ) vTime = "00:00:00";
	return ys = ys + "/" + ms + "/" + ds + " " + vTime; // Combine year, month, date and time in ISO format
}

function disableEnterKeyOnTextboxNextToButtons(e) {
	if (window.event && event.keyCode==13)return false;
}

function f_upperOnBlur (o) {
  o.value = o.value.toUpperCase();
}

function onkeyPressInteger (e) {
	var keynum;
	if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keynum = e.which;
	
	if(keynum==null) return true; 					
	//BACKSPACE: 8, TAB: 9 , ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, PAUSE: 19
	else if(keynum!=13 && keynum!=8 && keynum!=9 && keynum!=16){	  
		sIsDigit =/^[0-9]+$/
		var s = String.fromCharCode(keynum);
		var strValorOk = new String("");
		strValorOk = sIsDigit;
		if (!strValorOk.test(s))
			return false;
		else return true;
	}
    else return true;
}

function onkeyPressAlphaNumeric (e) {
	var keynum;
	if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keynum = e.which;

	if(keynum==null) return true; 
	//BACKSPACE: 8, TAB: 9 , ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, PAUSE: 19
	else if(keynum!=13 && keynum!=8 && keynum!=9 && keynum!=16){	  
		sIsAlpahNumeric = /^[a-zA-Z0-9]+$/
		var s = String.fromCharCode(keynum);
		var strValorOk = new String("");
		strValorOk = sIsAlpahNumeric;
		if (!strValorOk.test(s))
			return false;
		else return true;
 	}
    else return true;   
}

function onkeyPressAlphaNumericList (e) {
	var keynum;
	if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keynum = e.which;

	if(keynum==null) return true; 
	//BACKSPACE: 8, TAB: 9 , ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, PAUSE: 19
	else if(keynum!=13 && keynum!=8 && keynum!=9 && keynum!=16){	  
		sIsAlpahNumeric = /^[a-zA-Z0-9]+$/
		var s = String.fromCharCode(keynum);
		var strValorOk = new String("");
		strValorOk = sIsAlpahNumeric;
		if (!strValorOk.test(s))
			return false;
		else return true;
	}
	else return true; 
}

function integerValueGreaterThanZero(source, arguments)
{
	if(arguments=="") return false;
	var intValue = parseInt(arguments);
	if(intValue<=0) return false;
	return true;
}

function removeExtraEnterKeysFromList(vString)
{
	vString = vString.replace("\r","\n") + "\n";	
	while(vString.indexOf("\n") == 0)
	{
		vString = vString.substring(1);
	}	
	while(vString.indexOf("\n\n") > 0)
	{
		vString = vString.replace("\n\n","\n");
	}						
	return vString;
}

function textMaxLengthFreeText(obj, maxLength, evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode
    var max = maxLength - 0;
    var text = obj.value;

    if (charCode == 13) {
        return false;
    }

    if (text.length < max) {
        return true; // false;
    }
    else {
        return false; // true;
    }
}

function textMaxLength(obj, maxLength, evt)
{
	var charCode=(evt.which) ? evt.which : evt.keyCode
	var max = maxLength - 0;
	var text = obj.value;
	
	if(charCode==13)
	{
		return false;
	}

    //if (text.length >= max)
    if (text.length < max)
	{
		var ignoreKeys = [8,46,37,38,39,40,35,36];
		for(i=0;i<ignoreKeys.length;i++)
		{
			if(charCode==ignoreKeys[i])
			{
			    return false; // true;
			}
		}
		return true; // false;
	}
	else
	{
	    return false;// true;
	}
} 
	/*---------------------------------------------------------------------------------------------*/
	/* used in MobBasedKil - ManualNVDUpload.aspx - ManualMovementOffPic and ManualMovementOntoPic */
	/* Hugo Rodriguez 23/11/2009	- begin														   */
	/*---------------------------------------------------------------------------------------------*/
	/* Validates the given file path. */
	function validateFilePathMobBased()
	{	        
		var result = true;
		var msg = "";
		var mFile = document.getElementById('BaseMP_BaseMasterPageContent_mFile');
		var txtNVDImageHidden = document.getElementById('BaseMP_BaseMasterPageContent_txtNVDImageHidden');
		var val = mFile.value;
		var len = mFile.value.length;
		if (len == 0)
		{
			return true;
		}
		if (val.lastIndexOf("/") > -1)
		{
			result = false;
			mFile.focus();
			msg = "You must enter a valid file path.";
			alert(msg);
			return result;
		}
		//extension allowed: PDF, JPG, GIF, TIF, PNG
		if (
			!(
			((val.indexOf(".pdf") > 0) && (val.lastIndexOf(".pdf") == val.indexOf(".pdf"))) ||
			((val.indexOf(".PDF") > 0) && (val.lastIndexOf(".PDF") == val.indexOf(".PDF"))) ||

			((val.indexOf(".jpg") > 0) && (val.lastIndexOf(".jpg") == val.indexOf(".jpg"))) ||
			((val.indexOf(".JPG") > 0) && (val.lastIndexOf(".JPG") == val.indexOf(".JPG"))) ||

			((val.indexOf(".gif") > 0) && (val.lastIndexOf(".gif") == val.indexOf(".gif"))) ||
			((val.indexOf(".GIF") > 0) && (val.lastIndexOf(".GIF") == val.indexOf(".GIF"))) ||


			((val.indexOf(".tif") > 0) && (val.lastIndexOf(".tif") == val.indexOf(".tif"))) ||
			((val.indexOf(".TIF") > 0) && (val.lastIndexOf(".TIF") == val.indexOf(".TIF"))) ||

			((val.indexOf(".png") > 0) && (val.lastIndexOf(".png") == val.indexOf(".png"))) ||
			((val.indexOf(".PNG") > 0) && (val.lastIndexOf(".PNG") == val.indexOf(".PNG"))) 
			)
			)
		{
			result = false;
			mFile.focus();
			msg = "File can only have the following extensions: PDF, JPG, GIF, TIF, PNG.";
			alert(msg);
			return result;
		}
		
		
		var i6indexval = val.lastIndexOf("\\");
		if (i6indexval > -1)
		{
			var i8exitforcondition = (len - i6indexval - 3);
			var i9startpos = i6indexval + 1;
			var i14endposforfilename = len;
			var i5filename = val.substring(i9startpos, i14endposforfilename);
			
			var fileLength = i5filename.length;
			if(fileLength<5)
			{
				msg = "File name and extension should be greater or equal than 5 characters.";			
				result = false;				
			}
			if(fileLength>14)
			{
				msg = "File name and extension should be lesser or equal than 14 characters.";			
				result = false;				
			}
						
			for (var i=0; i<i8exitforcondition; i++)
			{
				var i11testcharint = i5filename.charCodeAt(i);
				if (((i11testcharint > 32) && (i11testcharint < 46))
					|| ((i11testcharint > 46) && (i11testcharint < 48))
					|| ((i11testcharint > 57) && (i11testcharint < 65))
					|| ((i11testcharint > 90) && (i11testcharint < 97))
					|| (i11testcharint < 32)
					|| (i11testcharint > 122))
				{
					if (i11testcharint != 95)
					{
					    if(i11testcharint != 45)
					    {
						    result = false;
						    msg = "File names can only contain letters (A-Z), numbers (0-9), dashes, underlines and spaces.";
						    break;
					    }
					}
				}
			}
		}
		if (result == false)
		{
			mFile.focus();
			alert(msg);
		}
		else
		{
			txtNVDImageHidden.value = val;
		}
		return result;
	}		
	function setDropCattleObtain()
	{
		var dropBreededOnVendorPIC = document.getElementById('BaseMP_BaseMasterPageContent_dropBreededOnVendorPIC');
		var dropCattleObtain	   = document.getElementById('BaseMP_BaseMasterPageContent_dropCattleObtain');
		var myindex  = dropBreededOnVendorPIC.selectedIndex;
		var dropBreededOnVendorPICValue = dropBreededOnVendorPIC.options[myindex].value;		
	
		if(dropBreededOnVendorPICValue != "N")
		{
			dropCattleObtain[0].selected = true;
		}
	}	
	
	function enabledDropCattleObtain()
	{
		var dropBreededOnVendorPIC = document.getElementById('BaseMP_BaseMasterPageContent_dropBreededOnVendorPIC');	
		var dropCattleObtain	   = document.getElementById('BaseMP_BaseMasterPageContent_dropCattleObtain');		
		var myindex					= dropBreededOnVendorPIC.selectedIndex;
		var dropBreededOnVendorPICValue = dropBreededOnVendorPIC.options[myindex].value;		
	
		if(dropBreededOnVendorPICValue == "N")
		{
			dropCattleObtain.disabled = false;
		}
		else
		{			
			dropCattleObtain[0].selected = true;
			dropCattleObtain.disabled = true;
		}		
	}	
	
	/* Validates the Other PIC(s)  */
	function validateOtherPICList(txtOtherPICS)
	{
		var len = txtOtherPICS.value.length;
		var val = txtOtherPICS.value;
		var result = true;
		if (len > 0)
		{
			val = txtOtherPICS.value = removeExtraEnterKeysFromList(val);
			len = txtOtherPICS.value.length;
		}
			
		if (len > 0)
		{
			result = validateOtherPICsOnList(val, txtOtherPICS);
			//if(!result) txtOtherPICS.focus();
		}
		return result;	
	}
	
	function validateOtherPICsOnList(val, txtOtherPICS)
	{
	   var ErrorMsgOtherPiclbl = document.getElementById('ErrorMsgOtherPiclbl');
	   ErrorMsgOtherPiclbl.innerHTML="";
		while(val.length>0)
		{
			var vPIC = TrimString(val.substring(0,val.indexOf("\n")));
			val = val.substring(val.indexOf("\n")+1);
			if(!checksinglepic(txtOtherPICS, vPIC))
			{
				    ErrorMsgOtherPiclbl.innerHTML = "Incorrect format in other PICs field: " + vPIC + ", Other PICs must have 8 characters";
				return false;										
			}	
		} 
		return true;
    }

    function validateOtherPICorBrandList(txtOtherPICsOrBrands) {
        var len = txtOtherPICsOrBrands.value.length;
        var val = txtOtherPICsOrBrands.value;
        if (len > 0) {
            val = txtOtherPICsOrBrands.value = removeExtraEnterKeysFromList(val);
            len = txtOtherPICsOrBrands.value.length;
        }

        if (len > 0) {
            var ErrorMsgOtherPiclbl = document.getElementById('ErrorMsgOtherPiclbl');
            ErrorMsgOtherPiclbl.innerHTML = "";
            var errorMessage;
            while (val.length > 0) {
                var vCode = TrimString(val.substring(0, val.indexOf("\n")));
                val = val.substring(val.indexOf("\n") + 1);

                //check each variable
                var codeIsValid = true;
                if (vCode.length == 8) {
                    if (!checksinglepic(txtOtherPICsOrBrands, vCode)) {
                        codeIsValid = false;
                        errorMessage = "Incorrect format in other PICs or Brands field: " + vCode;
                    }
                }
                else if ((vCode.length != 3) && (vCode.length != 4) && (vCode.length != 7)) {
                    codeIsValid = false;
                    errorMessage = "Incorrect format in other PICs or Brands field: " + vCode + ", Other PICs/Brands must have 3,4,7 or 8 characters";
                }

                //if not valid then print an error message
                if (codeIsValid == false) {
                    ErrorMsgOtherPiclbl.innerHTML = errorMessage;
                    return false;
                }
            }
        }

        return true;
    }		

	
//**********************************************************************//	
// functions used in ManualMovementOffPicAgent and manualNVDUpload     *//
//**********************************************************************//
	function onkeyPressToPICList (e) {	
		var keynum;
		if(window.event) // IE
			keynum = e.keyCode;
		else if(e.which) // Netscape/Firefox/Opera
			keynum = e.which;

		if(keynum==null) return true; 
		//BACKSPACE: 8, TAB: 9 , ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, PAUSE: 19
		else if(keynum!=13 && keynum!=8 && keynum!=9 && keynum!=16){	
			sIsAlpahNumeric = /^[a-zA-Z0-9\/]*$/
			var s = String.fromCharCode(keynum);
			var stVarlorOk = new String("");
			strValorOk = sIsAlpahNumeric;
			if (!strValorOk.test(s))
				return false;
			else return true;
		}
		else return true;
	}	
	
	/* Validates the PIC(s)/Tailtag(s). */
	function validateToPICListTailTag()
	{
		var txtToPICList = document.getElementById('BaseMP_BaseMasterPageContent_txtToPICList');
		var len = txtToPICList.value.length;
		var val = txtToPICList.value;
		var result = true;
		if (len > 0)
		{
			val = txtToPICList.value = removeExtraEnterKeysFromList(val);
			val = txtToPICList.value = removeExtraSlashZeroFromList(val);
			len = txtToPICList.value.length;
		}
			
		if (len > 0)
		{
			result = validateEachToPicHeadOnList(val, "TO PIC / Heads");
			if(!result) txtToPICList.focus();
		}
		else
		{
			txtToPICList.focus();
			result = false;
		}
		return result;
	}	
		
	function validateEachToPicHeadOnList(val, fieldName)
	{
		while(val.length>0)
		{
			var toPicHeadItem = TrimString(val.substring(0,val.indexOf("\n")));
			val = val.substring(val.indexOf("\n")+1);
			
			//Check this line has correct lenght
			if(toPicHeadItem.length<10) //At least 8 PIC characters(fixed) + "/" + Number of heads = 10
			{
				alert("Incorrect format in " + fieldName + " field: " + toPicHeadItem + ", Enter each PIC and Number of head(s) separating them with a '/' character.");
				return false;
			}
			
			//get PIC
			var toPIC = toPicHeadItem.substring(0,8);
			if(!checksinglepic("", toPIC))
			{
				alert("Incorrect format in " + fieldName + " field: " + toPicHeadItem + ", Invalid PIC format");
				return false;						
			}
						
			//get "/" character
			var slashChar = toPicHeadItem.substring(8);
			if(slashChar.indexOf("/")!=0)
			{
				alert("Incorrect format in " + fieldName + " field: " + toPicHeadItem + ", Separate PIC and Number of head(s) with a '/' character.");
				return false;			
			}
			
			//get integer value			
			var numberOfHeads = toPicHeadItem.substring(9);
			if(!validateNumber(numberOfHeads))
			{	
				alert("Incorrect format in " + fieldName + " field: " + toPicHeadItem + ", Number of head(s) should be a numeric value.");
				return false;						
			}			
			if(numberOfHeads.length>4) 
			{
				alert("Incorrect format in " + fieldName + " field: " + toPicHeadItem + ", Number of head(s) should be lesser than 9999.");
				return false;									
			}
		} 
		return true;
	}
		
		
	function removeExtraSlashZeroFromList(vString)
	{
		while(vString.indexOf("/0") > 0)
		{
			vString = vString.replace("/0","/");
		}		
		return vString;		
	}		
	/* Hugo Rodriguez 23/11/2009	- end									*/	


/****************************************NLIS 3.5 VERSION PATCHES**********************************************************/

//*******************************************ControlValidationFunctions****************************************************************

function CheckIsNull35(source, arguments)
{
	arguments.IsValid = CheckIsNull(source, arguments.Value);	
	return arguments.IsValid;	
}

function checksinglepic35(source, arguments)
{
	arguments.IsValid = checksinglepic(source, arguments.Value);	
	return arguments.IsValid;	
}

function checkmultiplepic35(source, arguments)
{
    arguments.Value = fCleanText35(arguments.Value);
	arguments.IsValid = checkmultiplepic(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckSaleyardID35(source, arguments)
{
	arguments.IsValid = CheckSaleyardID(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckRFID35(source, arguments)
{
	arguments.IsValid = CheckRFID(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckNLISID35(source, arguments)
{
	arguments.IsValid = CheckNLISID(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckPhoneNumber35(source, arguments)
{
	arguments.IsValid = CheckPhoneNumber(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckIsNumeric35(source, arguments)
{
	arguments.IsValid = CheckIsNumeric(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckMultipleRFID35(source, arguments)
{
    arguments.Value = fCleanText35(arguments.Value);
	arguments.IsValid = CheckMultipleRFID(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckShireCode35(source, arguments)
{
	arguments.IsValid = CheckShireCode(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckNLISID_RFID35(source, arguments)
{
	arguments.IsValid = CheckNLISID_RFID(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckMultipleNLISID_RFID35(source, arguments)
{
    arguments.Value = fCleanText35(arguments.Value);
	arguments.IsValid = CheckMultipleNLISID_RFID(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckDestPIC4LiveX35(source, arguments)
{
	arguments.IsValid = CheckDestPIC4LiveX(source, arguments.Value);	
	return arguments.IsValid;	
}


function CheckIsPercentage35(source, arguments)
{
	arguments.IsValid = CheckIsPercentage(source, arguments.Value);	
	return arguments.IsValid;	
}

function checksinglepic4CompGrp35(source, arguments)
{
	arguments.IsValid = checksinglepic4CompGrp(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckNLISID_RFID4CompGrp35(source, arguments)
{
	arguments.IsValid = CheckNLISID_RFID4CompGrp(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckIsNull4CompGrp35(source, arguments)
{
	arguments.IsValid = CheckIsNull4CompGrp(source, arguments.Value);	
	return arguments.IsValid;	
}

function ValCharForName35(source, arguments)
{
	arguments.IsValid = ValCharForName(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckPBT35(source, arguments)
{
	arguments.IsValid = CheckPBT(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckEstabNo35(source, arguments)
{
	arguments.IsValid = CheckEstabNo(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckNLISID_RFID_ISNULL35(source, arguments)
{
	arguments.IsValid = CheckNLISID_RFID_ISNULL(source, arguments.Value);	
	return arguments.IsValid;	
}

function checksinglepic_ISNULL35(source, arguments)
{
	arguments.IsValid = checksinglepic_ISNULL(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckIsNullOrNumeric35(source, arguments)
{
	arguments.IsValid = CheckIsNullOrNumeric(source, arguments.Value);	
	return arguments.IsValid;	
}
//*******************************************ControlValidationFunctions****************************************************************

function Validate_date2(source, arguments)
{ 
    arguments.IsValid=Validate_date(source, arguments.Value);    
    return arguments.IsValid;
}

function CheckddlToSelectItem35(source, arguments)
{
    /*
	if (arguments.Value == "Empty" || arguments.Value == "")
	{
		arguments.IsValid= false;
	}
	else
	{
		arguments.IsValid = true;
	}
	 return arguments.IsValid;
	 */
    arguments.IsValid=CheckddlToSelectItem(source, arguments.Value);    
    return arguments.IsValid;		 
}

    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
//    function doClick(buttonName,e)
//    {
//        var key;

//         if(window.event)
//              key = window.event.keyCode;     //IE

//         else
//              key = e.which;     //firefox
//    
//        if (key == 13)
//        {
//            //Get the button the user wants to have clicked

//            var btn = document.getElementById(buttonName);
//            if (btn != null)
//            { //If we find the button click it
//                //btn.click(); //DOES NOT WORK ON FIREFOX
//                __doPostBack('BaseMP:BaseMasterPageContent:lLogin','');
//                event.keyCode = 0
//            }
//        }
//   }

/* Validates a Text. */
function validateText35(source, arguments)
{
	arguments.IsValid = validateText(source, arguments.Value);	
	return arguments.IsValid;
}

function validateTextAndCharacters35(source, arguments)
{
	arguments.IsValid = validateTextAndCharacters(source, arguments.Value);	
	return arguments.IsValid;	
}   

function validateOldPassword35(source, arguments)
{
	arguments.IsValid = validateOldPassword(source, arguments.Value);	
	return arguments.IsValid;	
}

function validateRequiredField35(source, arguments)
{
	arguments.IsValid = validateRequiredField(source, arguments.Value);	
	return arguments.IsValid;	
}

function CheckAccID35(source, arguments)
{
	arguments.IsValid = CheckAccID(source, arguments.Value);	
	return arguments.IsValid;	
}

function integerValueGreaterThanZero35(source, arguments)
{
	arguments.IsValid = integerValueGreaterThanZero(source, arguments.Value);	
	return arguments.IsValid;	
}

function validateComment35(source, arguments)
{
	arguments.IsValid = validateComment(source, arguments.Value);	
	return arguments.IsValid;
}

function validateToPICListTailTag35(source, arguments)
{
	arguments.IsValid = validateToPICListTailTag();	
	return arguments.IsValid;
}

function CheckSaleyardIDorPIC35(source, arguments)
{
	arguments.IsValid = CheckSaleyardIDorPIC(source, arguments.Value);	
	return arguments.IsValid;
}

function validateFilePathMobBased35(source, arguments)
{	        
	arguments.IsValid = validateFilePathMobBased();	
	return arguments.IsValid;
}

/*
function TrimString35(sInString) {
    alert(sInString);
    alert(sInString.Value);
	return TrimString(sInString.Value);	
}
*/

function ValidateMultipleListBox(source, arguments)
{    
    var chkBoxList = document.getElementById(arguments);
    var chkBoxCount = chkBoxList.getElementsByTagName("input");
    	
	for(var i=0; i< chkBoxCount.length; i++) 
    {
	    if (chkBoxCount[i].checked == true)
	    {
	        return true;   
	    }				
    }
    
	return false;		
}

function uncheckedSpecies(source, arguments)
{                 
    var chkBoxList = document.getElementById(arguments);
    var chkBoxCount = chkBoxList.getElementsByTagName("input");
    if (chkBoxCount[0].checked == true)
	    for(var i=1; i< chkBoxCount.length; i++) 
	        chkBoxCount[i].checked = false;
}

function uncheckedAllSpecies(source, arguments)
{
    var chkBoxList = document.getElementById(arguments);
    var chkBoxCount = chkBoxList.getElementsByTagName("input");
	for(var i=1; i< chkBoxCount.length; i++) 
	    if (chkBoxCount[i].checked == true)
	    {
	        chkBoxCount[0].checked = false;   
	        return;
	    }				
}
 
	/* Validates the First Name. */
	function validateFName35(source, arguments)
	{   
	    arguments.IsValid= true;
	    
		var val = arguments.Value;
		
		if (val.length == 0)
		{
			arguments.IsValid= false;
		}
		else
		{
			
			if (val.indexOf(" ") == 0)
			{
				arguments.IsValid= false;				
			}
			else
			{
				//the name can be alphanumeric
				var pattern = "^[a-zA-Z0-9]+$"; 
				
				if(val.search(pattern)!= -1)
				{
					arguments.IsValid= true;
				}
				else
				{
					arguments.IsValid= false;
				}	
			}		
		}
		return arguments.IsValid;
	}
	/* Validates the Last Name. */	
	function validateLName35(source, arguments)
	{
	    arguments.IsValid= true;
	    
		var val = arguments.Value;
		if (val.length == 0)
		{
			arguments.IsValid= false;
		}
		else
		{
			
			if (val.indexOf(" ") == 0)
			{
				arguments.IsValid= false;
				
			}
			else
			{
				//the name can be alphanumeric
				var pattern = "^[a-zA-Z0-9]+$"; 
				
				if(val.search(pattern)!= -1)
				{
					arguments.IsValid= true;
				}
				else
				{
					arguments.IsValid= false;
				}
			}
		}
		return arguments.IsValid;
	}
	
function checkPICList(source, arguments)
{
    var retValue=true;
	arguments = TrimString(arguments);
	if (arguments == "")
	{
		return false;
	}	
	arrpics = arguments.split(';');
	var PICCounter = 0;
	for (var i = 0; i< arrpics.length ; i++)
    {
        var trimedPIC = TrimString(arrpics[i]);        
        if(trimedPIC=="") continue;
        PICCounter++;
        if(PICCounter>5)
        {
            alert('Please enter no more than 5 PICs');
            retValue=false;
            break;        
        }
        if(!checksinglepic(source,trimedPIC))
        {
            alert('Invalid PIC ' + trimedPIC);
            retValue=false;
            break;
        }
    }    
    return retValue;         
}	

function checkPICList35(source, arguments)
{
	arguments.IsValid = checkPICList(source, arguments.Value);	
	return arguments.IsValid;
}

function validateCSVComment35(source, arguments) {
    arguments.IsValid = validateCSVComment(source, arguments.Value);
    return arguments.IsValid;
}

function doClickForDefaultButton(buttonName, e) {
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE

    else
        key = e.which;     //firefox
    
    if (key == 13) {
        //Get the button the user wants to have clicked

        var btn = document.getElementById(buttonName);
        
        if (btn != null && typeof (Page_ClientValidate) == 'undefined' || (typeof (Page_ClientValidate) == 'function' && Page_ClientValidate())) { //If we find the button click it
            //btn.click(); //DOES NOT WORK ON FIREFOX
            __doPostBack(buttonName.replace(/_/g,":"), '');
            event.keyCode = 0
        }
    }
}

function SetScrollerPosition() {
    window.scrollTo(0, 0);
}

