function chStyle(v,name) {
    if(v==1){
	document.getElementById(name).style.backgroundColor = '#ffffdd';
	document.getElementById(name).style.color = '#0000dd';
    } else {
	document.getElementById(name).style.backgroundColor = '#ffffff';
	document.getElementById(name).style.color = '#000000';
    }
}

function submitForm(obj, strMode, lngPT, strURL, lngTarget) {
    document.forms[0].hdnPageType.value = lngPT;
    if (strMode !='' && strMode !=' ') { document.forms[0].hdnMode.value = strMode; }
    document.forms[0].action = strURL;
    if (!lngTarget || lngTarget==1) { document.forms[0].target = "_self";
    } else if (lngTarget==2) { document.forms[0].target = "_blank";
    } else if (lngTarget==3) { document.forms[0].target = "_top";
    } else { document.forms[0].target = lngTarget; }
    document.forms[0].submit();
}

function SubmitDualFrame(objSource, strURL, strTarget) {
    objSource.action = strURL;
    objSource.target = strTarget;
    objSource.submit();
}

function GotoURL(strTHISPAGENAME, strState) {
    window.location = strTHISPAGENAME + "?st=" + strState
}

function ShowIt(layer) {
    if (document.getElementById && document.getElementById(layer) !=null) {
	document.getElementById(layer).style.visibility = "visible";
	document.getElementById(layer).style.display="block";
    } else if (document.layers && document.layers[layer] !=null) {
	    alert(document.layers[layer].visibility);
           document.layers[layer].visibility = "visible";
	    document.layers[layer].style.display="block";
    } else if (document.all) {
	document.all[layer].style.zIndex=100;
	document.all[layer].style.display="block";
       document.all[layer].style.visibility = "visible";
    }
}

function HideIt(layer) {
    if (document.getElementById && document.getElementById(layer) !=null) {
	document.getElementById(layer).style.visibility = "hidden";
	document.getElementById(layer).style.display="none";
    } else if (document.layers && document.layers[layer] != null) {
       document.layers[layer].visibility = "hidden";
    } else if (document.all && document.all[layer] != null) {
       document.all[layer].style.visibility = "hidden";
	document.all[layer].style.display="none";
	document.all[layer].style.zIndex = 2;
    } 
}

function clickVisibility(layer, bolOptionalIsShow) {
    //bolOptionalIsShow force one state.
    //0: Hide
    //1: Show

    if (document.getElementById && document.getElementById(layer) !=null) {
	if (bolOptionalIsShow!=null) {
	    if (bolOptionalIsShow==0) {HideIt(layer);}else{ShowIt(layer);}
	} else {
	    if (document.getElementById(layer).style.visibility=="hidden") {
	        ShowIt(layer);} else {HideIt(layer);}
	}
    } else if (document.layers && document.layers[layer] !=null) {
	alert(document.layers[layer].visibility);
	if (bolOptionalIsShow!=null) {
	    if (bolOptionalIsShow==0) {HideIt(layer);}else{ShowIt(layer);}
	} else {
	    if (document.layers[layer].visibility == "hidden") { 
	        ShowIt(layer);} else {HideIt(layer);}
	}
    } else if (document.all && document.all[layer] !=null) {
	if (bolOptionalIsShow!=null) {
	    if (bolOptionalIsShow==0) {HideIt(layer);}else{ShowIt(layer);}
	} else { 
	    if (document.all[layer].style.visibility == "hidden") { 
	        ShowIt(layer);} else {HideIt(layer);}
	}
    }
}

function isVisible(lngLayerCount) {
    lngShow = 0 ;
    lngHide = 0 ;
    for(i=0;i<lngLayerCount;i++) {
	layer = 'L' + i;
        if (document.getElementById && document.getElementById(layer) !=null) {
	    if (document.getElementById(layer).style.visibility=="hidden") {
		lngShow++;
	} else {lngHide++;}
        } else if (document.layers && document.layers[layer] !=null) {
	    if (document.layers[layer].visibility == "hidden") { 
	        lngShow++;} else {lngHide++}
        } else if (document.all && document.all[layer] !=null) {
	    if (document.all[layer].style.visibility == "hidden") { 
	        lngShow++;} else {lngHide++}
        }
    }
    if (lngShow>lngHide) {retVal=0;} else {retVal=1;}
    return retVal;
}

function expand_collapse(lngLayerCount) {
    bolIsVisible = isVisible(lngLayerCount);
    if (bolIsVisible) {lngShow=0;}else{lngShow=1;}
    for(i=0;i<lngLayerCount;i++) {
	clickVisibility('L' + i,lngShow);
    }
}

//Cookie Handling using only Javascript

function getCookieValue(cookieName) {
    var cookieValue = document.cookie;
    var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
 
    if (cookieStartsAt == -1) { cookieStartsAt = cookieValue.indexOf(cookieName +"="); }

    if (cookieStartsAt == -1) { cookieValue = null; 
    } else {
	cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) +1;
	var cookieEndsAt = cookieValue.indexOf(";",cookieStartsAt);
	if (cookieEndsAt == -1) { cookieEndsAt = cookieValue.length; }
	cookieValue = unescape(cookieValue.substring(cookieStartsAt,cookieEndsAt));
    }
    return cookieValue;
}

function setCookie(cookieName, cookieValue, cookiePath, cookieExpires, cookieDomain) {
    var tmp;
    cookieValue = escape(cookieValue);
 
    if (cookieExpires =="") {
	var nowDate = new Date();
	nowDate.setHours(nowDate.getHours()+24);
	cookieExpires = nowDate.toGMTString();
    }
    tmp = cookieName +"=" + cookieValue +"; expires=" + cookieExpires +";path="+cookiePath;
    if (cookieDomain) {
	tmp=tmp+";domain="+cookieDomain;
    }
    document.cookie = tmp;
}

function deleteCookie(cookieName, cookiePath) { 
    cookieExpires = 'Fri, 02-Jan-1970 00:00:00 GMT';  // MAKE IT EXPIRE!
    setCookie(cookieName, '', cookiePath, cookieExpires);
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(!radioLength)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(!radioLength) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
