
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function getCSS(a,b) {
	var theSheet=Get_Cookie(a);
	if(theSheet){
    	document.write('<LINK rel="stylesheet" type="text/css" href="' + theSheet + '">');
	} else {
		document.write('<LINK rel="stylesheet" type="text/css" href="' + b + '">');
	}	
}

function setCSS(c, theStyle) {
	Set_Cookie(c, theStyle ,expires,"/");
	top.location.reload();
}

function changeFont(theSelect) {
	var theSheet='Assets/style_sheets/'+theSelect.value+'.css';
	Set_Cookie(theSelect.name, theSelect.selectedIndex,expires,"/");
	setCSS(theSelect.name+"CSS", theSheet);
	return;
}

function replace(string,text,by) {
// Replaces text with by in string
    var i = string.indexOf(text);
    var newstr = '';
    if ((!i) || (i == -1)) return string;
    newstr += string.substring(0,i) + by;

    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);
    
    return newstr;
}

function onCheck(string) {
	if (string == "on") 
		return true; 
	return false; 
}

function getValue(string,elementName,object,elementType) {
// gets value of elementName from string and populates object of elementType

	if(!object) {
		alert ("object is null.");
		return false;
	}
    var startPos = string.indexOf(elementName + "=")
    
    if (startPos > -1) {
        startPos = startPos + elementName.length + 1;
        var endPos = string.indexOf("&",startPos);
        if (endPos == -1) endPos = string.length;

        var elementValue = unescape(string.substring(startPos,endPos));
        
        if ((elementType == "text")||(elementType=="password")||(elementType=="hidden"))     object.value = elementValue;
        if (elementType == "select")   object.selectedIndex = elementValue;
        if (elementType == "checkbox") {
			object.checked = onCheck(elementValue);
		}
        if ((elementType == "radio")&& isFinite(elementValue)) {
			//var myText = "setting radio button "+elementName+" ; value: "+elementValue;
			//alert(myText);
			object[elementValue-1].checked = true;
		}
    }
}

function checkedToText(checkbox) {
	if (checkbox.checked==true) 
		return "on"; 
	return "off"; 
}

function stateChecker(radio) {   
	var checkedButton = "none";
	var elements=radio.length;   
	for (var i=0;i<elements;i++)  {
		if (radio[i].checked=="1") {
			checkedButton=radio[i].value      
		}   
	}
	return checkedButton
}

function setValue(elementName,object,elementType) {
// gets value of elementName from object and populates string.  returns the string.

    var elementValue;
	var elementString = "";
    
    if ((elementType=="hidden"))     elementValue = object.value;
    if ((elementType=="text"))     elementValue = object.value;
    if ((elementType=="password"))     elementValue = object.value;
    if (elementType=="select")   elementValue = object.selectedIndex;
    if (elementType=="checkbox") elementValue = checkedToText(object);
    if (elementType=="radio")    elementValue = stateChecker(object);
	
	elementString = elementName + "=" + elementValue;
	return elementString;
    
}

