var newwin;
var isIE6 = isBrowserIE6();

var cSecureDelim1 = "!<>!|!<>!";
var cGlobalDelim = "^~";
var cColDelim = "^|";
var cRowlDelim = "^~";

var PWD_REGEXP = /(?=.*\d)(?=.*[a-z])/i;
var EMAIL_REGEXP = "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9\.{0}])?";
var ALP_REGEXP = "[^a-zA-Z '-]";
var PHONE_REGEXP = "[^0-9]";
var char_invalid = "";
var USERNAME_REGEXP = "[^a-zA-Z0-9@._]";

var DEFAULT_WINDOW_HEIGHT = 500;
var DEFAULT_WINDOW_WIDTH = 950;

// Top value for the footer
var DEFAULT_FOOTER_TOP = 470;
var currentStreetKeyCode = 0;

function ltrim(sInstr)
{
	var sOutStr;
	var ictr;

	sOutStr = sInstr;

	for (ictr = 0; ictr < (sInstr.length); ictr++)
		if (sInstr.charAt(ictr) != ' ') break;

	if (ictr < (sInstr.length))
	    sOutStr = sInstr.substring(ictr,sInstr.length);

	return sOutStr;
}

function rtrim(sInstr)
{
	var sOutStr;
	var ictr;

	sOutStr = sInstr;

	for (ictr = (sInstr.length - 1); ictr >= 0; ictr--)
	{
		if (sInstr.charAt(ictr) != ' ')
			break;
	}

	if (ictr < (sInstr.length - 1))
		sOutStr = sInstr.substring(0, ictr + 1);

	return sOutStr;
}

function trim(sInstr)
{
	var sOutStr;

	sOutStr = ltrim(sInstr);
	sOutStr = rtrim(sOutStr);

	return sOutStr;
}

function textLimit(field, maxlen)
{
    if (field.value.length > maxlen)
    {
        field.value = field.value.substring(0, maxlen);
        alert("Maximum of " + maxlen + " characters allowed.");
    }
}

function checkForProperCase(sText, sProper, sFirstFlag)
{
	var returnValue;

	switch(sProper)
	{
		case "ON":
			returnValue = ConvertProperNew(sText);
			break;

		case "OFF":
			returnValue = sText;
			break;

		case "FIRST":
			if (sFirstFlag == '1')
				returnValue = sText;
			else
				returnValue = ConvertProperNew(sText);
			break;
	}

	return returnValue;
}

function isInputFieldNotEmpty(control)
{
	if (trim(control.value) != ""  && control.value != "null")
	{
		control.className = "err";
		return true;
	}

	control.className = "valid";
	return false;
}

function isInputFieldEmpty(control)
{
	if (trim(control.value) == ""  || control.value == "null")
	{
		control.className = "err";
		return true;
	}

	control.className = "valid";
	return false;
}

function checkFormValidation(formName)
{
	var form = document.getElementById(formName);

	for (var index = 0; index < form.length; index++)
		if (form.elements[index].className == 'err')
			return false;

	return true;
}

function checkField(RegStr, objTextbox, sMessage, isOpp, isSubmission)
{
	if (trim(objTextbox.value) == "" || objTextbox.value == null)
	{
		if (!isSubmission)
		{
			setErrmsg("");
			objTextbox.className = "valid";
		}

		return true;
	}

	if (trim(objTextbox.value.toUpperCase()) == "NOT SUPPLIED" && isSubmission)
	{
		objTextbox.className = "valid";
		return true;
	}

	var regExp = new RegExp(RegStr);

	if ((regExp.test(objTextbox.value) && !isOpp) || (!regExp.test(objTextbox.value) && isOpp))
	{
		objTextbox.className = "err";

		if (isSubmission)
		{
			char_invalid = char_invalid  + sMessage + ",";
		}
		else
		{
			if (sMessage.toUpperCase() == "EMAIL")
				setErrmsg("Email address is invalid.");
			else
				setErrmsg(sMessage + " contains invalid characters.");
        }

		return false;
	}

    // For emails, regular expression fails to check for domain.
    // Unable to determine why, so we'll manyally check for a domain.
    if (sMessage.toUpperCase() == "EMAIL")
    {
        var str = objTextbox.value;
        var lastDotPos = str.lastIndexOf(".");
        var lengthOfLastPart = str.length - lastDotPos - 1;

        if ((lastDotPos < str.lastIndexOf("@")) || (lengthOfLastPart < 2 || lengthOfLastPart > 6))
        {
            objTextbox.className = "err";
            setErrmsg(sMessage + " is invalid.");
            return false;
        }
    }    

	if (!isSubmission)
	    setErrmsg("");

	objTextbox.className = "valid";

	return true;
}

function setErrmsg(msg)
{
	if (msg != "")
	{
		document.getElementById("celErrmsg").innerHTML = msg;
		document.getElementById("divErrmsg").style.display = "";
	}
	else
	{
		document.getElementById("celErrmsg").innerHTML = "";
		document.getElementById("divErrmsg").style.display = "none";
	}
}	
//end of validation functions
	
function launchwint(winurl, winfeatures)
{
	newwin = window.open(winurl, 'newwindow', winfeatures);
}

