
//*********************************
//	Common Includes [SLAC COPY]
//*********************************

NS = (document.layers)? true:false;
IE = (document.all)? true:false;

function invertColors(obj)
// Switch the foreground and background colors of the provided object.
// Move to global include file
{
	var tempColor = obj.currentStyle.backgroundColor
	obj.style.backgroundColor = obj.currentStyle.color;
	obj.style.color = tempColor;		
}


// BLH 04/06/01
function display(id,btype){
	if (btype)	{
		document.all[id].style.display="inline";
	} else {
		document.all[id].style.display="none";
	}
}

// BLH 04/06/01
function update(id,text){
	document.all[id].innerHTML=text;
}

// Show/Hide functions for non-pointer layer/objects
function show(id){
	if (NS) 
		document.layers[id].visibility = "show";
	else if (IE) 
		document.all[id].style.visibility = "visible";
}

function hide(id){
	if (NS) 
		document.layers[id].visibility = "hide";
	else if (IE) 
		document.all[id].style.visibility = "hidden";
}

function DivWrite(id,html){
	if (NS){
		document.layers[id].document.open();
		document.layers[id].document.write(html);
		document.layers[id].document.close();
	}else if (IE) {
		document.all[id].innerHTML = html;
	}
}

//This global variable would be set with the error message.  PUNE 17/10/00
var sCheckDate_ErrorMsg = "";

function dateDifference(StartDate, EndDate){
	YearSDate = StartDate.substring(6,10);
	YearEDate = EndDate.substring(6,10);

	if(parseFloat(YearEDate) < parseFloat(YearSDate)){
		return -1;
	}else if(parseFloat(YearEDate) == parseFloat(YearSDate)){
		//Check months
		MonthsSDate = StartDate.substring(3,5);
		MonthsEDate = EndDate.substring(3,5);

		if(parseFloat(MonthsEDate) < parseFloat(MonthsSDate)){
			return -1;
		}else if(parseFloat(MonthsEDate) == parseFloat(MonthsSDate)){
			//Check days
			DaysSDate = StartDate.substring(0,2);
			DaysEDate = EndDate.substring(0,2);

			if(parseFloat(DaysEDate) < parseFloat(DaysSDate)){
				return -1;
			}
		}
	}
	
	return 1;	
}

function dateDifferenceV2(StartDate, EndDate)
{
	// Added by MP 14/11/2003 for Tomahawk PRTV-CIMP
	
	/**********************************************
	* INPUT PARAMETERS
		StartDate		date for what you are comapring against
		
		EndDate			date for comparison
		
	* DESCRIPTION
		The function compares EndDate against the StartDate to see if it falls before, after or
		is the same date as the StartDate.
		
	* VERSION 2 ENHANCEMENTS
		Check to see if DaysEDate == DaysSDate, if so  return 0
		
	* RETURN
		-1		EndDate < StartDate
		0		StartDate = EndDate
		1		EndDate > StartDate
	***********************************************/
	
	YearSDate = StartDate.substring(6,10);
	YearEDate = EndDate.substring(6,10);

	if(parseFloat(YearEDate) < parseFloat(YearSDate))
		return -1;
	else if(parseFloat(YearEDate) == parseFloat(YearSDate))
	{
		//Check months
		MonthsSDate = StartDate.substring(3,5);
		MonthsEDate = EndDate.substring(3,5);

		if(parseFloat(MonthsEDate) < parseFloat(MonthsSDate))
			return -1;
		else if(parseFloat(MonthsEDate) == parseFloat(MonthsSDate))
		{
			//Check days
			DaysSDate = StartDate.substring(0,2);
			DaysEDate = EndDate.substring(0,2);

			if(parseFloat(DaysEDate) < parseFloat(DaysSDate))
				return -1;
			if(parseFloat(DaysEDate) == parseFloat(DaysSDate))
				return 0;
		}
	}
	
	return 1;	
} // end function dateDifferenceV2

function checkDate(dateObj){ 
	var sGenMsg = "Date Error - "
	var err = 0; var psj = 0; var allNum = false; var nSlashes = 0;
	var bIsObject = false; var d = ''; var f = ''; var b = ''; var z;
	if (typeof(dateObj) == "object") {bIsObject = true;}
		
	if (bIsObject)
		a = dateObj.value; 
	else
		a = dateObj;

	if (a == "dd/mm/ccyy" || a == ""){
		sCheckDate_ErrorMsg = sGenMsg + "Date not entered."
		if (bIsObject){		
			//dateObj.focus();
			//dateObj.select();
		}
		return "";
	}

	for (eachChr = 0; eachChr < a.length; eachChr++) {
		z = a.charAt(eachChr);
		if (z!='0' && z!='1' && z!='2' && z!='3' && z!='4' && z!='5' && z!='6' && z!='7' && z!='8' && z!='9' && z!='/') {
			sCheckDate_ErrorMsg = sGenMsg + "Invalid character(s) detected in date field."
			if (bIsObject){
				//dateObj.focus();
				//dateObj.select();
			}
			return "";
		}else {
			if (z == '/') {nSlashes++;}
			if (nSlashes == 0 && z != '/') {d = d + '' + z;}
			else if (nSlashes == 1  && z != '/') {b = b + '' + z;}
			else if (nSlashes == 2  && z != '/') {f = f + '' + z;}			
		}
	}
	
	if (nSlashes != 2) {
		sCheckDate_ErrorMsg = sGenMsg + "Please enter date in format DD/MM/CCYY."		
		return "";
	}
		
	if(d.length != 1 && d.length != 2)	{
		sCheckDate_ErrorMsg = sGenMsg + "Invalid day entered"		
		return "";
	}else if (d < 1 || d > 31) 	{ 
		sCheckDate_ErrorMsg = sGenMsg + "Invalid day entered."		
		return "";
	}
	else if (d.length == 1)	{
		d = '0' + '' + d;
	}

	if(b.length != 1 && b.length != 2)	{
		sCheckDate_ErrorMsg = sGenMsg + "Invalid month entered."		
		return "";
	}else if (b < 1 || b > 12) 	{ 
		sCheckDate_ErrorMsg = sGenMsg + "Invalid month entered."		
		return "";
	}else if (b.length == 1){
		b = '0' + '' + b;
	}
	
	if(f.length != 4){
		sCheckDate_ErrorMsg = sGenMsg + "Please enter year in the format CCYY."		
		return "";
	}
	else if (f<0 || f>9999) 
	{ 
		sCheckDate_ErrorMsg = sGenMsg + "Invalid year entered."		
		return "";
	}
	//At this point the date format is correct.        
	//advanced error checking
		
	// months with 30 days
	if (b == 4 || b == 6 || b == 9 || b == 11)	{
		if (d == 31) 		{ 
			sCheckDate_ErrorMsg = sGenMsg + "Month cannot have 31 days."			
			return "";
		}
	}

	// february, leap year
	if (b == 2)	{
		if (d > 29)		{
			sCheckDate_ErrorMsg = sGenMsg + "Month cannot have days more than 29."			
			return "";
		}
		if (f%4 == 0){
			if (f%100 == 0 && f%400 != 0){
				if (d > 28)	{
					sCheckDate_ErrorMsg = sGenMsg + "Month cannot have days more than 28 when its not a leap year."					
					return "";
				}
			}			
		}else if (d > 28){
			sCheckDate_ErrorMsg = sGenMsg + "Month cannot have days more than 28 when its not a leap year."			
			return "";
		}
	}

	a = d + '/' + b + '/' + f;
	if (bIsObject){
		dateObj.value = a;
	}
	return a;
}

