function getCheckedValue(radioObj) {

	if(!radioObj)
		return "";
	var radioLength = radioObj.length;

	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

/*load the javascript for the module into the document head... if we don't do this we can't pickup the script
with the module thats loaded through AJAX*/

/*1 = public
0 = admin*/
/*readyFunctions is a list of functions that need to run once a script is loaded, the function is in the same location in it's list, as  the script
in scriptPath that its running for...*/
function insertScriptandStyle(scriptPath,stylePath,pubAdmin,readyFunctions){
	
	/*we have to get the head this way... getElementById won't work on a head cause it can't have an id*/
	docHead = document.getElementsByTagName("head")[0];
	
	/*make sure to load styles first, or some of the javascript stuff buggers up*/
	moduleStyle = buildHtml.createLink(stylePath,"stylesheet","text/css","moduleStyle" + moduleStyleCnt,docHead);
	moduleStyleCnt++;
	
	/*we can have multiple scripts, so loop through the list and add them all*/
	scriptArray = scriptPath.split(",");
	if ( typeof(readyFunctions) != "undefined" && readyFunctions != null ) {
		readyFuncArray = readyFunctions.split(",");
	}
	else{
		readyFuncArray = new Array();
	}
	
	for(var r=0;r<scriptArray.length;r++){
		moduleScript = buildHtml.createScript('text/javascript',scriptArray[r],readyFuncArray[r],"moduleScript" + moduleScriptCnt);
		
		/*the index.php for the public and admin side have a script for our ajax object.... we insert right after that. this is mostly done so that 
		all the default js on the admin side can get the afterModuleDel functions that we are appending...*/
		if(document.getElementById("ajaxScript") == null || pubAdmin == 1){
			docHead.appendChild(moduleScript);
	  	}
	  	else{
			insertAfter(document.getElementById("ajaxScript"),moduleScript);
	  	}
		
		moduleScriptCnt++;
	}
	
	moduleScriptCnt = 0;
	moduleStyleCnt = 0;
}

// This function inserts newNode after referenceNode
function insertAfter( referenceNode, newNode ){
    referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}

/*converts a 12 hour time string to a 24 hour time string that is mysql compatible*/
function timeConvertMysql(timeVal){
	
	var timeAry = timeVal.split(":");
	var timeHrs = timeAry[0];
	
	if(timeVal.match(/am/i) != null){
		var timeStr = timeHrs + ":" + timeAry[1].slice(0,timeAry[1].indexOf(" ",0)) + ":00";
		return timeStr;
	}
	else if(timeVal.match(/pm/i) != null){
		timeHrs = parseInt(timeHrs) + 12;
		var timeStr = timeHrs + ":" + timeAry[1].slice(0,timeAry[1].indexOf(" ",0)) + ":00";
		return timeStr;
	}
	else{
		alert("Invalid Time Entered");
		return false;
	}
}

function epochToMySQL(eDate){
	var newDate = eDate.split("/");
	var myDate = newDate[2] + "-" + newDate[0] + "-" + newDate[1];
	return myDate;
}

/*to use this function all the targets should be a member of the same css class, and their ID should be the class
with a unique number identifier appended*/
function toggleExpanded(prefix,suffix){

	var clickTarget = document.getElementById(prefix + suffix);
	
	/*note... we can't use getElementsByName here cause it won't work on IE DOM created elements*/
	var closeChecks = document.getElementsByClassName(prefix);

	/*loop through and close previously opened answers*/
	for(i=0;i<closeChecks.length;i++){
		/*if it isn't the one we want open, and its currently open, close it*/
		if(closeChecks[i].id != prefix + suffix && document.getElementById(closeChecks[i].id).style.display != "none"){
			Effect.BlindUp(closeChecks[i].id,{ duration: 0.5});
		}
	}
	
	/*toggle if its opened or closed*/
	if(clickTarget.style.display == "none"){
		Effect.BlindDown(prefix + suffix,{ duration: 0.5});
	}
	else{
		Effect.BlindUp(prefix + suffix,{ duration: 0.5});
	}

}

function setWrapperDiv(){
	
	var wrapperAjax = ajaxObj();
	
	/*make the request for the page content*/
	var requestParams = "function=getAllRecords";
	
	wrapperAjax.onreadystatechange=function(){
		if(wrapperAjax.readyState==4){
			eval(wrapperAjax.responseText);
			for(var i=0;i<ajaxReturn.length;i++){
				
				/*set the class name*/
				/*check for an element of that ID first....*/
				var wrappedDiv = new Array();
				wrappedDiv[0] = document.getElementById(ajaxReturn[i]["elementID"]);
				/*if it doesn't exist, it must be a className*/
				if((typeof(wrappedDiv[0]) == "undefined" || wrappedDiv[0] == null)){
					wrappedDiv = document.getElementsByClassName(ajaxReturn[i]["elementID"]);
				}
						   		   
				/*check if the top left wrapper is there*/
				wrapperCheck = document.getElementById(ajaxReturn[i]["elementWrapClass"] + "-TL-" + ajaxReturn[i]["elementID"]);

				if(typeof(wrapperCheck) == "undefined" || wrapperCheck == null || (wrappedDiv.className =! null && typeof(wrappedDiv.className) != "undefined" && wrappedDiv.className.length == 0)){
					
					for(var d=0;d<wrappedDiv.length;d++){
						wrappedDiv[d].className = ajaxReturn[i]["elementWrapClass"] + " " + wrappedDiv[d].className;
						
						/*create corner divs*/
						topLeftWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-TL-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-topLeft",null,null,wrappedDiv[d],null);
						topRightWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-TR-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-topRight",null,null,wrappedDiv[d],null);
						bottomLeftWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-BL-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-bottomLeft",null,null,wrappedDiv[d],null);
						bottomRightWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-BR-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-bottomRight",null,null,wrappedDiv[d],null);
						
						/*create the sides of our div*/
						topWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-T-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-top",null,null,wrappedDiv[d],null);
						bottomWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-B-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-bottom",null,null,wrappedDiv[d],null);
						leftWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-L-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-left",null,null,wrappedDiv[d],null);
						rightWrap = buildHtml.createDivHTMLElement(ajaxReturn[i]["elementWrapClass"] + "-R-" + ajaxReturn[i]["elementID"],ajaxReturn[i]["elementWrapClass"] + "-right",null,null,wrappedDiv[d],null);
					}
				}
			}
		}
	}
	ajaxPost(wrapperAjax,"/cmsAPI/settings/wrapper-elements.php",requestParams,true);
}

function setWrapperStyles(){
	
	var wrapperAjax = ajaxObj();
	
	/*make the request for the page content*/
	var requestParams = "function=getGroupedFieldValues&fieldName=elementWrapClass,isHover,isActive";
	
	wrapperAjax.onreadystatechange=function(){
		if(wrapperAjax.readyState==4){
			eval(wrapperAjax.responseText);
			
			for(var i=0;i<ajaxReturn.length;i++){
				/*we need image objects for all the images so we can position them based on their size*/
				
				/*set the background*/
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topLeft","background-image","url(" + window["topLeftImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-top","background-image","url(" + window["topImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topRight","background-image","url(" + window["topRightImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-left","background-image","url(" + window["leftImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-right","background-image","url(" + window["rightImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomLeft","background-image","url(" + window["bottomLeftImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottom","background-image","url(" + window["bottomImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomRight","background-image","url(" + window["bottomRightImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				changecss("." + ajaxReturn[i]["elementWrapClass"],"background-image","url(" + window["backRepeatImg" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				
				/*hover*/
				if(ajaxReturn[i]["isHover"]==1){
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-topLeft","background-image","url(" + window["topLeftImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-top","background-image","url(" + window["topImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-topRight","background-image","url(" + window["topRightImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-left","background-image","url(" + window["leftImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-right","background-image","url(" + window["rightImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-bottomLeft","background-image","url(" + window["bottomLeftImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-bottom","background-image","url(" + window["bottomImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover ." + ajaxReturn[i]["elementWrapClass"] +  "-bottomRight","background-image","url(" + window["bottomRightImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":hover" ,"background-image","url(" + window["backRepeatImgHover" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				}
				
				/*Active*/
				if(ajaxReturn[i]["isActive"]==1){
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-topLeft","background-image","url(" + window["topLeftImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-top","background-image","url(" + window["topImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-topRight","background-image","url(" + window["topRightImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-left","background-image","url(" + window["leftImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-right","url(" + window["rightImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-bottomLeft","url(" + window["bottomLeftImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-bottom","background-image","url(" + window["bottomImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active ." + ajaxReturn[i]["elementWrapClass"] +  "-bottomRight","background-image","url(" + window["bottomRightImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
					changecss("." + ajaxReturn[i]["elementWrapClass"] + ":active","background-image","url(" + window["backRepeatImgActive" + ajaxReturn[i]["elementWrapClass"]].src + ")");
				}
				
				/*set the dimensions and positioning*/
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topLeft","height",window["topLeftImg" + ajaxReturn[i]["elementWrapClass"]].height + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topLeft","width",window["topLeftImg" + ajaxReturn[i]["elementWrapClass"]].width  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topLeft","left",eval(window["topLeftImg" + ajaxReturn[i]["elementWrapClass"]].width * -1)  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topLeft","top",eval(window["topLeftImg" + ajaxReturn[i]["elementWrapClass"]].height * -1)  + "px");
				
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-top","height",window["topImg" + ajaxReturn[i]["elementWrapClass"]].height + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-top","width","100%");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-top","left",0  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-top","top",eval(window["topImg" + ajaxReturn[i]["elementWrapClass"]].height * -1)  + "px");
				
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topRight","height",window["topRightImg" + ajaxReturn[i]["elementWrapClass"]].height + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topRight","width",window["topRightImg" + ajaxReturn[i]["elementWrapClass"]].width  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topRight","right",eval(window["topRightImg" + ajaxReturn[i]["elementWrapClass"]].width * -1)  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-topRight","top",eval(window["topRightImg" + ajaxReturn[i]["elementWrapClass"]].height * -1)  + "px");
				
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-left","height","100%");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-left","width",window["leftImg" + ajaxReturn[i]["elementWrapClass"]].width  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-left","left",eval(window["leftImg" + ajaxReturn[i]["elementWrapClass"]].width * -1)  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-left","top","0px");
				
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-right","height","100%");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-right","width",window["rightImg" + ajaxReturn[i]["elementWrapClass"]].width  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-right","right",eval(window["rightImg" + ajaxReturn[i]["elementWrapClass"]].width * -1)  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-right","top","0px");
				
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomLeft","height",window["bottomLeftImg" + ajaxReturn[i]["elementWrapClass"]].height + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomLeft","width",window["bottomLeftImg" + ajaxReturn[i]["elementWrapClass"]].width  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomLeft","left",eval(window["bottomLeftImg" + ajaxReturn[i]["elementWrapClass"]].width * -1)  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomLeft","bottom",eval(window["bottomLeftImg" + ajaxReturn[i]["elementWrapClass"]].height * -1)  + "px");
				
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottom","height",window["bottomImg" + ajaxReturn[i]["elementWrapClass"]].height + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottom","width","100%");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottom","left",0  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottom","bottom",eval(window["bottomImg" + ajaxReturn[i]["elementWrapClass"]].height * -1)  + "px");
				
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomRight","height",window["bottomRightImg" + ajaxReturn[i]["elementWrapClass"]].height + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomRight","width",window["bottomRightImg" + ajaxReturn[i]["elementWrapClass"]].width  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomRight","right",eval(window["bottomRightImg" + ajaxReturn[i]["elementWrapClass"]].width * -1)  + "px");
				changecss("." + ajaxReturn[i]["elementWrapClass"] +  "-bottomRight","bottom",eval(window["bottomRightImg" + ajaxReturn[i]["elementWrapClass"]].height * -1)  + "px");
				
				setWrapperDiv();
			}
		}
	}
	
	ajaxPost(wrapperAjax,"/cmsAPI/settings/wrapper-elements.php",requestParams,true);
}