<!--//

function ValidateEmailAddr(strNewAddr)
{
	//checks string and returns true or false
	if (strNewAddr.indexOf("@") <= 1)
	{
		return false
	}
	else
	{
		if (strNewAddr.indexOf(".") <= 1)
		{
			return false
		}
		else
		{
			if (strNewAddr.indexOf(" ") != -1)
			{
				return false
			}
			else
			{
				if (strNewAddr.length < 3)
				{
					return false
				}
				else
				{
					if (strNewAddr.length < 3)//Extra criteria goes here.
						{
						return false
					}
					else
					{
						return true
					}
				}
			}
		}
	}
}
function GetSelectedIndex(objGroup)
//30052002 DLD
//used for radio groups to find the selected item
//returns zero if no item selected
//else returned value starts at one.
{
	for (var i = 0 ; i < objGroup.length ; i++)
	{
		if (objGroup[i].checked)
		{
		    return i + 1 
		}
	}
	return 0
}

function GetSelectedValue(objGroup)
//30052002 DLD
//used for radio groups to find the selected value
//returns empty string if no item selected
//else returns value.
{
	if (GetSelectedIndex(objGroup) != 0)
	{
	    return objGroup[GetSelectedIndex(objGroup)- 1].value 
	}
	else
	{
		return ""
	}
}


function FindSelectIndexFromValue(objSelect,strStoredValue)
//recieves a select item and a stored value and searches the select item for the value,
//if found it sets the selected index of the select item to the first instance of the value.
{
	if(strStoredValue != "")
	{
		for ( var z = 0 ; z < objSelect.options.length ; z++)
		{
			//the line below helps in debugging the script
			//alert(objSelect.options[z].text + "    \n" + strStoredValue + "\n\n" +objSelect.options[z].text.length + "    \n" + strStoredValue.length)
			if (strStoredValue == objSelect.options[z].text)
			{
				objSelect.selectedIndex = z
				break
			}			
		}
	}
}

function FindArrayIndexFromValue(objArray,strElement,strStoredValue)
//recieves an array and a stored value and searches the array element (strElement )for the value,
//if found it returns the selected index of the array to the first instance of the value.
{
	if(strStoredValue != "")
	{
		for ( var z = 0 ; z < objArray.length ; z++)
		{
			//the line below helps in debugging the script
			if (strStoredValue == objArray[z][strElement])
			{
				return z;
				break
			}			
		}
		alert(objArray.length + "    \n\n" +  objArray[z][strElement] + "    \n\n" + strStoredValue)
	}
}



function openAWindow( pageToLoad, winName, width, height, center, scroll, status, resize)
{
	if (winName == "itdetailWin")
	{
		var idxEquals = pageToLoad.indexOf("=")+1
		pageToLoad = (pageToLoad.substr(0,idxEquals)) + (escape(pageToLoad.slice(idxEquals)))
	}
	xposition=10; yposition=10;
		if ((parseInt(navigator.appVersion) >= 4 ) && (center)) {
			xposition = (screen.width - width) / 2;
			yposition = (screen.height - height) / 2;
		}
	if (status == "" || status == null )
	{
		status = "0"
	}
	else
	{
		status = "1"
	}
	if (resize == "" || resize == null )
	{
		resize = "0"
	}
	else
	{
		resize = "1"
	}
	
	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0,"
	+ "menubar=0,"
	+ "resizable=" + resize + ","
	+ "scrollbars=" + scroll + ","
	+ "status=" + status + ","
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "left=" + xposition + ","
	+ "top=" + yposition;
	
	var objNewWindow = window.open(pageToLoad,winName,args);
	
	//return objNewWindow;
}


// Start Image Swap Functions
	function hiLite(imgDocID,imgObjName)
	{
		document.images[imgDocID].src = imgObjName;
	}
	function hiLiteOff(imgDocID,imgObjName)
	{
		document.images[imgDocID].src = imgObjName;
		
	}
// End Image Swap Functions


