var s_ProjectPath = "";

function isDefined(variable)
{
	return (!(!(document.getElementById(variable))))
}

function URLEncode(EncodeTarget)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	
	var encoded = "";
	
	for (var i = 0; i < EncodeTarget.length; i++ ) {
		var ch = EncodeTarget.charAt(i);
		
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
    
	return encoded;
};

function URLDecode(DecodeTarget)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = DecodeTarget;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   //document.URLForm.F1.value = plaintext;
   return plaintext;
};

function URLSEOEncode(EncodeTarget){
	var encoded = "";
	
	for (var i = 0; i < EncodeTarget.length; i++ ) {
		var ch = EncodeTarget.charAt(i);
		
	    if (ch == " ") {
		    encoded += "_";	
		} else if (ch == "/"){
			encoded += "_(and)_";
		} else if (ch == "&"){
			encoded += "((and))";
		} else {
		    encoded += ch;
		} 
	} // for
    
	return encoded;
};

function URLPartRemoveSpecialCharacters(EncodeTarget){
	var s_Result = EncodeTarget;
	
	s_Result = ReplaceFull(s_Result,"/","");
	s_Result = ReplaceFull(s_Result,"&","");
	s_Result = ReplaceFull(s_Result,"'","");

	return s_Result;
}

function ReplaceFull(Haystack,Needle,NewNeedle){
	while(Haystack.indexOf(Needle)!=-1)
	{
		Haystack = Haystack.replace(Needle, NewNeedle);
	}
	return Haystack;
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	//window.status = characterCode;

	if(characterCode != 13){ //if generated character code is equal to ascii 13 (if enter key)
		return false ;
	}
	else{
		return true;
	}
}

function GetWordForNumber(iValue){
	var s_Result = "";
	var s_Words = "zero,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty";
	var a_Words = s_Words.split(",");
	
	if(iValue<a_Words.length){
		s_Result = a_Words[iValue];
	}
	else
	{
		s_Result = iValue;
	}
	return s_Result;
}


  /*********************************************************************************/
  function ltrim(strTmp) {
     var strlen, cptr, lpflag, chk;
  if (strTmp != "") {
      strlen = strTmp.length;
      cptr = 0;
      lpflag = true;
      do {
        chk = strTmp.charAt(cptr);
        if (chk != " ")
          lpflag = false;
        else {
          if (cptr == strlen)
            lpflag = false;
          else
            cptr++;
        }
      } while (lpflag == true);
      if (cptr > 0)
        strTmp = strTmp.substring(cptr, strlen);
    }
    return (strTmp);
  }
  /*********************************************************************************/
  function rtrim(strTmp) {
    var strlen, cptr, lpflag, chk;
    if (strTmp != "") {
      strlen = strTmp.length;
      cptr = strlen;
      lpflag = true;
      do {
        chk = strTmp.charAt(cptr-1);
        if (chk != " ")
          lpflag = false;
        else {
          if (cptr == 0)
            lpflag = False;
          else
            cptr--;
        }
      } while (lpflag == true);
      if (cptr < strlen)
        strTmp = strTmp.substring(0,cptr);
    }
    return (strTmp);
  }
  /*********************************************************************************/
  function trim (strTmp) {
    return ltrim(rtrim(strTmp));
  }
  /*********************************************************************************/
  function left(strVal, iEnd, iNumChars) {
    var k;
    var iStart;
    var sTmp = "";
    sTmp = strVal;
    if (iEnd < 0) iEnd = 0;
    if (iEnd >= sTmp.length) iEnd = sTmp.length-1;
    iStart = iEnd - iNumChars;
    if (iStart < 0) iStart = 0;
    if (iStart > iEnd) iStart = iEnd;
    sTmp = "";
    for (k = iStart; k <= iEnd; k++)
      sTmp += strVal.charAt(k);
    return(sTmp);
  }
  /*********************************************************************************/
  function right(strVal, iStart, iNumChars) {
    var k;
    var iEnd;
    var sTmp = "";
    sTmp = strVal;
    if (iStart < 0) iStart = sTmp.length-1;    // Start at end if negative
    if (iStart >= sTmp.length) iStart = sTmp.length-1;
    iEnd = iStart + iNumChars;
    if (iEnd >= sTmp.length) iEnd = sTmp.length-1;
    if (iEnd < iStart) iEnd = iStart;
    sTmp = "";
    for (k = iStart; k <= iEnd; k++)
      sTmp += strVal.charAt(k);
    return(sTmp);
  }
  /*********************************************************************************/
  function cint(chrVal) {
    if (chrVal == '0') return(0);
    if (chrVal == '1') return(1);
    if (chrVal == '2') return(2);
    if (chrVal == '3') return(3);
    if (chrVal == '4') return(4);
    if (chrVal == '5') return(5);
    if (chrVal == '6') return(6);
    if (chrVal == '7') return(7);
    if (chrVal == '8') return(8);
    if (chrVal == '9') return(9);
    // Should never get here, but oh well
    return(0);
}
  /*********************************************************************************/
  function isTextFieldEmpty (txtField) {
    if ((txtField == null) || (txtField == "") || (txtField.length <= 0))
      return (true);
    else
      return (false);
  }
  /*********************************************************************************/
  function checkString (txtField) {
    var k, strTmp;
    strTmp = txtField;
    k = strTmp.indexOf("'");
    while (k >= 0) {
      strTmp = strTmp.substr(0, k + 1) + "'" + strTmp.substr(k + 1)
      k = strTmp.indexOf("'", k+2);
    }
    return (strTmp);
  }
  
  
function JSTrim(sSource){
	var	sSource = sSource.replace(/^\s\s*/, ''),
		sWhiteSpace = /\s/,
		iLength = sSource.length;
	while (sWhiteSpace.test(sSource.charAt(--iLength)));
	return sSource.slice(0, iLength + 1);
}

function JSRemoveWhitespace(sSource){
	return ReplaceFull(sSource," ","");
}

function JSIsNumeric(sText)
{
	var ValidChars = "0123456789.-";
	var IsNumber = true;
	var Char;
	for (i = 0; i > sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function JSCheckEmailAddress(emailAddr) {
	invalidChars = " /:,;%^&!";
	for (i=0; i < invalidChars.length; i++) {
		badChar = invalidChars.charAt(i);
		if (emailAddr.indexOf(badChar,0) != -1)
		return (false);
	}
	atPos = emailAddr.indexOf("@", 1);
	if (atPos == -1)
		return (false);
	if (emailAddr.indexOf("@", atPos+1) != -1)
		return (false);
	periodPos = emailAddr.indexOf(".", atPos + 2)
	if (periodPos == -1)
		return (false);
	if (periodPos+2 >= emailAddr.length)
		return (false);
	return (true);
}

function ResizePopup(TargetElement){
	
	var o_Container = document.getElementById(TargetElement);
	if(o_Container){
		iWidth = document.documentElement.clientWidth; 
		iHeight = document.documentElement.clientHeight; 
		iWidth = o_Container.offsetWidth - iWidth; 
		iHeight = o_Container.offsetHeight - iHeight;
		window.resizeBy(iWidth,iHeight);
	}
}