function formatDate(inputDate)
{
	var sday = "", smonth = "",syear = "";
	var newFormatDate = new Date();
	var nPos1 = 0, nPos2 = 0;
	var strDate = inputDate.value;
	var strFullDate = "", strTempDate = "";
	var strErrMessage = "";
	var bError = false;

	if (strDate != "")
	{
		if (strDate.indexOf('/') > 0)
		{
			nPos1 = (strDate.indexOf('/')+1);
			nPos2 = (strDate.indexOf('/', nPos1+1)+1);
		}
		else if (strDate.indexOf('.') > 0)
		{
			nPos1 = (strDate.indexOf('.')+1);
			nPos2 = (strDate.indexOf('.', nPos1+1)+1);
		}
		else if (strDate.indexOf('-') > 0)
		{
			nPos1 = (strDate.indexOf('-')+1);
			nPos2 = (strDate.indexOf('-', nPos1+1)+1);
		}
		
		else if (isNumber(strDate.substring(0)))
		{
			if (strDate.length == 5 || strDate.length == 7)	
			{
				strTempDate = strDate.substring(0,1) + "/" + strDate.substring(1,3) + "/" + strDate.substring(3); 
				strDate = strTempDate;
				nPos1 = 2;
				nPos2 = 5;
			}
			else if (strDate.length == 6 || strDate.length == 8)
			{ 
				strTempDate = strDate.substring(0,2) + "/" + strDate.substring(2,4) + "/" + strDate.substring(4); 
				strDate = strTempDate;
				nPos1 = 3;
				nPos2 = 6;
			}
			else 
			{
				bError = true;
				strErrMessage = "is an invalid date, please reenter";
			}
		}
	
		else 
		{
			bError = true;
			strErrMessage = "is an invalid date, please reenter";
		}
	
	    if (bError == false)
		{	
			if (parseFloat(strDate.substring(0, nPos1)) < 1 || parseFloat(strDate.substring(0, nPos1)) > 31 || parseFloat(strDate.substring(nPos1, nPos2)) < 1 || parseFloat(strDate.substring(nPos1, nPos2)) > 12) 
			{
				bError = true;
				strErrMessage = "is an invalid date, please reenter";
			}
			if (bError == false)
			{
				
				//reformat the valid date into dd/mm/yyyy
				if (parseFloat(strDate.substring(0, nPos1)) < 10)
				{
					sday = "0";
				}
				sday += parseFloat(strDate.substring(0, nPos1-1));
				if (parseFloat(strDate.substring(nPos1, nPos2)) < 10)
				{
					smonth = "0";
				}
				smonth += parseFloat(strDate.substring(nPos1, nPos2-1));
				if (strDate.substring(nPos2).length < 3)
				{
					if (parseFloat(strDate.substring(nPos2)) < 10)
					{	
						syear = "200";
					}
					else
					{
						syear = "20";
					}
				 
				}
				syear += parseFloat(strDate.substring(nPos2));
				
				strFullDate = sday;
				strFullDate += "/" + smonth;
				strFullDate += "/" + syear;
		
				if(checkDate(strFullDate) == "")
				{
					bError = true;
					strErrMessage = (sCheckDate_ErrorMsg)
		
				}
			 }
		}
		if (bError == false)
		{
			inputDate.value = strFullDate;
			return true;
		}	
		else
		{
			alert(strDate + " " + strErrMessage)
			inputDate.focus();
			inputDate.select();
			return false;
		}
    }
}

//This function is the replacement by b.r.vinod as I found errors with the old verson.
//However, I have saved the old version as checkdecimalNumber1() just below this function.
function checkDecimalNumber(amtStr, fldSize, deciNumber){
	var temp;
	var len;
	var i;
	var temp = "1";
	test0 = 0;
	test = 0;
	str = "";
	var intStr = "";
	var decStr = "";
	var decPlace = 0;
	
	// Moved up in code to force amtStr to be a string
	amtStr = "" + amtStr;
	//further added on 12/12/00
	// To take  care of a situation where a decimal point is  entered more than once. Further added on 12/12/*00
 	if (amtStr.lastIndexOf('.')!= amtStr.indexOf('.') )	{
 		alert("Number must contain no more than one decimal place" );
 		return -1;
 		}   
		
	//further added on 01/11/00 to take care of commas in the amount strings
	var arrtemp;
	arrtemp = amtStr.split(",");
	amtStr = arrtemp[0];
	for( i = 1 ; i< arrtemp.length ; i++)
    amtStr = amtStr + arrtemp[i];
	
	len = amtStr.length;
	for (i = 0;i < len && test == 0;i++){
		if (i==0 && amtStr.charAt(i) == "-"){
			i++;
		}
		if (amtStr.charAt(i) != "0" && amtStr.charAt(i) != "1" && amtStr.charAt(i) != "2" && amtStr.charAt(i) != "3" && amtStr.charAt(i) != "4" && amtStr.charAt(i) != "5" && amtStr.charAt(i) != "6" && amtStr.charAt(i) != "7" && amtStr.charAt(i) != "8" && amtStr.charAt(i) != "9" && amtStr.charAt(i) != ".") 	{
			test = 1;
		}
		if (amtStr.charAt(i) != "0" && amtStr.charAt(i) != ".")	{
			test0 = 1;
		}
	}
	if (test == 1){
		alert("You cannot enter anything other than numbers");
		return -1;
	}
	if (test0 == 0)	{
		str = '0.';
		for (i=0; i < deciNumber; i++)
			str = str + '0';
		return str;
	}

	for (i = 0;i < fldSize - deciNumber - 1;i++)
		temp = temp + '0';

	if (parseFloat(amtStr) >= parseFloat(temp))	{
		alert("Please enter a number less than " + parseFloat(temp));
		return -1;
	}

	if (amtStr.substring(0, 1) == '.')
		amtStr = '0' + amtStr;

	// We've had problems in the past when multiplying numbers that they do not give the exact number we expect.
	// Instead formt the number through basic string handling.

	decPlace = amtStr.lastIndexOf('.');
	if (decPlace == -1)	{
		// This is an integer
		intStr = amtStr;
		decStr = "";
		decPlace = amtStr.length;
	}else{
		intStr = amtStr.substring(0,decPlace);
		decStr = amtStr.substring(decPlace+1, amtStr.length);
	}

	// Pad the decimal string to have the required number of decimal places.
	for (i = decStr.length; i < deciNumber; i++){
		decStr = decStr + "0";
		}

	// Now paste the two strings back together.
	   amtStr = intStr + decStr;

	    len = amtStr.length;
    	amtStr = amtStr.substring(0,  decPlace) + '.' + amtStr.substring(decPlace, decPlace +deciNumber);

	    // Strip leading zeros to make display neater
	    amtStr = stripLeading(amtStr, '0');
	    /*temp = parseFloat(amtStr);
	    temp = RoundUp(temp, 2);
	    temp = new String(temp);*/

		// If the number has now been reduced to something like .678, we want to pad it to 0.678 again.
		if (amtStr.charAt(0) == ".")
			amtStr = "0" + amtStr;
	return amtStr;
}