function BrowserTest()
{
	//browser test:
	bName = navigator.appName;
	bVer = parseInt (navigator.appVersion);
	
	if (bName == "Netscape" && bVer >= 3)
	{
		version = "n3";
	}
	else
	{
		if(bName == "Netscape" && bVer == 2)
		{
			version = "n2";
		}
		else
		{
			if (bName == "Microsoft Internet Explorer" && bVer >= 3)
			{
				version = "n3";
			}
			else
			{
			version = "n2";
			}
		}
	}
	if (version== "n3")
	{
		p1off = new Image(); p1off.src = "images/btnPrinterOff.gif";
		p1on = new Image(); p1on.src = "images/btnPrinterOver.gif";
		h1off = new Image(); h1off.src = "images/btnHelpOff.gif";
		h1on = new Image(); h1on.src = "images/btnHelp.gif";
		h2off = new Image(); h2off.src = "images/btnHelpOff2.gif";
		h2on = new Image(); h2on.src = "images/btnHelp.gif";
	}
}

//##### Start Date Validation Functions
	function getFront(mainStr,searchStr)
	{	
		//extract front part of string prior to searchString
		var foundOffset = mainStr.indexOf(searchStr)
		if (foundOffset == -1 )
		{
			return null
		}
		return mainStr.substring(0,foundOffset)
	}

	function getEnd(mainStr,searchStr)
	{
		//extract back end of string after searchString
		var foundOffset = mainStr.indexOf(searchStr)
		if (foundOffset == -1)
		{
			return null
		}
			return mainStr.substring(foundOffset+searchStr.length,mainStr.length)
	}

	function insertString(mainStr,searchStr,insertStr)
	{	
		//insert insertString immediately before searchString	
		var front = getFront(mainStr,searchStr)
		var end = getEnd(mainStr,searchStr)
		if (front != null && end != null )
		{
			return front + insertStr + searchStr + end
		}
		return null
	}
	function deleteString(mainStr,deleteStr)
	{
		// remove deleteString
		return replaceString(mainStr,deleteStr,"")
	}
		
	function replaceString(mainStr,searchStr,replaceStr)
	{
		//replace searchStr with replaceStr
		var front = getFront(mainStr,searchStr)
		var end = getEnd(mainStr,searchStr)
		if (front != null && end != null)
		{
			return front + replaceStr + end
		}	
		return null
	}

	function checkMonthLength(dd,mm)
	{
		//check the entered month for too high a value
		var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December")
		if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30 )
		{
			alert(months[mm] + " only has 30 Days.")
			return false
		}
		else
		{	if (dd > 31)
			{
				alert (months[mm] + " only has 31 days.")
				return false
			}
		}
		return true
	}
	function checkLeapMonth(dd,mm,yyyy)
	{ 
		//check the entered February date for too high a value
		if (yyyy % 4 > 0 && dd > 28 )
		{
			alert("February of " + yyyy + " only has 28 days.")
			return false
		}
		else
		{
			if (dd > 29)
			{
				alert("February of " + yyyy + " only has 29 days.")
				return false
			}
		}
		return true
	}

	function isDate(newinputStr,textfield,stresdLocale)
	{
	//30052002 DLD added return true to the bottom of the function.
	//05/12/2002 DLD added locale processing to compensate for different dates.
	var strMsg = "The date is not in an acceptable format.\n\nYou can only enter dates in the following formats : "
		
	if (stresdLocale == null )
	{
		alert("eSDLocal Has not been set for this page, using defaults")
		strMsg += "ddmmyyyy, dd/mm/yyyy, or dd-mm-yyyy"
	}
	else
	{
		switch (stresdLocale)
		{
		case "US" :
			strMsg += "mmddyyyy, mm/dd/yyyy, or mm-dd-yyyy"
			break;
		case "CH" :
			strMsg += "yyyymmdd, yyyy/mm/dd, or yyyy-mm-dd"
			break;
		default :
			strMsg += "ddmmyyyy, dd/mm/yyyy, or dd-mm-yyyy"
		}
	}
		var inputStr = newinputStr.value

		// convert hyphen delimiters to slashes
		while (inputStr.indexOf("-") != -1 )
		{
			inputStr = replaceString(inputStr,"-","/")
		}
		var delim1 = inputStr.indexOf("/")
		var delim2 = inputStr.lastIndexOf("/")

		if (delim1 != -1 && delim1 == delim2)
		{
			//there is only one delimiter

			alert(strMsg)
				newinputStr.focus()
				newinputStr.select()
			return false
		}
			
		if (delim1 != -1)
		{
			// there are delimiters; extract component values
			switch (stresdLocale)
			{
			case "US" :
				var mm = parseInt(inputStr.substring(0,delim1),10)
				var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10)
				var yyyy = parseInt(inputStr.substring(delim2 + 1,inputStr.length),10)
				break;
			case "CH" :
				var yyyy = parseInt(inputStr.substring(0,delim1),10)
				var mm = parseInt(inputStr.substring(delim1 + 1,delim2),10)
				var dd = parseInt(inputStr.substring(delim2 + 1,inputStr.length),10)
				break;
			default :
				var dd = parseInt(inputStr.substring(0,delim1),10)
				var mm = parseInt(inputStr.substring(delim1 + 1,delim2),10)
				var yyyy = parseInt(inputStr.substring(delim2 + 1,inputStr.length),10)
			}
		}
		else
		{
			// there are no delimiters; extract component values
			switch (stresdLocale)
			{
			case "US" :
				var mm = parseInt(inputStr.substring(0,2),10)
				var dd = parseInt(inputStr.substring(2,4),10)
				var yyyy = parseInt(inputStr.substring(4,inputStr.length),10)
				break;
			case "CH" :
				var cntYear = 0
				if (Number(newinputStr.value) > 999999){cntYear = 2}
				var yyyy = parseInt(inputStr.substring(0,2 + cntYear),10)
				var mm = parseInt(inputStr.substring(2 + cntYear,4 + cntYear),10)
				var dd = parseInt(inputStr.substring(4 + cntYear,inputStr.length),10)
				break;
			default :
				var dd = parseInt(inputStr.substring(0,2),10)
				var mm = parseInt(inputStr.substring(2,4),10)
				var yyyy = parseInt(inputStr.substring(4,inputStr.length),10)
			}
		//alert(newinputStr.value + "\nmm\t" + mm + "\ndd\t"+dd+"\nyyyy\t"+yyyy)
		}
		
		if (isNaN(dd) || isNaN(mm) || isNaN(yyyy))
		{
			// there is a non-numeric character in the Date
				alert(strMsg)
				newinputStr.focus()
				newinputStr.select()
			return false
		}    
		if (dd < 1 || dd > 31)
		{
			// day value is not 1 thru 31
			alert("Days must be entered between the range of 01 to 31")
				newinputStr.focus()
				newinputStr.select()
			return false
		}
		if (mm < 1 || mm > 12)
		{
			// month value is not 1 thru 12
			alert("Months must be entered between the range of 01 (January) to 12 (December)")
				newinputStr.focus()
				newinputStr.select()
			return false
		}
		if (yyyy < 100)
		{
			// entered value is two digits
			if (yyyy >= 30) {
				yyyy += 1900
			} else {
				yyyy += 2000
			}
		}
			
		if (!checkMonthLength(dd,mm))
		{
			newinputStr.focus()
			newinputStr.select()
			return false
		}
		if (mm == 2)
		{
			if (!checkLeapMonth(dd,mm,yyyy))
			{
				newinputStr.focus()
				newinputStr.select()
				return false
			}
		}
		var today = new Date()
		var newDate = new Date(yyyy,mm - 1,dd + 1)
		
		if (today > newDate)
		{
			alert ("You cannot enter a required date before today's date.")
			newinputStr.focus()
			newinputStr.select()
			return false;
		}
		// Put value back into field
		var strNewValue
		
		switch (stresdLocale)
		{
		case "US" :
			strNewValue = mm + "/" + dd + "/" + yyyy
			break;
		case "CH" :
			strNewValue = yyyy + "/" + mm + "/" + dd
			break;
		default :
			strNewValue = dd + "/" + mm + "/" + yyyy
		}
		
		
		
		newinputStr.value = strNewValue
		return true ;
	}
