/* Cookies */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/* Strings */

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/* General */

function datedisplay() {
        Today = new Date()
        weekday = Today.getDay()
        day = Today.getDate()
        month = Today.getMonth()+1
        year = Today.getYear()

if (weekday==0) {dow="Sunday"}
if (weekday==1) {dow="Monday"}
if (weekday==2) {dow="Tuesday"}
if (weekday==3) {dow="Wednesday"}
if (weekday==4) {dow="Thursday"}
if (weekday==5) {dow="Friday"}
if (weekday==6) {dow="Saturday"}

if (month==1) {monthstring="Jan"}
if (month==2) {monthstring="Feb"}
if (month==3) {monthstring="Mar"}
if (month==4) {monthstring="Apr"}
if (month==5) {monthstring="May"}
if (month==6) {monthstring="Jun"}
if (month==7) {monthstring="Jul"}
if (month==8) {monthstring="Aug"}
if (month==9) {monthstring="Sep"}
if (month==10) {monthstring="Oct"}
if (month==11) {monthstring="Nov"}
if (month==12) {monthstring="Decr"}

yearstring = year.toString();

document.write (day + " " + monthstring + " " + yearstring)
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function WA_AddValueToList(ListObj,TextString,ValString,Position)  {
  if (isNaN(parseInt(Position)))   {
    Position = ListObj.options.length;
  }
  else  {
    Position = parseInt(Position);
  }
  if (ListObj.length > Position)  {
  ListObj.options[Position].text=TextString;
  if (ValString != "")  {
    ListObj.options[Position].value = ValString;
  }
    else  {
      ListObj.options[Position].value=TextString;
    }
  }
  else  {
    var LastOption = new Option();
    var OptionPosition = ListObj.options.length;
    ListObj.options[OptionPosition] = LastOption;
    ListObj.options[OptionPosition].text = TextString;
    if (ValString != "")  {
      ListObj.options[OptionPosition].value = ValString;
    }
    else  {
      ListObj.options[OptionPosition].value=TextString;
    }
  }
}

function WA_subAwithBinC(a,b,c)
{

	var i = c.indexOf(a);
	var l = b.length;

	while (i != -1)	{
		c = c.substring(0,i) + b + c.substring(i + a.length,c.length);  //replace all valid a values with b values in the selected string c.
  i += l
		i = c.indexOf(a,i);
	}
	return c;

}

function WA_AddSubToSelected(sublist,targetlist,repeatvalues,leavetop,leavebottom,noseltop,noselbot,topval,toptext)     {
  for (var j=0; j<noseltop; j++)     {
    sublist.options[j].selected = false;
  }
  for (var k=0; k<noselbot; k++)     {
    sublist.options[sublist.options.length-(k+1)].selected = false;
  }
  if (sublist.selectedIndex >= 0)      {
   if (leavebottom)     {
      botrec = new Array(2);
      botrec[0] = targetlist.options[targetlist.options.length-1].value;
      botrec[1] = targetlist.options[targetlist.options.length-1].text;
      targetlist.options[targetlist.options.length-1] = null;
    }
    if (!leavetop && targetlist.options.length > 0)     {
      if (targetlist.options[0].value == topval)     {
        targetlist.options[0] = null;  
      }
    }
    else     {
      if (leavetop && toptext != '')     {
        targetlist.options[0].value = topval;
        targetlist.options[0].text = toptext;
      }
    }
    for (var o=0; o<sublist.options.length; o++)     {
      if (sublist.options[o].selected && o >= noseltop && o < sublist.options.length - noselbot)     {
        theText = sublist.options[o].text;
        theValue = sublist.options[o].value;
        addvalue = true;
        if (!repeatvalues)      {
          for (var p=0; p<targetlist.options.length; p++)     {
            if (theValue == targetlist.options[p].value)      {
              addvalue = false;
            }
          }
        }
        if (addvalue)  WA_AddValueToList(targetlist,theText,theValue,targetlist.options.length);
      }
    }
    if (leavebottom)     {
      WA_AddValueToList(targetlist,botrec[1],botrec[0],targetlist.options.length);
    }
  }
  for (var l=0; l < targetlist.options.length; l++)    {
    targetlist.options[l].selected = false;
  }
}

function WA_RemoveSelectedFromList(theBox,nottoremove,noneselectedoption,noneselectedvalue,noneselectedtext)     {
  var n=0;
  var selectedArray = new Array();
  for (var j=0; j<theBox.options.length; j++)     {
    if (!theBox.options[j].selected || nottoremove.indexOf("|WA|" + theBox.options[j].value + "|WA|") >= 0)     {
      theBox.options[n].value = theBox.options[j].value;
      theBox.options[n].text = theBox.options[j].text;
      n++;
    }
    else {
	    selectedArray[selectedArray.length] = j;
    }
  }
  for (var k=0; k<selectedArray.length; k++)  {
    theBox.options[selectedArray[k]].selected = false;
  }
  m = n;
  while (m<=j)     {
    theBox.options[n] = null;
    m++;
  }
  if (theBox.options.length == noneselectedoption && noneselectedtext != "")     {
    noneselectedvalue = WA_subAwithBinC("|WA|",",",noneselectedvalue);
    noneselectedtext = WA_subAwithBinC("|WA|",",",noneselectedtext);
    WA_AddValueToList(theBox,noneselectedtext,noneselectedvalue,0);
  }
  for (var l=0; l < theBox.options.length; l++)    {
    theBox.options[l].selected = false;
  }
}

function WA_SelectAllInTarget(boxtoselect, valstonotselect)       {
  for (var x=0; x<boxtoselect.options.length; x++)       {
    if (valstonotselect.indexOf("|WA|" + boxtoselect.options[x].value + "|WA|") < 0) {
		boxtoselect.options[x].selected = true;
    }
    else       {
		boxtoselect.options[x].selected = false;
    }
  }
}

function f1()
{
    var div=document.getElementById('backGroundDiv');

    if (div == null)
        return false; 
    div.className="Popup_BackGround";
}

function f2()
{
    var div=document.getElementById('backGroundDiv');
    if (div == null)
        return false;
    div.className="";
}

function OpenOverlay(url,w,h)
		{
			var wnd = window.radopen(url, 'RadWindow');
			wnd.setSize(w,h);
			wnd.center();
			wnd.SetModal(true);
		}
function CallBackFunction(radWindow, returnValue)
{
			if (returnValue) window.location.reload();
}
function setActiveStyleSheet(title, reset) {
	        var i, a, main;
	        for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			    a.disabled = true;
			    if(a.getAttribute("title") == title) a.disabled = false;
		        }
	        }
	        if (reset == 1) createCookie("wstyle", title, 365);
}