//This is the original version of checkDecimalNumber (). Since I found some errors with this, I am replacing this with a new version above.
function checkDecimalNumber1(amtStr, fldSize, deciNumber){	
	var len;
	var i;
	var temp = "1";
	test0 = 0;
	test = 0;
	str = "";
	var intStr = "";
	var decStr = "";
	var decPlace = 0;
	
	len = amtStr.length;
	for (i = 0;i < len && test == 0;i++){
		if (i==0 && amtStr.charAt(i) == "-"){
			i++;
		}
		if (amtStr.charAt(i) != "0" && amtStr.charAt(i) != "1" && amtStr.charAt(i) != "2" && amtStr.charAt(i) != "3" && amtStr.charAt(i) != "4" && amtStr.charAt(i) != "5" && amtStr.charAt(i) != "6" && amtStr.charAt(i) != "7" && amtStr.charAt(i) != "8" && amtStr.charAt(i) != "9" && amtStr.charAt(i) != ".") 	{
			test = 1;
		}
		if (amtStr.charAt(i) != "0" && amtStr.charAt(i) != ".")	{
			test0 = 1;
		}
	}
	if (test == 1){
		alert("You cannot enter anything other than numbers");
		return -1;
	}
	if (test0 == 0)	{
		str = '0.';
		for (i=0; i < deciNumber; i++)
			str = str + '0';
		return str;
	}

	for (i = 0;i < fldSize - deciNumber - 1;i++)
		temp = temp + '0';

	if (parseFloat(amtStr) >= parseFloat(temp))	{
		alert("Please enter a number less than " + parseFloat(temp));
		return -1;
	}

	if (amtStr.substring(0, 1) == '.')
		amtStr = '0' + amtStr;

	// We've had problems in the past when multiplying numbers that they do not give the exact number we expect.
	// Instead formt the number through basic string handling.

	decPlace = amtStr.lastIndexOf('.');
	if (decPlace == -1)	{
		// This is an integer
		intStr = amtStr;
		decStr = "";
	}else{
		intStr = amtStr.substring(0,decPlace);
		decStr = amtStr.substring(decPlace+1, amtStr.length);
	}

	// Pad the decimal string to have the required number of decimal places.
	for (i = decStr.length; i < deciNumber; i++)
		decStr = decStr + "0";

	// Now paste the two strings back together.
	amtStr = intStr + decStr;
	len = amtStr.length;
	for (i = 0;i < fldSize - len - 1;i++)
		amtStr = '0' + amtStr;
	amtStr = amtStr.substring(0, amtStr.length - deciNumber) + '.' + amtStr.substring(amtStr.length - deciNumber, amtStr.length);//This line is commented and replaces by next line by vinod on 27/09/00
	// Strip leading zeros to make display neater
	amtStr = stripLeading(amtStr, '0');

	return amtStr;
}
function checkInt(amtStr, fldSize){	

	test0 = 0;
	test = 0;
	str = "";
	len = amtStr.length;
	var i;

	for (i = 0;i < len && test == 0;i++)	{
		if (amtStr.charAt(i) != "0" && amtStr.charAt(i) != "1" && amtStr.charAt(i) != "2" && amtStr.charAt(i) != "3" && amtStr.charAt(i) != "4" && amtStr.charAt(i) != "5" && amtStr.charAt(i) != "6" && amtStr.charAt(i) != "7" && amtStr.charAt(i) != "8" && amtStr.charAt(i) != "9") {
			test = 1;
		}
		if (amtStr.charAt(i) != "0"){
			test0 = 1;
		}
	}
	if (test == 1)	{
		alert("You can only enter whole numbers");
		return -1;
	}

	if (test0 == 0)	{
		return "";
	}
	amt = strToInt(amtStr);
	amtStr = amt + "";
	l = amtStr.length;
	len = fldSize - amtStr.length;
	len = len + 1;
	for (i = 1;i < len;i++)
		str = str + "0";
	str = str + amtStr;

	// Strip any leading zeros to make display nicer
	str = stripLeading(str, '0');

	return str;
}
	
// Checks that X is between A and Z
function checkRange(str, x, a, z){
	if(x !="")
		x = parseFloat(x);
	else 
		x=0;
	
	x = parseFloat(x);
	a = parseFloat(a);
	z = parseFloat(z);

	if(x > z || x < a){
		alert( str + " must be between " + a + " and " + z);
		return 0;
	}else
		return 1;
}

function getDateToday(){
	var today = new Date();
	if (!Date.prototype.getFullYear){
		year = today.getYear();

		if (year < 1000){
			year = year + 1900;
		}
	}else{
		year = today.getFullYear();
	}

	var month = today.getMonth() + 1;
	var day = today.getDate();

	if (day < 10)	{
		day = '0' + day;
	}

	if (month < 10)	{
		month = '0' + month; 
	}

	return day + '/' + month + '/' + year;
}

function Round(dNumber, iPlaces){
	var temp;
	var iMultiplier;
	
	iMultiplier = Math.pow(10, iPlaces) 
	temp = dNumber * iMultiplier;
	dNumber = Math.round(temp);
	temp = dNumber / iMultiplier;
	return temp;
}

function RoundUp(dNumber, iPlaces){
	var temp;
	var iMultiplier;

	if (iPlaces == 2)
		iMultiplier = 100;
	if (iPlaces == 3)
		iMultiplier = 1000;

	temp = Math.round(dNumber * iMultiplier) / iMultiplier;

	if(dNumber > temp)		
		temp = parseFloat(temp) + 0.01;

	return temp;
}

function RoundDown(dNumber, iPlaces){
	var temp;
	var iMultiplier;

	iMultiplier = Math.pow(10, iPlaces) 
	temp = dNumber * iMultiplier;
	dNumber = Math.floor(temp);
	temp = dNumber / iMultiplier;
	return temp;

	return temp;
}

function stripLeading (str, stripme)  //Strips leading characters, but unlike stripTrailing it will leave the last character
{				      //This is because I expect to get values through like 000000 and I want to keep the last digit
  var result = "";
  for (ty=0;ty<(str.length-1); ty++) 
    if (str.charAt(ty) == stripme)
      result=result;  // ie do nothing
    else
     break;
  
   //Now to copy in the remaining characters
   for (yt=ty; yt<(str.length); yt++)
    result += str.charAt(yt);
  
 return result;
}

function stripAll (str, stripme)  //This function will strip all characters specified from the string
{
	var result = "";
	for (ty=0;ty<str.length; ty++) 
		if (str.charAt(ty) == stripme)
			result=result;  // ie do nothing
		else
			result+=str.charAt(ty);

	return result;
}

function strToInt(st){
	var str = "";
	str = str + st;
	len = str.length;
	test = 0;
	var i;
	for (i = 0;i < len;i++)	{
		ch = str.charAt(i);
		if (ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' && ch != '6' && ch != '7' && ch != '8' && ch != '9')	{
			alert("The entered string contains characters other than numbers");
			return -1;
		}
	}
	for (i = 0;i < len && test != 1;i++){
		ch = str.charAt(i);
		if (ch != '0')
			test = 1;
	}
	i = i - 1;
	num = str.substring(i, len);
	return parseInt(num);
}