//##### End Date Functions

function formatNumber (expr, decplaces)
{
	// formatNumber function for SO Entry Screen
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	while(str.length <= decplaces)
	{
		str = "0" + str
	}
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);
}

function dollarise (expr, locale)
{
	// dollarise function for SO Entry Screen
	// return "$" + formatNumber (expr, 2 )
	
	switch (locale)
	{
	case "US" :
		return "$" + formatNumber (expr, 2 )
		break;
	case "UK" :
		return "£" + formatNumber (expr, 2 )
		break;
	default :
		return "$" + formatNumber (expr, 2 )
	}
}

function isWholeNumber(chknum)
{
	// isWholeNumber function for SO Entry Screen
	var chknum
	if (Math.ceil(chknum) != chknum)
	{
		alert("Value must be a whole number - Rounding Up")
		chknum = Math.ceil(chknum)
	}
	return chknum;
}

//Start Loading Bar Functions
var ibar = 0;
var blnTimerRunning = "True";
	function startbar(top)
	{
		document.write('<div id="d1" name="d1" class="fieldData" style="text-indent:0px;position:absolute;top:' + top + 'px;"></div>')
		document.write('<div id="d2" name="d2" style="background-color:red;position:absolute;left:150px;top:' + top + 'px;"></div>')
		longtime()
	}

	function endbar()
	{
		blnTimerRunning = "False"
	}

	function longtime()
	{
		ibar = 0;
		document.getElementById("d1").innerText="Loading Data, Please Wait!";
		timedIterations(); 
	}

	function timedIterations()
	{
		if (ibar<=1000 && blnTimerRunning == "True")
		{
			document.getElementById("d2").style.width=ibar;
			setTimeout("timedIterations();", 100);
			ibar += 10;   
		}
		else
		{
			document.getElementById("d1").innerText="";
			document.getElementById("d2").style.width = 0;
		}
	}