// Create a dialog
function createDialog(url) {
			var id;
			var frameTitle;
			var frameHeight;
            var iframe = document.createElement("iframe");
            var dialog = document.createElement("div");
            
            // Setup iframe
            iframe.src = url;
            iframe.setAttribute('frameborder',0);
            iframe.setAttribute('border',0);
            iframe.setAttribute('name','harold');
            
            // Setup dialog
            dialog.appendChild(iframe);
            dialog.setAttribute("style","display: none");
            
            // Load the dialog
            document.body.appendChild(iframe);
            
            //newFrame = frames['harold'];
            //newFrame.document.onload = function() {
            //};
            
            //newFrame = frames['harold'];
            //title = newFrame.document.getElementsByTagName('title').innerHTML;
            
            //alert(title);
}

// Open an overlay window in the front end
function FEOpenOverlay(url,title,w,h) {
            var id = title.replace(/\s/g,'-').toLowerCase();
            var iframe = document.createElement("iframe");
            
            // Setup iframe
            iframe.src = url;
            iframe.setAttribute('frameborder',0);
            iframe.setAttribute('border',0);
            iframe.setAttribute('name',id);
            iframe.setAttribute('id',id);
            iframe.setAttribute('width',w);
            iframe.setAttribute('height',h);
            
            // Setup dialog
            $("body").append($(iframe));
            $(iframe).dialog({
                title: title,
                autoOpen: false,
                modal: true,
                width: w,
                height: h,
                overlay: {
                    background: "#000",
                    opacity: 0.2
                }
            });
            
            $(iframe).dialog("open");
}