function toUpper(obj){
	obj.value = obj.value.toUpperCase();
}
function ageCal(from, to) {
	daysDiff = parseFloat(to.substring(0, 2)) - parseFloat(from.substring(0, 2));
	monthsDiff = parseFloat(to.substring(3, 5)) - parseFloat(from.substring(3, 5));
	yearsDiff = parseFloat(to.substring(6, 10)) - parseFloat(from.substring(6, 10));

	if (daysDiff > 0)
		monthsDiff = monthsDiff + 1;				

	if (monthsDiff < 0)	{
		monthsDiff = monthsDiff + 12;
		yearsDiff = yearsDiff - 1;
	}else{
		if (monthsDiff > 11){
			monthsDiff = monthsDiff - 12;
			yearsDiff = yearsDiff + 1;
		}
	}
	
	if (yearsDiff < 0)
		return "-1";

	if (monthsDiff < 10)
		monthsDiff = '0' + monthsDiff;

	if (yearsDiff < 10)
		yearsDiff = '0' + yearsDiff;

	return yearsDiff + ' ' + monthsDiff;
}

function trueAgeCal(from, to) {

	daysDiff = parseFloat(to.substring(0, 2)) - parseFloat(from.substring(0, 2));
	monthsDiff = parseFloat(to.substring(3, 5)) - parseFloat(from.substring(3, 5));
	yearsDiff = parseFloat(to.substring(6, 10)) - parseFloat(from.substring(6, 10));

	if (daysDiff < 0){
		daysDiff = 30 + daysDiff
		monthsDiff = monthsDiff - 1;
	}

	if (monthsDiff < 0)	{
		monthsDiff = 12 + monthsDiff;
		yearsDiff = yearsDiff - 1;
	}

	if (daysDiff < 10)
		daysDiff = '0' + daysDiff;				

	if (monthsDiff < 10)
		monthsDiff = '0' + monthsDiff;

	if (yearsDiff < 10)
		yearsDiff = '0' + yearsDiff;

	return yearsDiff + ' ' + monthsDiff + ' ' + daysDiff;
}

var sCheckAge_ErrorMsg;
function checkAgeWritten(ageObj){
	sCheckAge_ErrorMsg = "";
	var sGenMsg = ""; 
	var nSlashes = 0;
	var bIsObject = false; var y = ''; var m = ''; var z; var a;
	if (typeof(ageObj) == "object") {bIsObject = true;}
		
	if (bIsObject)
		a = ageObj.value; 
	else
		a = ageObj;

	if (a == "yy mm" || a == ""){
		sCheckAge_ErrorMsg = sGenMsg + "Age not entered."		
		return "";
	}

	for (eachChr = 0; eachChr < a.length; eachChr++) 	{
		z = a.charAt(eachChr);
		if (z!='0' && z!='1' && z!='2' && z!='3' && z!='4' && z!='5' && z!='6' && z!='7' && z!='8' && z!='9' && z!=' ') 
		{
			sCheckAge_ErrorMsg = sGenMsg + "Invalid character(s) detected in age field."		
			return "";
		}else {
			if (z == ' ') {nSlashes++;}
			if (nSlashes == 0 && z != ' ') {y = y + '' + z;}
			else if (nSlashes == 1  && z != ' ') {m = m + '' + z;}
		}
	}
	
	if (nSlashes > 1){
		sCheckAge_ErrorMsg = sGenMsg + "Please enter age in the format 'YY MM'."		
		return "";
	}
	
	if (y.length != 1 && y.length !=2){
		sCheckAge_ErrorMsg = sGenMsg + "Invalid year in age field."		
		return "";
	}else if (y.length == 1){
		y = '0' + y;
	}
	
	if (m.length > 2){
		sCheckAge_ErrorMsg = sGenMsg + "Invalid month in age field."		
		return "";
	}	else if (m.length == 1)	{
		m = '0' + m;
	}	else if (m.length == 0)	{
		m = '00';
	}
	
	if (m < 0 || m > 11){
		sCheckAge_ErrorMsg = sGenMsg + "Invalid month in age field."		
		return "";
	}

	a = y + ' ' + m
	if (bIsObject)	{
		ageObj.value = a;
	}
	return a;
}

function isNumber(amtStr, fldsize){
	var checkChar;
	var blChecked=false;
	for (i = 0;i < fldsize; i++)	{
		checkChar = amtStr.charAt(i);
		if(checkChar == ".")		{	
			var y=amtStr.indexOf(".",0);
			for(i=y+1;i<fldsize;i++)			{
				checkChar = amtStr.charAt(i);
				if(checkChar !=0)
					return false;
				else
					blChecked=true;				
			}
		}
		
		if(blChecked==true)
			return true;
		else{
			if (checkChar != "0" && checkChar != "1" && checkChar != "2" && checkChar != "3" && checkChar != "4" && checkChar != "5" && checkChar != "6" && checkChar != "7" && checkChar != "8" && checkChar != "9")
				return false;
		}
	}	
	return true;
}

function isAlpha(str){
	var checkChar;
	
	for (i = 0; i < str.length; i++)	{
		checkChar = str.charAt(i);
		if(checkChar != "A" && checkChar != "B" && checkChar != "C" && checkChar != "D" && checkChar != "E" && checkChar != "F" && checkChar != "G" && checkChar != "H" && checkChar != "I" && checkChar != "J"
			&& checkChar != "K" && checkChar != "L" && checkChar != "M" && checkChar != "N" && checkChar != "O" && checkChar != "P" && checkChar != "Q" && checkChar != "R" && checkChar != "S" && checkChar != "T"
			&& checkChar != "U" && checkChar != "V" && checkChar != "W" && checkChar != "X" && checkChar != "Y" && checkChar != "Z" && checkChar != "a" && checkChar != "b" && checkChar != "c" && checkChar != "d"
			&& checkChar != "e" && checkChar != "f" && checkChar != "g" && checkChar != "h" && checkChar != "i" && checkChar != "j" && checkChar != "k" && checkChar != "l" && checkChar != "m" && checkChar != "n"
			&& checkChar != "o" && checkChar != "p" && checkChar != "q" && checkChar != "r" && checkChar != "s" && checkChar != "t" && checkChar != "u" && checkChar != "v" && checkChar != "w" && checkChar != "x"
			&& checkChar != "y" && checkChar != "z")
				return false;
	}

	return true;
}
function isAlphaChar(str){
		checkChar = str
		if(checkChar != "A" && checkChar != "B" && checkChar != "C" && checkChar != "D" && checkChar != "E" && checkChar != "F" && checkChar != "G" && checkChar != "H" && checkChar != "I" && checkChar != "J"
			&& checkChar != "K" && checkChar != "L" && checkChar != "M" && checkChar != "N" && checkChar != "O" && checkChar != "P" && checkChar != "Q" && checkChar != "R" && checkChar != "S" && checkChar != "T"
			&& checkChar != "U" && checkChar != "V" && checkChar != "W" && checkChar != "X" && checkChar != "Y" && checkChar != "Z" && checkChar != "a" && checkChar != "b" && checkChar != "c" && checkChar != "d"
			&& checkChar != "e" && checkChar != "f" && checkChar != "g" && checkChar != "h" && checkChar != "i" && checkChar != "j" && checkChar != "k" && checkChar != "l" && checkChar != "m" && checkChar != "n"
			&& checkChar != "o" && checkChar != "p" && checkChar != "q" && checkChar != "r" && checkChar != "s" && checkChar != "t" && checkChar != "u" && checkChar != "v" && checkChar != "w" && checkChar != "x"
			&& checkChar != "y" && checkChar != "z")
				return false;

	return true;
}
function isNINumber(str){

	for(i=0; i<9; i++)	{
		checkChar = str.charAt(i);

		if(((i == 0 || i == 1 || i ==8) && (isAlphaChar(checkChar) == false)) ||
			(i>1 && i<8 && isAlphaChar(checkChar) == true))	{
			alert("Please enter National Insurance Number in format AANNNNNNA")
			return 0;
		}
	}
	return 1;
}