//End Loading Bar Functions
//Start quote description limitation function
											
		function WriteToHiddenField(objTextField)
		{//version 1.1, breaks contents of text area up into substrings small enough to fit in the qu fields
			
			//30052002 DLD should be on the onkeyup event in a text area, not the on key press
			// else it will cut the last letter of the text area as it hasn't been saved at the instant that the value
			//is read.
			
			var strTextArea = objTextField.value
			var x = 0
			var intFindStart = 0
			var intFindEnd = 0
			var strNewLine = "\n"
			var blnMoreLines = true
			var intFindSpace = 0
			while(blnMoreLines)
			
			{
				if (x < 8 )
				{
					intFindEnd = strTextArea.indexOf(strNewLine,intFindStart)// find the ending point of the line
					if (intFindEnd == -1)//if no newlines are after the start of this substring
					{
						if (strTextArea.substring(intFindStart).length < 70)
						{//if the user has not entered any spaces
							
							//for debugging
							//alert("substring :" + strTextArea.substring(intFindStart) + "\nintFindStart :" + intFindStart)
							
							document.getElementById('qmGenDesc' + x).value = strTextArea.substring(intFindStart)
							blnMoreLines = false
							break
						}
						else
						{//find a space and break the line at the space
							intFindSpace = strTextArea.lastIndexOf(" ", intFindSpace + 70)
							document.getElementById('qmGenDesc' + x).value = strTextArea.substring(intFindStart,intFindSpace)
							intFindStart = intFindSpace + 1
							x++
						}
					}
					else
					{	
						if (strTextArea.substring(intFindStart,intFindEnd).length < 70)
						{
							document.getElementById('qmGenDesc' + x).value = strTextArea.substring(intFindStart,intFindEnd)
							intFindStart = intFindEnd + 1
							x++
						}
						else
						{//find a space and break the line at the space
							intFindSpace = strTextArea.lastIndexOf(" ", intFindSpace + 70)
							document.getElementById('qmGenDesc' + x).value = strTextArea.substring(intFindStart,intFindSpace)
							intFindStart = intFindSpace + 1
							x++
						}
					}
				}else
				{
					alert("This area can only hold a maximum number of 8 lines of information,\nwith a maximum of 70 characters in each line.\nPlease revise your statement")
					objTextField.value = objTextField.value.substring(0, objTextField.value.length - 2);
				break
				}		
			}
		}
//End the quote description limitation function

function subWindowClose(isSub)
{
	if(isSub)
	{
		javascript:window.opener.location.href = "../wlWelcome.asp?welVar=True"
	}else
	{
		javascript:window.opener.location.href = "wlWelcome.asp?welVar=True"
	}	
	self.close()
}

//-->