var emailformdiaplay=false;		

function showEmailform() {
   var iframe = document.getElementById("iframeEmailForm");
   if (!emailformdiaplay)
   {
   iframe.style.display="";
   emailformdiaplay=true;   
   }
   else{
   iframe.style.display="none";
   emailformdiaplay=false;
   iframe.src=iframe.src;
   }
   
}

			

function removeBranding() {
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { 
        if(left(a.getAttribute("href"),12) != "styles/base_" && left(a.getAttribute("href"),16) != "/styles/textsize") {
            a.disabled = true;
        }
    }
    var c = createCookie('brandingStatus','0',1);
}

function addBranding() {
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(left(a.getAttribute("href"),12) != "styles/base_" && left(a.getAttribute("href"),16) != "/styles/textsize") {
            a.disabled = false;
        }
    }
    var c = createCookie('brandingStatus','1',1);
}


$(document).ready(function() {


	$("body").addClass("js");

	$("div.searchitems").hide();
    $("div.searchitems-link").show();
	$("div.searchitems-link a").toggle(function(){
			$(this).toggleClass("open");
			$(".searchitems").toggleClass("open").slideDown("fast",function() {
			    //$(this).find("input[type='text']").focus();
			})	
	},function(){
			$(this).toggleClass("open");
			$("div.searchitems").toggleClass("open").slideUp("fast");
	});
						   
	/*
	// Replace input button with a link button
	$("input.LinkButton").each(function() {
										
		jsHref = "javascript:__doPostBack('" + $(this).attr('name') + "','')";
		btnLink = '<a class="LinkButton" id="' + $(this).attr('id') + '" href="' + jsHref + '"><span>' + $(this).attr('value') + "</span></a>";
		
		$(this).replaceWith(btnLink);
		
	});
	*/
	
	/* JavaScript form buttons */
	
	$("a.LinkButton").wrapInner("<span></span>").mousedown(function() {
		$(this).addClass("LinkButtonDown");
	}).mouseup(function() {
		$(this).removeClass("LinkButtonDown");
	}).mouseout(function() {
		$(this).removeClass("LinkButtonDown");
	});
	
	/* Hide branding stylesheets */
	
	/*$("#editbar").before('<div style="padding: 5px; background: #ccc;" id="removebranding"><input type="checkbox" name="brandingswitch" id="brandingswitch" checked="checked"> <label for="brandingswitch">Branding stylesheets</label></div>');
	$("#removebranding input[type='checkbox']").change(function(){
	    var s = readCookie("brandingStatus");
	    if(s) {
	        if(s == '1') {
	            removeBranding();
	        } else {
	            addBranding();
	        }
	    } else {
	        removeBranding();
	    }
	});*/
	
	/* Error msg flash */
	
    $(".errorbox").addClass("errorbox-highlight");
    $(".errorbox").removeClass("errorbox-highlight",800);
    
	/* Status msg flash */
	
    $(".statusbox").addClass("errorbox-highlight");
    $(".statusbox").removeClass("errorbox-highlight",800);
    
});
		
/*
	Runs in IE as soon as the document model is available
*/

if ($.browser.msie) {
	$(document).ready(function() {
							   
							   
		/* If there is an image inside a radio/checkbox label, make it work in IE */
		$("label img").click(function() {
		
			inputTarget = $(this).parents("label").attr("for");
			$("input[type='radio']#" + inputTarget).attr("checked","checked");
			$("input[type='checkbox']#" + inputTarget).attr("checked",!tog);
			tog=!tog;
		
		});

	});
}