function objectCount(object) {
	if (object) {
		if (object.length) {
			return object.length;
		} else {
			return 1;
		}
	} else {
		return 0;
	}
}

function getTermY(CDate,RDate){
	CDate_year = CDate.substring(6,10);
	CDate_month = CDate.substring(3,5);
	CDate_day = CDate.substring(0,2);

	RDate_year = RDate.substring(6,10);
	RDate_month = RDate.substring(3,5);
	RDate_day = RDate.substring(0,2);

	if(RDate_year > CDate_year)
	{
		TermY = parseFloat(RDate_year) - parseFloat(CDate_year);

		if(CDate_month > RDate_month || (CDate_month == RDate_month && CDate_day > RDate_day))
			TermY -= 1;
	}
	else
		TermY = 00;

	return TermY;
}

function getTermM(CDate,RDate){
	CDate_month = CDate.substring(3,5);
	RDate_month = RDate.substring(3,5);
	CDate_day = CDate.substring(0,3);
	RDate_day = RDate.substring(0,3);

	if(RDate_month >= CDate_month)
		TermM = parseFloat(RDate_month) - parseFloat(CDate_month);
	else
		TermM = parseFloat(RDate_month) + 12 - parseFloat(CDate_month);

	if(CDate_day > RDate_day)
		TermM -= 1;
	
	return TermM;
}

//added by Sandeep to validate length, pop up error message and return focus to the field
function validateLengthAndShowErrMess(otxtObject, nmaxLength, sNameOfField){
	if(otxtObject.value.length > nmaxLength)	{
		alert(sNameOfField +" cannot contain more than "+nmaxLength +" characters") ;
		otxtObject.focus() ;
		return 0;
	}
}

function IsPremiumDueDate(CDate,RDate,freq){
	CDateM = parseFloat(CDate.substring(3,5));
	RDateM = parseFloat(RDate.substring(3,5));
	CDateD = parseFloat(CDate.substring(0,3));
	RDateD = parseFloat(RDate.substring(0,3));

	if (RDateM <= CDateM)
		RDateM = RDateM + 12;

	firstYear = RDateM - CDateM;

	if(CDateD != RDateD)	{
		alert("The day must be the same as the day of commencement date");
		return 0;		
	}

	switch (freq)	{
		case "M": 
		case "Monthly":
				break;

		case "Q": 
		case "Quarterly" :

			if (firstYear != 3 && firstYear != 6 && firstYear != 9 && firstYear != 12)			{
				alert("Renewal date must be on a premium due date.");
				return 0;
			}
			break;

		case "H": 
		case "Half Yearly":

			if (firstYear != 6 && firstYear != 12)	{
				alert("Renewal date must be on a premium due date.");
				return 0;
			}
			break;

		case "Y": 
		case "A":
		case "Annually":
		case "Yearly":

			if (firstYear != 12){
				alert("Renewal date must be on a premium due date.");
				return 0	
			}
			break;
	}

	return 1;
}

//Function to remove highlight from the selected row
function RemoveHighlight(theID) {
	for (var i = 0; i < document.all[theID].length; i++){
		document.all[theID][i].className = "clsSmlNavOff"
	}
}

//Function to highlight the selected row
function HighlightAll(theID){
	for (var i = 0; i < document.all[theID].length; i++){
		document.all[theID][i].className = "clsSmlNavOver"
	}
}

// Function to check if a postcode is in a valid format.
function validatePostCode(objPost){
	var sTemp;
	var iTempLen;
	var sPart1;
	var sPart2;
	var bPostCodeOK;

	bPostCodeOK = 1;

	// First need to split the postcode into two parts. The second part will always be
	// 3 characters, so split these off.

	sTemp = stripAll(objPost.value, " ");
	sTemp = sTemp.toUpperCase();
	iTempLen = sTemp.length;
	sPart1 = stripAll(sTemp.substring(0,iTempLen-3), " ");
	sPart2 = stripAll(sTemp.substring(iTempLen-3, iTempLen), " ");

	if (sPart1.length == 4)	{		
		if ((isAlphaChar(sPart1.substring(0,1))) && 
			(isAlphaChar(sPart1.substring(1,2))) && 
			(isNumber(sPart1.substring(2,3),1)) && 
			((isNumber(sPart1.substring(3,4),1)) || (isAlphaChar(sPart1.substring(3,4))))){
			// This postcode is OK
		}else{
			alert("Invalid Postcode entered.");
			objPost.focus();
			objPost.select();
			return 0;
		}
	}

	if (sPart1.length == 3)	{		
		if (((isAlphaChar(sPart1.substring(0, 1))) && (isAlphaChar(sPart1.substring(1, 2))) && (isNumber(sPart1.substring(2),1))) ||
			((isAlphaChar(sPart1.substring(0, 1))) && (isNumber(sPart1.substring(1, 2),1)) && (isNumber(sPart1.substring(2),1))) ||
			((isAlphaChar(sPart1.substring(0, 1))) && (isNumber(sPart1.substring(1, 2),1)) && (isAlphaChar(sPart1.substring(2))))){
			// This postcode is OK
		}else{
			alert("Invalid Postcode entered.");
			objPost.focus();
			objPost.select();
			return 0;
		}
	}
	
	// If it is in the format AN
	if (sPart1.length == 2)	{
		if ((isAlphaChar(sPart1.substring(0, 1))) && (isNumber(sPart1.substring(1),1)))	{
			// This Postcode is OK
		}else{
			alert("Invalid Postcode entered.");
			objPost.focus();
			objPost.select();
			return 0;
		}
	}
	
	// If the first part of the postcode is in any other format, it can't be correct.
	if (sPart1.length < 2 || sPart1.length > 4)	{
		alert("Invalid Postcode entered.");
		objPost.focus();
		objPost.select();
		return 0;
	}

	// Now check 2nd part of postcode. Must always be in format NAA.
	if ((sPart2.length == 3) && (isNumber(sPart2.substring(0, 1),1)) && (isAlphaChar(sPart2.substring(1, 2))) && (isAlphaChar(sPart2.substring(2)))){
		// This postcode is OK
	}else{
		alert("Invalid Postcode entered.");
		objPost.focus();
		objPost.select();
		return 0;
	}

	// If we have got this far the postcode must be correct, so return it in a standard format
	objPost.value = sPart1 + " " + sPart2;
	return 1;
}

function fixTextString(str){
	var tempStr = str;	
	tempStr = stripAll(tempStr, ",");
	tempStr = stripAll(tempStr, "!");
	tempStr = stripAll(tempStr, "_");
	tempStr = stripAll(tempStr, "\\");
	return tempStr;}

