
function Widget_makeCookie(Name,Value,Expiry,Path,Domain,Secure){ 
	if (Expiry!= null) { 
		var datenow = new Date(); 
		datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry)); 
		Expiry = datenow.toGMTString(); 
	} 

	Expiry = (Expiry!= null)? '; expires='+Expiry : ''; 
	Path = (Path!= null)?'; path='+Path:''; 
	Domain = (Domain!= null)? '; domain='+Domain : ''; 
	Secure = (Secure!= null)? '; secure' : ''; 

	document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure; 
} 

function Widget_readCookie(Name) { 
	var cookies = document.cookie; 
	if (cookies.indexOf(Name + '=') == -1) return null; 
	var start = cookies.indexOf(Name + '=') + (Name.length + 1); 
	var finish = cookies.substring(start,cookies.length); 
	finish = (finish.indexOf(';') == -1)? cookies.length : start + finish.indexOf(';'); 
	return unescape(cookies.substring(start,finish)); 
} 

function Widget_setActiveStyleSheet(vImgExtension,vType, vMode, vClientID) {
//alert("in active style widget");
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       if(a.getAttribute("title").indexOf(vType) != -1) a.disabled = true;
       if(a.getAttribute("title") == vType + '-' + vMode) a.disabled = false;
     }
   }
   //alert("break");
   for (i=1; i <= 3; i++){
	 //var oImg = dnn.dom.getById(vClientID + "_" + vType + "_" + i);	
	 var oImg = document.getElementById(vClientID + "_" + vType + "_" + i);	
	 //alert(vClientID + "_" + vType + "_" + i);
	//alert(oImg);	
	//alert("getAttribute:"); 
	 //alert(oImg.getAttribute("id"));
	 //alert(oImg.getAttribute("id").value);

     oImg.src = oImg.getAttribute("src").replace('-active.'+vImgExtension,'-inactive.'+vImgExtension);
	 if (oImg.getAttribute("src").indexOf(vType + '-' + vMode + '-inactive.'+vImgExtension) != -1){
	 //alert("doing image swap");
	 
	 //alert("image src before");
	 //alert(oImg.src);
		oImg.src = oImg.getAttribute("src").replace('-inactive.'+vImgExtension,'-active.'+vImgExtension);
		//alert("image src after");
		//alert(oImg.src);

	 }
   }
}

function Widget_selectStyle(vImgExtension,vCookieName, vType, vMode, vClientID) 
{
  Widget_makeCookie(vCookieName, vType + '_' + vMode, 90, '/');
  
  Widget_setActiveStyleSheet(vImgExtension,vType, vMode, vClientID)

}

function Widget_selectStyleOnly(vImgExtension,vCookieName, vType, vMode, vClientID) 
{
      Widget_setActiveStyleSheet(vImgExtension,vType, vMode, vClientID)
}


function Widget_hover(vImgExtension,oImg,vCookieName){
	if (oImg != null){
	  if (Widget_readCookie(vCookieName) != null){
	    if (oImg.getAttribute("src").indexOf('-active.'+vImgExtension) != -1){
		  oImg.src = oImg.getAttribute("src").replace('-active.'+vImgExtension,'-hover.'+vImgExtension);
	    }
	    else {
		  oImg.src = oImg.getAttribute("src").replace('-inactive.'+vImgExtension,'-hover.'+vImgExtension);
	    }
	  }
	}
}

function Widget_unhover(vImgExtension,oImg,vCookieName){
	if (oImg != null){
	  var theCookie = Widget_readCookie(vCookieName);
	  if (theCookie != null){
	    
	  	//alert("oImg.Classname: " +oImg.className);
	  	//alert("the Cookie: " +theCookie);
	    if (oImg.className==theCookie){
	    //alert("className=cookie")
			oImg.src = oImg.getAttribute("src").replace('-hover.'+vImgExtension,'-active.'+vImgExtension);    
	    }
	    else {
	    //alert("unhover ELSE, setting image back to inactive!")
			oImg.src = oImg.getAttribute("src").replace('-hover.'+vImgExtension,'-inactive.'+vImgExtension);	    
	    }
	  }
	}
}


var theForm = document.forms['Form'];
if (!theForm) {
    theForm = document.Form;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

// set to default text_medium, to set styles & load sheet when page loads
function setInitialStyleFromCookie()
{
	var theCookie = Widget_readCookie("Widget_Text_0");

	if (theCookie != null)
	{
		//alert("the cookie is not = null!");
		if(theCookie =="text_normal")
	 	{
	 		//var oImg = document.getElementById("dnn_ctl00_text_1");
	 		//oImg.src = oImg.getAttribute("src").replace('-inactive.gif','-active.gif');	
	 		//Widget_selectStyleOnly('gif','Widget_Text_0','text','normal','dnn_ctl00');
	 		Widget_selectStyleOnly("gif","Widget_Text_0","text","normal","dnn_ctl00");

	 	}
	 	else if (theCookie =="text_medium")
	 	{
	 		//var oImg = document.getElementById("dnn_ctl00_text_2");
	 		//oImg.src = oImg.getAttribute("src").replace('-inactive.gif','-active.gif');
			Widget_selectStyle("gif","Widget_Text_0","text","medium","dnn_ctl00");
	 	}
	 	else if (theCookie =="text_large")
	 	{
	 		//var oImg = document.getElementById("dnn_ctl00_text_3");
	 		//oImg.src = oImg.getAttribute("src").replace('-inactive.gif','-active.gif');
	 		Widget_selectStyle("gif","Widget_Text_0","text","large","dnn_ctl00");	 	
	 	}
	}
	else
	{
		//alert("the cookie  = null!");

	 	//default medium
	 	//var oImg = document.getElementById("dnn_ctl00_text_2");
	 	//oImg.src = oImg.getAttribute("src").replace('-inactive.gif','-active.gif');
		Widget_selectStyle("gif","Widget_Text_0","text","medium","dnn_ctl00");
	}
}
   


   