function display_alt(text, e, display)
{
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;					
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;	
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

	document.getElementById("celText").innerHTML = text;

	var objDisplay = document.getElementById('divAlt');

	if (display)
	{
		objDisplay.style.visibility = "visible";
		objDisplay.style.display = "";
		objDisplay.style.display = "block";
		objDisplay.style.position = "absolute";
		objDisplay.style.top = posy;
		objDisplay.style.left = posx + 10;
	}
	else 
	{
		objDisplay.style.visibility = "hidden";
		objDisplay.style.display = "none";
		objDisplay.style.position = "absolute";
		objDisplay.style.top = posy;
		objDisplay.style.left = posx + 10;
	}
}

function getKeyCode(e)
{
    // this returns keycode in a way that firefox browsers can also read.
	var code = 0;

	if (!e)
	    e = window.event;

    if (e)
    {
	    if (e.keyCode)
	        code = e.keyCode;
	    else if (e.which)
	        code = e.which;
    }

	return code;
}

function setStreetType(keyCode1, keyCode2, streetType, streetTypeAbbr, control)
{
    var num = 0;

    if (currentStreetKeyCode != keyCode1 && currentStreetKeyCode != keyCode2)
        if ((num = setSelectedIndex(streetType, control)) == 0)
            num = setSelectedIndex(streetTypeAbbr, control);

    return num;
}

function streetTypeOnKeyPressEvent(e, control)
{
	var num = 0;
	var keyCode = getKeyCode(e);

	switch (keyCode)
	{
        case 8:
            num = 0;
            break;

        case 65:
        case 97:
            num = setStreetType(65, 97, "AVENUE", "AV", control);
            break;

        case 66:
        case 98:
            num = setStreetType(66, 98, "BOULEVARD", "BVD", control);
			break;

        case 67:
        case 99:
            num = setStreetType(67, 99, "COURT", "CT", control);
			break;

        case 68:
        case 100:
            num = setStreetType(68, 100, "DRIVE", "DR", control);
			break;

        case 69:
        case 101:
            num = setStreetType(69, 101, "ESPLANADE", "ESP", control);
			break;

        case 70:
        case 102:
            num = setStreetType(70, 102, "FAIRWAY", "FAWY", control);
			break;

        case 71:
        case 103:
            num = setStreetType(71, 103, "GROVE", "GR", control);
			break;

        case 72:
        case 104:
            num = setStreetType(72, 104, "HARBOUR", "HRBR", control);
			break;

        case 73:
        case 105:
            num = setStreetType(73, 105, "INLET", "INLT", control);
			break;

        case 74:
        case 106:
            num = setStreetType(74, 106, "JUNCTION", "JNC", control);
			break;

        case 75:
        case 107:
            num = setStreetType(75, 107, "KEY", "KEY", control);
			break;

        case 76:
        case 108:
            num = setStreetType(76, 108, "LANE", "LANE", control);
			break;

        case 77:
        case 109:
            num = setStreetType(77, 109, "MOTORWAY", "MOTORWAY", control);
			break;

        case 78:
        case 110:
            num = setStreetType(78, 110, "NEAVES", "NVS", control);
			break;

        case 79:
        case 111:
            num = setStreetType(79, 111, "OAKS", "OAKS", control);
			break;

        case 80:
        case 112:
            num = setStreetType(80, 112, "PLACE", "PL", control);
			break;

        case 81:
        case 113:
            num = setStreetType(81, 113, "QUAY", "QY", control);
			break;

		case 82:
		case 114:
		    num = setStreetType(82, 114, "ROAD", "RD", control);
            break;

	    case 83:
	    case 115:
	        num = setStreetType(83, 115, "STREET", "ST", control);
			break;

        case 84:
        case 116:
            num = setStreetType(84, 116, "TERRACE", "TCE", control);
			break;

        case 85:
        case 117:
            num = setStreetType(85, 117, "UNDERPASS", "UPAS", control);
			break;

        case 86:
        case 118:
            num = setStreetType(86, 118, "VALE", "VALE", control);
			break;

        case 87:
        case 119:
            num = setStreetType(87, 119, "WAY", "WAY", control);
			break;

        case 89:
        case 121:
            num = setStreetType(89, 121, "YARD", "YARD", control);
			break;

        default:
            break;
	}

    // ignore tab character
    if (keyCode != 9 && num != 0)
    {
        if (isBrowserIE())
            control.selectedIndex = num - 1;
        else
            control.selectedIndex = num
    }

    currentStreetKeyCode = keyCode;
}

function setSelectedIndex(typeName, control)
{
	for (var index = 0; index < control.options.length; index++)
	{
		if (control.options[index].value.toUpperCase() == typeName.toUpperCase())
		{
		    if (isBrowserIE())
			    return index;
			else
			    return index - 1;
	    }
    }

	return 0;
}

function displaySection(displayId, display)
{
	var objDisplay = document.getElementById(displayId);

    if (objDisplay != null)
    {
	    if (display)
	    {
		    objDisplay.style.visibility = "visible";
		    objDisplay.style.display = "";
	    }
	    else
	    {
		    objDisplay.style.visibility = "hidden";
		    objDisplay.style.display = "none";
	    }
    }
}

function getWindowHeight()
{
	if (isBrowserIE())
		return document.documentElement.clientHeight;
	else
		return window.innerHeight;
}

function getWindowWidth()
{
	if (isBrowserIE())
		return document.documentElement.clientWidth;
	else
		return window.innerWidth;
}

function isBrowserIE()
{
    var agt = navigator.userAgent.toLowerCase();
    var is_ie = (agt.indexOf("msie") != -1);

    if (is_ie)
        return true;
    else
        return false;
}