// do not allow characters \ and " to be entered, checked onkeydown - added by KEH 4/6/01
// also do not allow characters '!', '£', '~', '^', '{', and '}' - added SJM 26/06/01
// also do not allow character '&' - added NT 01/08/02
function checkValidChar(e){
	var nWhichKeyPressed = -1;
	nWhichKeyPressed = e.keyCode
		
	//alert("Key pressed is:" + nWhichKeyPressed)
	if((nWhichKeyPressed == 220) || (nWhichKeyPressed == 50 && e.shiftKey) || (nWhichKeyPressed == 49 && e.shiftKey) || (nWhichKeyPressed == 54 && e.shiftKey)
		|| (nWhichKeyPressed == 51 && e.shiftKey)  || (nWhichKeyPressed == 55 && e.shiftKey) || (nWhichKeyPressed == 222) || (nWhichKeyPressed == 219) || (nWhichKeyPressed == 221))  
	{e.returnValue=false}
}

//Added by swapneswar to validate whether an entered date is between the given limits.For example
//date entered between sysdate-1 to sys date+5 yrs

function validateConDt(otxtObj,before ,after){	

	var CDate_year = dtServerDate.substring(6,10);
	var RDate_year = otxtObj.value.substring(6,10);
	var nYDiff=parseFloat(CDate_year)-parseFloat(RDate_year);
	var CDate_month = dtServerDate.substring(3,5);
	var RDate_month = otxtObj.value.substring(3,5);
	var nMDiff = parseFloat(CDate_month) - parseFloat(RDate_month);
	var nDayDiff = parseFloat(dtServerDate.substring(0, 2)) - parseFloat(otxtObj.value.substring(0, 2));
	
	if ((nYDiff==before) && (nMDiff == 0 && nDayDiff<0)) {
		return "";
      }
    if ((nYDiff==before) && (nMDiff < 0)) {
		return "";
      }
	
	if ((nYDiff==-(after)) && (nMDiff == 0 && nDayDiff >0)){	
		return "" ;
	  }	
	 if ((nYDiff==-(after)) && (nMDiff > 0 )){	
		return "" ;
	  }	
	  
	if ((nYDiff < before) && (nYDiff > -(after))){	
		return "";
	  }	
	var Beforelimit=CDate_year-before;
	var Afterlimit=CDate_year+after;
	if 	 ((RDate_year > Beforelimit) && (RDate_year<Afterlimit)) {
	 return "";
	}
	alert("Contribution date Should be between system date minus" + before+ " year to system date plus "+after+" years");
	otxtObj.focus();
	otxtObj.select();			
}

/****************************************************************
function to check whether a field contains all blank spaces
*****************************************************************/
function isAllBlankSpace(oValue){
	var blsAllBlank = true ;
	var str = "" + oValue ;
	for(i=0;i<str.length;i++){
		if(str.charAt(i) != " ")
			blsAllBlank = false ;
	}
	return blsAllBlank ;
}

/****************************************************************
function to compare two date's
parameter: date1, date2
if date1=date2 then return 0
if date2<date1 then return -1
if date2>date1 then return 1
*****************************************************************/
function compareDates(date1,date2){
	var nCDateFrom_year = date1.substring(6,10);
	var nCDateTo_year = date2.substring(6,10);
	
	if(nCDateTo_year < nCDateFrom_year)	{
		return -1;
	}else if(nCDateTo_year == nCDateFrom_year){
		var nCDateFrom_month = date1.substring(3,5);
		var nCDateTo_month = date2.substring(3,5);
		if(nCDateTo_month < nCDateFrom_month){
			return -1;
		}else if(nCDateTo_month == nCDateFrom_month){
			var nCDateFrom_day = date1.substring(0,2);
			var nCDateTo_day = date2.substring(0,2);
			if(nCDateTo_day < nCDateFrom_day){	
				return -1;
			}else if(nCDateTo_day == nCDateFrom_day)
				return 0;
			else return 1;
		}
		else return 1;
	}
	else return 1;	
}



function padString(stringToPad, sideToPad, charToPadWith, sizeToPadTo){

var padSide = sideToPad.toUpperCase();
var paddedStr="Error : General error in input!";
var padSize = parseFloat(sizeToPadTo);
var unpadStr = stringToPad;
var attStr =  "";
var padCharLen = charToPadWith.length;
if (padSize != 0) {
	if (padCharLen == 1) {
		for (howMany=0; howMany<padSize; howMany++){
		attStr = attStr + charToPadWith;
		}
	
		if (padSide=="L" || padSide=="R"){
		
			if (padSide=="L"){
			unpadStr = attStr + unpadStr;
			unpadLen = unpadStr.length;
			unpadCut = unpadLen-padSize;
			paddedStr = unpadStr.substring(unpadCut, unpadLen);
			}
			
			if (padSide=="R"){
			unpadStr = unpadStr + attStr;
			paddedStr = unpadStr.substring(0, padSize);
			}
		}
		else {paddedStr="Error : Pad-side is not 'L' or 'R'!";}
	}
	else {paddedStr="Error : Padding character does not have unit length!";}
}
	
else {paddedStr = "Error : Pad-size passed should be a non-zero integer!";}
return paddedStr;
}

function roundToDecimals(numberToRound, decimalPlaces)
{
	var sNum = '' + numberToRound;
	var nDec = parseInt(decimalPlaces);
	var iDec = sNum.indexOf(".", 0);
	var sInt, sDec, i;
	if (iDec == -1)	{
		sNum = sNum + "."
	}
	for (i=0; i<nDec; i++){
		sNum = sNum + "0";
	}
	iDec = sNum.indexOf(".", 0);
	sInt = sNum.substring(0, iDec);
	sDec = sNum.substring(iDec+1, iDec+nDec+1);
	sNum = sInt + "." + sDec;
	
	return sNum;
}

 function validateAmount(objtxt,nEndRange,nTotalPlace,nDecimalPlace){
	
		
	if (parseFloat(checkDecimalNumber(objtxt.value,nTotalPlace,nDecimalPlace))!=-1)	{
		if (parseFloat(checkDecimalNumber(objtxt.value,nTotalPlace,nDecimalPlace))<0){
			objtxt.value=0;
		    alert("Please enter a number from 0 to " + nEndRange);
		}else{
			objtxt.value=checkDecimalNumber(objtxt.value,nTotalPlace,nDecimalPlace);
			if (objtxt.value>nEndRange)	{
				objtxt.value = nEndRange;
				alert("Value has been changed to Maximum Limit" + nEndRange);
			}
		}
	}else{	
		objtxt.value=0;
		objtxt.focus();
		objtxt.select();
	}  
 }

var hlpWindow;
function openHelp(sHelpPage, sHelpName) {
	sLocation = "Help/" + sHelpPage + ".htm#" + sHelpName;
	hlpWindow = window.open(sLocation, "EService_Help","menubar=no,height=100,width=650,top=0,left=0,scrollbars=1");
	hlpWindow.focus();
}

