// JavaScript Document

function getScrollY(idx){
		var formname =document.getElementById(idx);
		var scrollY;
		if (document.all)
    		{
	      	if (!document.documentElement.scrollTop)
        		scrollY = document.body.scrollTop;
      		else
      			scrollY = document.documentElement.scrollTop;
    		}
    	else
    		{
	      scrollY = window.pageYOffset;
		  }
		formname.y.value=scrollY;
	}
	function towherever(y)
	{
		self.scrollTo(0,y);
	}

var runOnLoad = new Array(); // for queuing multiple onLoad event functions
window.onload = function() { for(var i=0; i<runOnLoad.length; i++) runOnLoad[i]() }
// hide dotted :focus outlines when mouse is used
// but NOT when tab key is used
if(document.getElementsByTagName)
for(var i in a = document.getElementsByTagName('a')) {
  a[i].onmousedown = function() {
    this.blur(); // most browsers
    this.hideFocus = true; // ie
    this.style.outline = 'none'; // mozilla
  }
  a[i].onmouseout = a[i].onmouseup = function() {
    this.blur(); // most browsers
    this.hideFocus = false; // ie
    this.style.outline = null; // mozilla
  }
}

function updateImg(id,img){

if(document.getElementById(id)){
document.getElementById(id).style.background='#FFF url('+img+') no-repeat bottom center';
}
}
sfHover = function() {
	var sfEls = document.getElementById("location").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function IsFloat(value){
	var pattern1 = /^(\d+)(\.){0,1}(\d*)$/
	var pattern2 = /^(\d*)(\.){0,1}(\d+)$/
	return pattern1.test(value) || pattern2.test(value);
}

function formatValue(value){
	return Math.round(value*100)/100;
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function IsNumeric(value){
	var validate=/(^\d+$)/
	if ((validate.test(value)) && (value > 0))
		return 0; 
	else
		return 1; 
}
function TextToEntities(strPlainText, blnPartialEncodeOnly) {
    var strPartial  = [];
    var strFull     = [];
    var intP        = 0;
    var intF        = 0;
    var objPartialRegExp = (new RegExp).compile("[\\w\\s]");

    for (var intI=0; intI<strPlainText.length; ++intI) {
        var strChar = strPlainText.charAt(intI);
        var intChar = strChar.charCodeAt(0);

        if (isNaN(intChar)) {
            // IF CHAR FAILED TO DECODE, LEAVE AS CHAR
            strPartial.push(strFull.push(strChar));
        }
        else {
            var strEntity = "&#" + intChar + ";";
            strFull.push(strEntity);
            // IF CHAR WAS [a-zA-Z0-9_ \t] LEAVE AS CHAR, ELSE REPLACE WITH ENTITY
            strPartial.push(objPartialRegExp.test(strChar) ? strChar : strEntity);
        }
    }
    return (blnPartialEncodeOnly ? strPartial.join("") : strFull.join(""));
}

function URLDecode(url) {
	var HEXCHARS = "0123456789ABCDEFabcdef";
	var encoded = url;
	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++;
		}
	} 		
	return plaintext;
}