function isBrowserIE6()
{
    return navigator.appVersion.indexOf("MSIE 6.0") > 0;
}


function left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0, n);
}

function right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else 
    {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

//This function checks for the numeric key. In case numeric key then it allows
//the user to type in the Text Box. Decimal is not allowed

function chkKeyNumericNoDecimal(e)
{
	//Code for Netscape
	if (navigator.appName == "Netscape")
	{
	    var KeyCode;

        if (e.charCode)
        {
            KeyCode = e.charCode; // For Gecko
        }
        else
        {
            KeyCode = e.keyCode; // For Presto
        }

        if (e.shiftKey == true && (KeyCode == 37 || KeyCode == 35 || KeyCode == 36 || KeyCode == 40))
			e.preventDefault();

		if (e.shiftKey == true && KeyCode == 38)
			e.preventDefault();

        if (KeyCode != 9)
        {
			if (KeyCode != 37 && KeyCode != 38 && KeyCode != 39 && KeyCode != 40 && KeyCode != 35 && KeyCode != 46 && KeyCode != 8 && KeyCode != 36)
			{
			    if ((KeyCode < 47 || KeyCode > 57) && (KeyCode < 96 || KeyCode > 105))
			    {
			        e.preventDefault();
			    }
		    }
        }
	}
	else
	{
	    //Code for IE	
		if (event.keyCode < 48 || event.keyCode > 57)
		{
			if (event.ctrlKey)
			{
				if (event.keyCode == 67 || event.keyCode == 86 || event.keyCode == 88)
				{
					return true;
				}
				else
				{
					return false;
				}
			}

			if (event.keyCode == 190)
			{
				return false;
			}

			if (event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 96 && event.keyCode != 97 && event.keyCode != 98
			        && event.keyCode != 99 && event.keyCode != 100 && event.keyCode != 101 && event.keyCode != 102 && event.keyCode != 103
			        && event.keyCode != 104 && event.keyCode != 105 && event.keyCode != 9 && event.keyCode != 37 && event.keyCode != 38
			        && event.keyCode != 39 && event.keyCode != 40)
			{
				return false;
			}
		}
		else
		{
			if (event.shiftKey == true && (event.keyCode == 48 || event.keyCode == 49 || event.keyCode == 50 || event.keyCode == 51
			        || event.keyCode == 52 || event.keyCode == 53 || event.keyCode == 54 || event.keyCode == 55 || event.keyCode == 56
			        || event.keyCode == 57 || event.keyCode == 190 || event.keyCode == 191 || event.keyCode == 220))
			{
				return false;
			}
		}
	}

    return true;
}

function isValidDate(sDate)
{
	var sAry;
	var strDay = 0;
	var sMon = 0;
	var	sYea = 0;

	sAry = sDate.split("/");

	if (sAry.length != 3) return false;
	if (ChkNumber(sAry[0]) == false) return false;
	if (ChkNumber(sAry[1]) == false) return false;
	if (ChkNumber(sAry[2]) == false) return false;

	strDay = parseFloat(sAry[0]);
	sMon = parseFloat(sAry[1]);
	sYea = parseFloat(sAry[2]);

	if (sYea.toString().length != 4)
		return false;

	if (strDay == 0)
		return false;

	if ((sMon < 1) || (sMon > 12))
		return false;

    /*Check for 31 days month */
	if (((sMon == 1) || (sMon == 3) || (sMon == 5) || (sMon == 7) || (sMon == 8) || (sMon == 10) || (sMon == 12))&& ((strDay < 1) || (strDay > 31)))
		return false;

    /*Check for 30 days month */
	if (((sMon == 4)||(sMon == 6)||(sMon == 9)||(sMon == 11)) && ((strDay < 1)||(strDay > 30)))
		return false;

	if (sYea % 4 == 0)  /*Check for leap year*/
	{
		if ((sMon == 2) && ((strDay < 1) || (strDay > 29)))
		return false;
	}
	else
	{
		if ((sMon == 2) && ((strDay < 1) || (strDay > 28)))
		return false;
	}

	return true;
}

function ChkNumber(sValue)
{
	sValue = trim(sValue);

	if ((trim(sValue)) == "0")
		return true;

	if (isNaN(parseFloat(sValue)))
	{
		return false;
	}
	else
	{
	    if ((parseFloat(sValue)) == 0)
		    return false;
		else
			return true;
	}
}

function clearSelect(controlName)
{
    var oSelect = document.getElementById(controlName);

    while (oSelect.length > 0)
        oSelect.remove(0);
}

function createOption(controlName, value, text)
{
    var oSelect = document.getElementById(controlName);
    var oOption = document.createElement("option");

    oOption.text = text;
    oOption.value = value;

    try
    {
        // standards compliant
        oSelect.add(oOption, null);
    }
    catch(ex)
    {
        // IE only
        oSelect.add(oOption);
    }
}

function SetSelectedComboEntry(control, value, isCheckIndex)
{
	if (value == null)
		return;

	for (var index = 0; index < control.length; index++)
	{
		if (isCheckIndex)
		{
			if (control.options[index].value.toLowerCase().indexOf(value.toLowerCase()) >= 0)
			{
				control.selectedIndex = index;
				index = control.length;
			}
		}
		else
		{
			if (control.options[index].value.toLowerCase() == value.toLowerCase())
			{
				control.selectedIndex = index;
				index = control.length;
			}
		}
	}
}

function convertProper(text)
{
	text = trim(text);

	if (text == "")
		return text;

	var iCnt = 0;
	var iTmp = 0;
	var sTmp = "";
	var proper = "";

	for (index = 0; index < text.length; index++)
	{
		//Get characters
		sTmp = new String(text.substr(index, 1));

		if (iTmp == 1 || index == 0)
		{
			sTmp = sTmp.toUpperCase();
			iTmp = 0;
		}
		else
		{
			sTmp = sTmp.toLowerCase();
		}

		if (sTmp == " ")
		   iTmp = 1;

		proper += sTmp;
		sTmp = "";
	}

	return proper;
}

function removeTableRows(table, rowsToKeep)
{
    if (table != null)
    {
        var rows = table.rows;

        while (rows.length > rowsToKeep)
            table.deleteRow(rows.length - 1);
    }
}

/*	
    This function checks for invalid characters
	Parameter iCheckConst can be 1 ot 4
	1-Numeric including decimal values
	2-Alphabet
	3-AlphaNumeric
	4-Email Address  
	5-Numeric with dot and sign
	6-Numeric but no decimal values
	7-Numeric with dot but no sign 
	8-Alphabet with dot .
	9-AlphaNumeric with dot . and brackets ( )
	10-Phone Numeric with Extension character(/)
	11-For numeric with dash and space 
	12-For alphanumeric with dot . and single quote ' and brackets ( )
	13-Alphabet with ' for suburbs
	14-Alphabet without forward slash \ and double quote "
*/

function ifValidChars(sText, iCheckConst)
{
    sText = trim(sText);

    if (sText == "")
        return false;

    switch(iCheckConst)
    {
        case 1:
		    sValidChars = "1234567890.-";

		    for (i = 0; i < sText.length; i++)
		    {
		        sChar = sText.charAt(i);

		        if (sValidChars.indexOf(sChar, 0) < 0)
			      return false;
		    }

		    if  (sText == ".")
			    return false;
		    else
    			return true;

        case 2:
		    sUpperCase = sText.toUpperCase();

		    for (i = 0; i < sUpperCase.length; i++)
		    {
			    sCharCode = sUpperCase.charCodeAt(i);

			    if (((sCharCode < 65) || (sCharCode > 90)) && (sCharCode != 32))
			         return false;
		    }

		    return true;

        case 3:
		    sUpperCase = sText.toUpperCase()
	        for(i=0;i<sUpperCase.length;i++)
		    {
			    sCharCode = sUpperCase.charCodeAt(i)
			    if((sCharCode < 65) || (sCharCode > 90))
			    {
			         if(((sCharCode < 48) ||(sCharCode > 57)) && (sCharCode !=46) && (sCharCode!=32) && (sCharCode!=95) && (sCharCode!=47  && (sCharCode!=45))){
			         return false; }
	            } 
	        }    		  
	        return true; 
      case 4:				/* For e-mail */
		    sUpperCase = sText.toUpperCase() /* Convert to upper case */
	        for(i=0;i<sUpperCase.length;i++) /*For checking of invalid characters */
		    {
			    sCharCode = sUpperCase.charCodeAt(i)
			    if((sCharCode < 64) || (sCharCode > 90))
			    {
			         if(((sCharCode < 48) ||(sCharCode > 57)) && (sCharCode !=45) && (sCharCode !=46) && (sCharCode != 95)){
			         return false; }
	            } 
	        }    		  
		    iPos = sText.indexOf("@",1)
		    if (iPos == -1 ){    /*Checking for @ existance */
		      return false;}
		    if (sText.indexOf("@",iPos+1) != -1){  /*Checking for multiple @ existance */
		      return false;}
		     //Changed for "." validation
		     iPos = sText.indexOf(".",iPos)
		     if (iPos == -1 ){    /*Checking for . existance */
		      return false;} 
		    return true;
      case 5:                 /* For numeric with sign*/
		    sValidChars = "1234567890.-+"
		    for(i=0;i<sText.length;i++)
		    { 
		         sChar = sText.charAt(i)
		         if(sValidChars.indexOf(sChar,0)< 0){
			          return false ;}
		    }						
		    if (isNaN(sText))
			    return false;
    		
		    return true;
      case 6:                 /* For numeric no decimal allowed */
		    sValidChars = "1234567890"
		    for(i=0;i<sText.length;i++)
		    { 
		         sChar = sText.charAt(i)
		         if(sValidChars.indexOf(sChar,0)< 0){
			          return false ;}
		    }
		    return true;
      case 7:                /*For numeric-dot but no sign*/
		    sValidChars = "1234567890."
		    for(i=0;i<sText.length;i++)
		    { 
		         sChar = sText.charAt(i)
		         if(sValidChars.indexOf(sChar,0)< 0){
			          return false ;}
		    }
		    if(sText.indexOf(".") != sText.lastIndexOf("."))
			    return false;
		    if(sText.charAt(sText.length - 1) == ".")
			    return false;
		    return true;
      case 8:                 /* For alphabet with dot . */
		    sUpperCase = sText.toUpperCase()
		    for(i=0;i<sUpperCase.length;i++)
		    {
			    sCharCode = sUpperCase.charCodeAt(i)
			    if ((sCharCode != 46) && (sCharCode != 190))
			    {
				    if(((sCharCode < 65) || (sCharCode > 90)) && (sCharCode!=32)){
					     return false; }
			    }
		    } 		  
		    return true;
     case 9:				 /* For alphanumeric with dot . and brackets ( ) */
		    sUpperCase = sText.toUpperCase()
	        for(i=0;i<sUpperCase.length;i++)
		    {
			    sCharCode = sUpperCase.charCodeAt(i)	
			    if((sCharCode != 40) && (sCharCode != 41))
			    {
				    if((sCharCode < 65) || (sCharCode > 90))
				    {
				         if(((sCharCode < 48) ||(sCharCode > 57)) && (sCharCode!=46) && (sCharCode!=190) && (sCharCode!=32) && (sCharCode!=95) && ((sCharCode!=47) && (sCharCode!=45))){
				         return false; }
				    } 
			    }
	        }    		  
	        return true; 
     case 10:                 /* For numeric + "/" */
		    sValidChars = "1234567890/"
		    for(i=0;i<sText.length;i++)
		    { 
		         sChar = sText.charAt(i)
		         if(sValidChars.indexOf(sChar,0)< 0){
			          return false ;}
		    }
		    return true;
     case 11:                 /* For numeric with dash and space */
		    sValidChars = "1234567890.- "
		    for(i=0;i<sText.length;i++)
		    { 
		         sChar = sText.charAt(i)
		         if(sValidChars.indexOf(sChar,0)< 0){
			          return false ;}
		    }

		    if(sText==".")
			    return false;
		    else
			    return true;
     case 12:				 /* For alphanumeric with dot . and single quote ' and brackets ( ) */
		    sUpperCase = sText.toUpperCase()
	        for(i=0;i<sUpperCase.length;i++)
		    {
			    sCharCode = sUpperCase.charCodeAt(i)	
    			
			    if((sCharCode != 40) && (sCharCode != 41) && (sCharCode != 39))
			    {
				    if((sCharCode < 65) || (sCharCode > 90))
				    {
				         if(((sCharCode < 48) ||(sCharCode > 57)) && (sCharCode!=46) && (sCharCode!=190) && (sCharCode!=32) && (sCharCode!=95) && ((sCharCode!=47) && (sCharCode!=45))){
				         return false; }
				    } 
			    }
	        }    		  
	        return true;
    case 13:		//Alphabet with ' for suburbs
		    sUpperCase = sText.toUpperCase()
		    for(i=0;i<sUpperCase.length;i++)
		    {
			    sCharCode = sUpperCase.charCodeAt(i)
			    if(((sCharCode < 65) || (sCharCode > 90))&&(sCharCode!=32)&&(sCharCode!=39)){
			         return false; }
		    } 		  
		    return true;
    case 14:		//Alphabet without forward slash \ and double quote "
		    if (sText.indexOf("\\") >= 0)
			    return false;
		    if (chkDoubleQuotes(sText) == true)
			    return false;
		    return true;
    default:
		    return false;
    }		
}

function submitFormWithKey(evt)
{
	var keycode;

	if (window.event)
		keycode = window.event.keyCode;
	else if (evt)
		keycode = evt.which;
	else
		return true;

    // F8
    if (keycode == 119)
    {
        goBack();
    }

    // F12
	if (keycode == 123)
	{
		if (!submitform())
			return false;
	}

	return true;
}

//The following are the constants to specify the help message for each panel.
var cCustomerDetailsPanelTip = "Please confirm that your contact details are correct. If you need to modify this information, to ensure Asset Owners can contact you, please use User Profile section to make appropriate changes.";
var cCustomerConfirmationTip = "Ensure that the address shown below is correct, as this will be the same email we will send a confirmation of your enquiry.";
var cEnquiryDetailsTip = "1) Provide a start date for your project - remember asset owners require at least 2 days notice in order to prepare plans and send your information.<br>2) Define the purpose of your works, please note that some asset owners will respond differently to your selected Purpose.<br>3) Define the principle activity you are to carry out<br>4) Describe the Location of the Workplace.<br>Please ensure the details you provide are an accurate reflection of  your planned activity.";
var cForgottenPasswordTip = 'Enter your username into the box provided below and press "send password". Your password will be sent to your selected email address. Your username will most likely be your email address.';
var cSummaryDetailsTip = "Please take note of your job number, this number is unique to your job and can be referenced to Utilities when chasing up the delivery of your plans and information. You will receive an enquiry confirmation via email or fax which will also detail the job number and summarise your enquiry.";
var cConfirmLocationonMapTip= "The location searched on the previous screen should now be visible. Use the mapping tools below to navigate to your job site. In addition, a number of drawing tools are also provided to help design your site so that Asset Owners are able to respond with accurate plans and information.";
var cMapScreenLocationTip = "The address below is the location we have found in our database. If this does not match  your desired location or selected work design on the map, please update the address in this box by selecting the Edit button and entering an address that best describes your work site.";
var cNotesOfWorksTip = "Please provide any additional work site information to aid asset owners in responding to your enquiry with appropriate plans. This could include a description of any features in the vacinity of the work or any other particulars like, work is close to an intersection or a train station etc...";
var cNotesOfWorksEnquriySettingTip
var cCustomerAcceptanceTip = "By clicking in the confirm box,  you have confirmed that the information you have provided is accurate and correctly describes your proposed work site.";
var cEmergencyContactsTip = "The 'Emergency Contacts' option helps to view all registered asset owners in a specified region. Click 'Emergency Contacts' on DigSAFE OneCall 'Login' screen. The 'Emergency Contacts' screen, shown below, should be displayed. Notice that there are three options available in the interface. You can either specify a combination of Suburb and State, or alternatively you can specify the Postcode for the desired region, and then click 'Show Utilities'. A list of registered Utilities should be displayed.";
var cEmergencySearchTip = "The 'Emergency Contacts' option helps to view all registered asset owners in a specified region. Click 'Emergency Contacts' on DigSAFE OneCall 'Login' screen. The 'Emergency Contacts' screen, shown below, should be displayed. Notice that there are three options available in the interface. You can either specify a combination of Suburb and State, or alternatively you can specify the Postcode for the desired region, and then click 'Show Utilities'. A list of registered Utilities should be displayed.";
var cEmergencySearchResultsTip = "The 'Emergency Contacts' option helps to view all registered asset owners in a specified region. Click 'Emergency Contacts' on DigSAFE OneCall 'Login' screen. The 'Emergency Contacts' screen, shown below, should be displayed. Notice that there are three options available in the interface. You can either specify a combination of Suburb and State, or alternatively you can specify the Postcode for the desired region, and then click 'Show Utilities'. A list of registered Utilities should be displayed.";
var cMultipleSuburbsFound = "If the entered search location does not match completely with our database you will see this message. Please make sure that our suggestion matches your desired location before proceeding with your enquiry. If you need to change the search, you can simply update the details in the search panel and click next.";
var cCloseMatchFoundTip = "If the entered search location does not match completely with our database you will see this message. Please make sure that our suggestion matches your desired location before proceeding with your enquiry. If you need to change the search, you can simply update the details in the search panel and click next."
var cUserHistoryFiltersTip = "Search for previous enquiries by entering either an exact job number or by using the operators to find the job you were looking for. This section also allows you to search for jobs entered by you or by the call centre between dates or by selecting the town/suburb of your original enquiry.";
var cHistorySearchResultsTip = "Once your selection is made a list of your found results will be displayed. To find more details on the enquiry and see a view of the asset owners notified select the view link.";
var cCustomerInformationTip = "Below are the contact details as provided at the time of the enquiry. ";
var cEnquirySummaryDetailsTip = "The details shown describe the location and details of the enquiry submitted.";
var cEnquirySummaryDetailsTipPostClick = "The details shown describe the location and details of the original enquiry submitted. Fields such as Start Date, Purpose, Onsite Activity, Workplace and Enquiry notes can be edited as necessary before resubmitting a new enquiry."
var cEnquirySummaryUtilitiesListTip = "The list of Utilities provided were notified of your enquiry.";
var cEnquirySettingsTip = "By pre-setting your Enquiry Settings you save some time when submitting an enquiry. If you regularly perform the same basic job then you can quickly move through the enquiry process";
var cNotesOfWorksEnquriySettingTip = "As with enquiry settings, you can also set up notes you would like to deliver to all asset owners with your responses.";
var cCustomerProfileDetailsTip = "Provide your prefered name, company and job position.";
var cContactDetailsTip = "Asset owners can provide responses in a number of formats including email, fax and by mail. To ensure that you receive all responses from asset owners it is important that your contact information is updated.";
var cSurveyTip = "cSurveyTip";
var cLoginDetailsTip = "Choose your own username and password. We recommend using your email address as your user name. If you are sharing your login details with multiple people within your organisation it is important to ensure that the contact details are common to all individuals using the service. This will enable asset owners to provide responses to a single location.";
var cSecurityTip = "This is only important when you have forgotten your username or password. Select from the list of options and enter your answer, importantly ensure you select a security question that you help  you remember your password.";
var cMapScreenLocationEidtTip = "The address below is the location we have found in our database. If this does not match  your desired location or selected work design on the map, please update the address in this box by selecting the Edit button and entering an address that best describes your work site.";
var cLocationOfStreetSearchTip = 'To help find a location, chose from one of the search methods. If you are not able to find a location using the default "street" search then chose a different search to help get you close to your intended site. Remember; you can redefine your required location on the map screen. Your options are:<br>(1) Street Address - If you are working in confined or small site this search will take you straight there<br>(2) Street Intersection - Is a useful search if you know the intersection or a working within the street intersection<br>(3) Suburb - if your work site is a large area searching for a suburb will enable you to view a larger map and define your work site using the map tools on the next page<br>(4) Grid Search - Use a map grid to locate the map at a high zoom to then enable you to refine your work site using the map tools provided on the next page<br>(5) Coordinate Search - If you have coordinate information (in decimal degrees) this search will get you exactly to that selected location.';

var cLocationOfStreetSearchTipForXY = "Coordinate Search - If you have X and Y coordinate information this search will get you exactly to that selected location. The Digsafe OneCall system uses Latitude/Longitude as its primary coordinate system and GDA94 as its Datum.<br /><br />"
                                        + "Note: The XY Search does not support input of Degree's Minutes and Seconds. Users of GPS Systems will need to convert to decimal degrees to use search method successfully.";

var cLocationOfStreetSearchTipForGrid = "Grid Search - allows you to identify a location based on a street directory map reference.  The following digital street directory versions are supported in each state; <br /><br />"
                                            + "ACT - UBD Canberra Ed 14, Penguin Ed 1<br/>"
                                            + "NSW - UBD Sydney Ed 45, Newcastle Ed 20, Central Coast Ed 18, Wollongong Ed 19, Penguin Ed 1<br/>"
                                            + "NT - UBD Dar Ed 5, NT Topographic<br/>"
                                            + "QLD - UBD Brisbane, Gold Coast & Sunshine Coast Ed 52, State Grid<br/>"
                                            + "SA - UBD Adelaide Ed 47, SA Topographic<br/>"
                                            + "TAS - Tas Street Atlas Ed 6, TasMap<br/>"
                                            + "VIC - Melways Edition 36, VICRoad Edition 4<br/>"
                                            + "WA - StreetSmart Ed 48, Travellers Atlas Ed 8";
var cLocationOfIntersectionTip = "cLocationOfIntersectionTip";
var cLocationOfSuburbSearchTip = "cLocationOfSuburbSearchTip";
var cLocationOfGridSearchTip = "cLocationOfGridSearchTip";
var cLocationOfXYSearchTip = "cLocationOfXYSearchTip";
var cAddressDetailsTip = "Your address information is important and helps asset owners to mail responses if required. Please ensure you keep this information as current as possible. You have the opportunity to change this information at any stage after you have registered.";
var cSummaryUtilitiesListTip = "The following list of asset owners has been notified of your works and should respond within 48 hours. This list will also be delivered with your enquiry confirmation should you wish to follow each asset owner up individually.";
var cUtilitiesListTip;
//This function to show the help tips for panels
//sTipContent is the messages shown in the div.
//If set onTheRightSide as true, the tip div will be shown on the right hand side of the mouse clicking position
function showTips(sTipContent, evt, onTheRightSide, heightForIFrameFix)
{
    hideTips();

    var xPosition,yPosition;
    var ev;
    var theTop, offSet;

    if (document.documentElement && document.documentElement.scrollTop)
        theTop = document.documentElement.scrollTop;
    else
        theTop = document.body.scrollTop;

    if (onTheRightSide)
        offSet = -20;
    else
        offSet = parseInt(document.getElementById("divTip").style.width) + 20;

    ev = evt || window.event;

    if (ev.pageX || ev.pageY)
    {
        xPosition = evt.pageX - offSet;
        yPosition = evt.pageY;
    }
    else
    {
        xPosition = ev.clientX + document.body.scrollLeft - document.body.clientLeft - offSet;
        yPosition = ev.clientY + theTop;
    }

    document.getElementById("divTip").style.left = xPosition + "px";
    document.getElementById("divTip").style.top = yPosition + "px";

    document.getElementById("divTipContent").innerHTML = sTipContent;
    document.getElementById("divTip").style.display = "";

    if (heightForIFrameFix > 0)
        dropDownFixForIE6(xPosition, yPosition, heightForIFrameFix);
}

function dropDownFixForIE6(x, y, height)
{
    if (isIE6)
    {
        y += 5;

        document.getElementById("ifraBlank").style.left = x + "px";
        document.getElementById("ifraBlank").style.top = y + "px";
        document.getElementById("ifraBlank").style.display = "";
        document.getElementById("ifraBlank").style.height = height + "px";
    }
}

//This function is to hide the help tip div.
function hideTips()
{
    document.getElementById("divTip").style.display = "none";
    
    if (document.getElementById("ifraBlank") && isIE6)
        document.getElementById("ifraBlank").style.display = "none";
}

function check_match(src, target, sMessage, isSubmission)
{
	if (src != null && target != null)
	{
		if (src.value.toLowerCase() != target.value.toLowerCase())
		{
			src.className = "err";
			target.className = "err";

			if (!isSubmission)
			    setErrmsg(sMessage + " don\'t match.");

			return false;
		}

		src.className = "valid";
		target.className = "valid";	

		if (!isSubmission)
		    setErrmsg("");

		return true;
	}
}

function select_OnChange(control, sMessage)
{
	if (control.value == "null" || control.value == "")
	{
		control.className = "err";
		setErrmsg("Please specify " + sMessage);
	}
	else
	{
		control.className = "valid";
		setErrmsg("");
	}
}

function returnToNonTicket(formObject)
{
    formObject.action = "../ReturnToNonTicket.asp";
    formObject.submit();
}

function getRadioButtonValue(control)
{
    var value = "";

    for (var index = control.length - 1; index > -1; index--)
    {
        if (control[index].checked)
            value = control[index].value;
    }

    return value;
}

function setRadioButtonClass(control, cl)
{
    for (var index = control.length - 1; index > -1; index--)
        value = control[index].className = cl;
}

function ConvertProperNew(sText)
{
	sText = trim(sText);

	if (sText == "")
	    return sText;

	var iCnt = 0, iTmp = 0, sTmp = "", sProper = "";

	for (iCnt = 0; iCnt < sText.length; iCnt++)
	{
		//Get characters
		sTmp = new String(sText.substr(iCnt, 1));

		if ((iTmp == 1 && sTmp != " ") || (iCnt == 0))
		{
			sTmp = sTmp.toUpperCase();
			iTmp = 0;
		}
		else
			sTmp = sTmp.toLowerCase();

		if (sTmp	== "." || sTmp == "'" || sTmp == " ")
			iTmp = 1;

		sProper = sProper + sTmp;
		sTmp = "";
	}

	return sProper;
}

function fillInSelectedStreet(streetRecord)
{
	var street = streetRecord[0].split(" ");
	var streetNo = "";
	var streetName = "";
	var streetIndex = 0;

    // Handle existence of street number.
    if (street.length == 3)
	{
	    streetNo = trim(street[0]);
	    streetIndex = 1;
	}

    for (var index = streetIndex; index < street.length - 1; index++)
	    streetName = convertProper(trim(streetName + " " + trim(street[index])));

    if (trim(streetNo) != "")
        document.getElementById("StreetNo").value = streetNo;

    streetName = streetName.replace(',', '');
    document.getElementById("StreetName").value = streetName;

	SetSelectedComboEntry(document.getElementById("StreetType"), street[street.length - 1]);

	document.getElementById("Suburb").value = convertProper(trim(streetRecord[1]));
	document.getElementById("Postcode").value = trim(streetRecord[6]);
	SetSelectedComboEntry(document.getElementById("Postcode"), trim(streetRecord[5]));
}

function hideLoading()
{
    displaySection("waitcursor", false);
}

function showLoading()
{
    setWaitCursorPos();
    displaySection("waitcursor", true);
}

function setWaitCursorPos(formName)
{
    var dForm = document.getElementById(formName);
    var dLoading = document.getElementById("waitcursor");
    var windowHeight = getWindowHeight() - 10;
    var windowWidth = getWindowWidth() - 10;
    
    if (windowHeight < DEFAULT_WINDOW_HEIGHT)
        windowHeight = DEFAULT_WINDOW_HEIGHT;

    if (windowWidth < DEFAULT_WINDOW_WIDTH)
        windowWidth = DEFAULT_WINDOW_WIDTH;

    dLoading.style.height = windowHeight + "px";
    dLoading.style.width = windowWidth + "px";

    dLoading.style.top = "5px";
    dLoading.style.left = "5px";
    
    var imgLoad = document.getElementById("loadingImg");

    // Centre graphic in viewport
    // image size is 170x48.
    imgLoad.style.top = ((windowHeight - 48)  / 2) + "px";
    imgLoad.style.left = ((windowWidth - 170) / 2) + "px";
}

// Convert the passed in date value into a Date type
function getDateFromString(rawDate)
{
	var date = rawDate.split("/");
	return new Date(date[2], (date[1]) - 1, date[0]);
}

// Compares two dates.  Returns false if dateOne is earlier than dateTwo
function compareDates(dateOne, dateTwo)
{
    var dateOneAsDate = getDateFromString(dateOne);
    var dateTwoAsDate = getDateFromString(dateTwo);

    if (dateOneAsDate.setHours(0, 0, 0, 0) < dateTwoAsDate.setHours(0, 0, 0, 0))
        return false;
    else
        return true;   
}

function disableTab(evt)
{
    if (getKeyCode(evt) == 9)
        return false;
    else
        return true;
}

function isPanelShowing(panel)
{
    return document.getElementById(panel).style.display != "none";
}

function pageHasError()
{
    if (trim(document.getElementById("divErrmsg").style.display) == "none")
        return false;

    return true;
}

function setErrorPanelTitle(title)
{
    document.getElementById("celErrmsgTitle").innerHTML = title;

    if (trim(title) == "")
        document.getElementById("celErrmsgTitle").style.height = "15px";
}

function getRandomNum(lbound, ubound)
{
     return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandomChar(number, alpha, other, extra) 
{
    var numberChars = "0123456789";
    var alphaChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    // Binary characters have been remobed.  We won't be needing them.
    var binaryChars = "";
    var moreBinChars = "";
    var otherChars = binaryChars + moreBinChars;
    var charSet = extra;

    if (number)
        charSet += numberChars;

    if (alpha)
        charSet += alphaChars;

    if (other)
        charSet += otherChars;

    return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword(length, extraChars, firstNumber, firstAlpha, firstOther, latterNumber, latterAlpha, latterOther)
{
    var pass = "";
    length++;

    if (length > 0)
        pass += getRandomChar(firstNumber, firstAlpha, firstOther, extraChars);

    for (var idx = 1; idx < length; ++idx) 
        pass = pass + getRandomChar(latterNumber, latterAlpha, latterOther, extraChars);

    // If password does not contain a number, force it to add one.
    if (!hasNumber(pass))
        pass = pass + getRandomChar(true, false, false, "");

     return pass;
}

function hasNumber(stringToCheck)
{
    return /\d/.test(stringToCheck);
}

function setCursorToEndOfText(control)
{
    if (control.createTextRange)
    {
        var r = control.createTextRange();
        r.collapse(false);
        r.select();
    }
}
/* This function convert string into proper string in customer profile screen
 so that word after "'" or "_" should be uppercased */
function convertProperCustProfile(sText)
{
	sText = trim(sText);

	if (sText == "")
		return sText;

	var iTmp = 0;
	var sTmp = "";
	var sProper = "";

	for (var iCnt = 0; iCnt < sText.length; iCnt++)
	{
		sTmp = new String(sText.substr(iCnt, 1));

		if (iTmp == 1 || iCnt == 0)
		{
			sTmp = sTmp.toUpperCase();
			iTmp = 0;
		}
		else
		{
			sTmp = sTmp.toLowerCase();
		}

		if (sTmp	== "'" || sTmp	== "_" || sTmp	== "-")
		   iTmp = 1;

		sProper = sProper + sTmp;
		sTmp = "";
	}

	return sProper;
}

function characterCountDown(control, limit, target)
{
    target.innerHTML = limit - control.value.length;
}