//////////////Karthik's functions
	function formatNumber(nVal) {
	  var sTemp, sDecimal, nTemp, nLen;
	  var arrTemp, arrRound;

	  sTemp = "" + nVal;
	  arrTemp = sTemp.split(".");
	  if (arrTemp.length == 2) {
		sDecimal = "" + arrTemp[1];
		nLen = sDecimal.length;
		switch (nLen) {
		  case 0 : 
			sDecimal += "00";
			break;
		  case 1 :
			sDecimal += "0";
			break;
		  default :
			sDecimal += "";
		}
		return arrTemp[0] + "." + sDecimal;
	  }
	  return arrTemp[0] + ".00";
	}

	function formatCurrency(sNum) {
		//This functions formats the currency by suffixing ".00" and by attaching appropriate commas after every third digit
		//All formatting is done ONLY if necessary, along with some error handling
		//So, 123456 will be formatted as 123,456.00 where as 1,234.5 will be formatted as 1,234.50

		var nPos, bFound, sDecimal, sCurrency, nCtr, sTemp;

		//Remove leading/trailing blanks
		sNum = trim(sNum);
		sTemp = "";

		//Return bogus or incomplete string as "0"
		if ((sNum == "") || (sNum == ".") || (sNum == "0") || (sNum == "0.00") || (sNum == "-")) {
			return "0.00";
		}

		//Get the decimal part separately
		nPos = sNum.indexOf(".")
		if (nPos > 0) {
			bFound = true;
			sDecimal = sNum.slice(nPos + 1);
			sNum = sNum.slice(0, nPos);
		}

		//Eliminate any of ",£ " characters if exists
		for (nCtr = 0; nCtr < sNum.length; nCtr++) {
			if ((sNum.charAt(nCtr) != ".") && (sNum.charAt(nCtr) != ",") && (sNum.charAt(nCtr) != "£") && (sNum.charAt(nCtr) != " ")) {
				sTemp += sNum.charAt(nCtr);
			}
		}
		
		sNum = sTemp;
		sTemp = "";

		//Now handle "," in reverse order of string
		sTemp = sNum;
		nPos = 0;
		for (nCtr = sNum.length; nCtr > 0; nCtr--) {
			//Keep a count of the position relative to ".", since "," needs to be inserted after every third position
			if (nPos == 3) {
				//Reset the relative position for next ","
				nPos = 1;
				sTemp = sTemp.slice(0, nCtr) + "," + sTemp.slice(nCtr);
			} else {
				nPos += 1;
			}
		}

		sNum = sTemp + ".";

		if (bFound) {
			//Suffix required number of 0's till 2nd decimal place, or retain the existing decimals if excess of 2
			if (sDecimal.length == 0) {
				sNum += "00";
			} else if (sDecimal.length == 1) {
				sNum += sDecimal + "0";
			} else {
				sNum += sDecimal.slice(0,2);
			}
		} else {
			sNum += "00";
		}

		return sNum;
	}


function trim(sVal) {
  var sModVal = sVal
  while (sModVal.indexOf(" ")>=0) {
	sModVal = sModVal.replace(" ","");
  }
  return sModVal;
}

function ltrim(sVal) {
	var sModVal = "";
	var sChrFnd = "";

	ty=0;

	while (ty != sVal.length - 1) {
		if (sVal.charAt(ty) != " " && sChrFnd != "Y") {
			sChrFnd="Y";
			break;
		}
		ty = ty + 1;
	}

	sModVal = sVal.substr(ty,sVal.length - ty);
	return sModVal;
}

function rtrim(sVal) {
	var sModVal = "";
	var sChrFnd = "";

	ty=sVal.length - 1;

	while (ty != 0) {
		if (sVal.charAt(ty) != " " && sChrFnd != "Y") {
			sChrFnd="Y";
			break;
		}

		ty = ty - 1;
	}

	sModVal = sVal.substr(0,ty + 1);

	return sModVal;
}

///////////////////
function enableControl(oObject,strColor){
	var sColor;
	if (strColor == "")	{
		sColor = "#ffffff";
	}else{
		sColor = strColor;
	}

	oObject.disabled = false;
	oObject.style.backgroundColor = sColor;
}

function disableControl(oObject,strColor){
	var sColor;
	if (strColor == "")	{
		sColor = "#d3d3d3"
	}else{
		sColor = strColor
	}
	oObject.disabled = true;
	oObject.style.backgroundColor = sColor;
}

function lockControl(oObject,strColor){
	var sColor;
	if (strColor == "")	{
		sColor = "#d3d3d3"
	}else{
		sColor = strColor
	}
	oObject.readOnly = true;
	oObject.tabIndex = -1;
	oObject.style.backgroundColor = sColor;
}

function unlockControl(oObject,strColor){
	var sColor;
	if (strColor == "")	{
		sColor = "#ffffff"
	}else{
		sColor = strColor
	}

	oObject.readOnly = false;
	oObject.tabIndex = 0;
	oObject.style.backgroundColor = sColor;
}

function getCheckDigit(itrno){
	if ((itrno == "") || isNaN(itrno) || isAllBlankSpace(itrno) || itrno.length > 6) {
		return "Invalid Agency Number entered";
	}
	var fullitrno, subtotal, remtotal, checknum, sReturn;

	// first expand the itr no to 6 digits
	fullitrno = padString(itrno, "L", "0", 6);

	// now add all the digits together with their corresponding weightings

	subtotal = parseInt(fullitrno.charAt(0)) * 4;
	subtotal = subtotal + parseInt(fullitrno.charAt(1)) * 8;
	subtotal = subtotal + parseInt(fullitrno.charAt(2)) * 5;
	subtotal = subtotal + parseInt(fullitrno.charAt(3)) * 9;
	subtotal = subtotal + parseInt(fullitrno.charAt(4)) * 7;
	subtotal = subtotal + parseInt(fullitrno.charAt(5)) * 3;

	remtotal = subtotal % 11;
	checknum = 11 - remtotal;

	// now select the check digit depending on the number calculated

	switch (checknum) {
	   case 1 :
	      sReturn = "A";
	      break;
	   case 2 :
	      sReturn = "B";
	      break;
	   case 3 :
	      sReturn = "C";
	      break;
	   case 4 :
	      sReturn = "D";
	      break;
	   case 5 :
	      sReturn = "E";
	      break;
	   case 6 :
	      sReturn = "F";
	      break;
	   case 7 :
	      sReturn = "G";
	      break;
	   case 8 :
	      sReturn = "H";
	      break;
	   case 9 :
	      sReturn = "J";
	      break;
	   case 10 :
	      sReturn = "K";
	      break;
	   case 11 :
	      sReturn = "L";
	      break;
	   default :
	      sReturn = "ERROR";
	      break;
	}
	return sReturn; 
}

function swapImage(obj,strImg){
	obj = eval(obj);
	obj.src = "/EService/Images/" + strImg;
}

function dropCurtain(){
//	document.all("IDMainViewingArea").style.visibility = "hidden";
//	document.all("IDNavBar").style.visibility = "hidden";
//	showWaitFlame();
}

function showWaitFlame(){
//	document.all("IDWaitFlame").style.visibility = "visible";
}
// This function was only showing part of the text "rotating flame" which was
// written above the marquee end-tag of "IDWaitFlame" at the bottom of this page. This 
// text has been removed at present. To be replaced with a flame image in the future?. JK

function hideWaitFlame(){
//	document.all("IDWaitFlame").style.visibility = "hidden";
}

/*Functions related to showing and hiding of postit notes*/
function showPostitNote(obj, sMsg, nDisplayTime){
	var nTop = 0, nLeft = 0;
	var oCurrent = obj;
	
	while (oCurrent.offsetParent.id != 'IDBodyTag')	{
	
		oCurrent = oCurrent.offsetParent;
		nLeft = nLeft + oCurrent.offsetLeft;
		nTop = nTop + oCurrent.offsetTop;			
	}
	
	nTop = nTop + 10;
	nLeft = nLeft + 20;
	document.all("IDPostit").style.left = nLeft;
	document.all("IDPostit").style.top = nTop;
	document.all("IDPostit").innerHTML = sMsg;
	document.all("IDPostit").style.zIndex = 1000;
	document.all("IDPostit").style.visibility = "visible";
	timerHandle = setInterval('hidePostitNote(-1)',nDisplayTime);
	return;
}
var nPostitNoteCounter = 0;
function hidePostitNote(nAction){
	if (nAction == 0){
		nPostitNoteCounter = 0;
		clearInterval(timerHandle);
		document.all("IDPostit").innerHTML = "";
		document.all("IDPostit").style.visibility = "hidden";
	}else{
		if 	(nPostitNoteCounter == 2){
			nPostitNoteCounter = 0;
			clearInterval(timerHandle);
			document.all("IDPostit").innerHTML = "";
			document.all("IDPostit").style.visibility = "hidden";
		}else{
			nPostitNoteCounter++;
		}
	}
	return;
}

function checkDateRange(objRefDate, objCheckDate,iyear,imonth,iday){
	// this function checks that the date object objCheckDate is within iyear, imonth or iday of the 
	// entered check date (javascript date objects)
	// a positive year / month / day will check that the check date is within scope after the ref date
	// a negative year / month / day will check that the check date is within scope before the ref date
	var objTemp = new Date();

	// validate input parameters (only one of year month or day allowed)
	if ((iyear == 0) && (imonth == 0) && (iday == 0))
		return false;
	if ((iyear != 0) && (imonth != 0))
		return false;
	if ((iyear != 0) && (iday != 0))
		return false;
	if ((imonth != 0) && (iday != 0))
		return false;
	if (objRefDate.toString() == objCheckDate.toString())
		return true;

	objTemp.setFullYear(objRefDate.getFullYear() + iyear);
	objTemp.setMonth(objRefDate.getMonth() + imonth);
	objTemp.setDate(objRefDate.getDate() + iday);

	if (objRefDate < objCheckDate)
	{	// check for date within range after RefDate
		if (objTemp >= objCheckDate)
		{	// date within range
			return true;
		}
	}
	if (objRefDate > objCheckDate)
	{	// check for date within range before RefDate
		if (objTemp <= objCheckDate)
		{	// date within range
			return true;
		}
	}
	return false; 
}

// SJM - 31/01/02
//  CB - 25/10/04 Separate function created below for A&E which doesn't check on the address value being blank first.
//				  Please maintain both functions when changes are made	 
function focusMbrAddress(obj, sPath, sAdrName, sPCodeName){
	var sRtnValue, sAdr1;
	var arrAdrLine;
	var arrRtnValue = new Array(5);
	var i = 1;
	if (obj.value == ""){
		sRtnValue = window.showModalDialog(sPath,"AddressDetails","dialogWidth=355px;dialogHeight=185px;scrollbars=no;resizable=no;center=yes;border=thin;help=no;status=no;");		
		if (sRtnValue){
			arrRtnValue = sRtnValue.split("~");			
			if (arrRtnValue[0] != "false" && arrRtnValue[0]!= "ZapCode Error"){
				arrAdrLine = arrRtnValue[2].split(",");
				arrRtnValue[0] +=(arrRtnValue[0])?' - ':'';
				sAdr1 = arrRtnValue[0].toUpperCase()+arrRtnValue[1]+ ' '+ arrAdrLine[0];
				if (sAdr1.length > 32){
					alert("The maximum allowable characters of 32 in the first address field has been exceeded and will be truncated!");}				
				eval("document.all." + sAdrName + i++).value=sAdr1.substr(0,32);
				if (arrAdrLine[1]){eval("document.all." + sAdrName + i++).value=arrAdrLine[1];}
				eval("document.all." + sAdrName + i++).value=arrRtnValue[3];
				eval("document.all." + sAdrName + i++).value=(arrRtnValue[3]!= arrRtnValue[4])?arrRtnValue[4]:'';
				eval("document.all." + sPCodeName).value=arrRtnValue[5];
			}				
			else{	
				if (arrRtnValue == "false" ){ alert(" Invalid Postcode ");}
				else { 
					if (arrRtnValue == "ZapCode Error" ){ 
						alert("Sorry Our Address Server is Not Available");
					}
				}
			}
		}
	}
}

//Separate function created below for A&E which doesn't check on the address value being blank first.
//Please maintain both functions when changes are made	 

function AE_focusMbrAddress(obj, sPath, sAdrName, sPCodeName){
	var sRtnValue, sAdr1;
	var arrAdrLine;
	var arrRtnValue = new Array(5);
	var i = 1;

	sRtnValue = window.showModalDialog(sPath,"AddressDetails","dialogWidth=355px;dialogHeight=185px;scrollbars=no;resizable=no;center=yes;border=thin;help=no;status=no;");		
	if (sRtnValue){
		arrRtnValue = sRtnValue.split("~");			
		if (arrRtnValue[0] != "false" && arrRtnValue[0]!= "ZapCode Error"){
			arrAdrLine = arrRtnValue[2].split(",");
			arrRtnValue[0] +=(arrRtnValue[0])?' - ':'';
			sAdr1 = arrRtnValue[0].toUpperCase()+arrRtnValue[1]+ ' '+ arrAdrLine[0];
			if (sAdr1.length > 32){
				alert("The maximum allowable characters of 32 in the first address field has been exceeded and will be truncated!");}				
			eval("document.all." + sAdrName + i++).value=sAdr1.substr(0,32);
			if (arrAdrLine[1]){eval("document.all." + sAdrName + i++).value=arrAdrLine[1];}
			eval("document.all." + sAdrName + i++).value=arrRtnValue[3];
			eval("document.all." + sAdrName + i++).value=(arrRtnValue[3]!= arrRtnValue[4])?arrRtnValue[4]:'';
			eval("document.all." + sPCodeName).value=arrRtnValue[5];
			setFlg();
		}				
		else{	
			if (arrRtnValue == "false" ){ 
				alert(" Invalid Postcode ");
			}
			else { 
				if (arrRtnValue == "ZapCode Error" ){ 
					alert("Sorry Our Address Server is Not Available");
				}
			}
		}
	}
}

function validateEMail(obj)
{
	var s=""
	invalidChars = "' /:,;"
	if (trim(obj.value) == "")	
	{	
		alert("Please enter an email address.");
		obj.focus();
		return;
	}

	for (i = 0; i< invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i)
		if (obj.value.indexOf(badChar,0) != -1)
		{
			alert("You can't use following characters " + invalidChars +" in your email address.");
			obj.focus();
			return;
		}
	}
	atPos = obj.value.indexOf("@",1)
	if (atPos == -1)
	{
		alert("You need to provide an email address - this should be in the format info@SLAC.com.");
		obj.focus();
		return;
	}
	if (obj.value.indexOf("@",atPos+1) != -1)
	{
        alert("The Email address you have provided does not have @ symbol. Please enter a valid email address.");
		obj.focus();
		return;
	}
}