var xmlHttp;



function GetXmlHttpObject(){
	var objXMLHttp=null;
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	} // else if
	return objXMLHttp;
} // function



function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}





function slab_popup(theURL,winName,features) { //v2.0 features are:width=300,height=150,left=200,top=100,resizable=no,scrollbars=no,toolbar=no,status=no
newwindow = window.open(theURL,winName,features);
if(window.focus){ newwindow.focus(); }
}



function poptastic(theURL,winName,features){
newwindow = window.open(theURL,winName,'width=300,height=150,left=200,top=100,resizable=no,scrollbars=no,toolbar=no,status=no');
if(window.focus){ newwindow.focus(); }
}



// show and hide

function showHide(theitem,state){
	if(document.getElementById){
		var itemobj = document.getElementById(theitem);
	} else if (document.all){
		var itemobj = document.theitem;
	}
	currentOpacity = itemobj.style.opacity;
	if(state == "show"){
		itemobj.style.display = 'block';
	} else {
		itemobj.style.display = 'none';
	}
}





function showHideDelay(theitem,thestate,thedelay){
	if(document.getElementById){
		var itemobj = document.getElementById(theitem);
	} else if (document.all){
		var itemobj = document.theitem;
	}
	if(thestate == 'show'){
		itemobj.style.display = 'block';
   		t = setTimeout("showHide(\'"+theitem+"\','show')",thedelay);
   	} else {
    	clearTimeout(t);
   		t = setTimeout("showHide(\'"+theitem+"\','hide')",thedelay);
	}
}



function showHideMove(theitem,state,referenceItem){
	if(document.getElementById){
		var theblock = document.getElementById(theitem);
		var refBlock = document.getElementById(referenceItem);
	} else if (document.all){
		var theblock = document.theitem;
		var refBlock = document.referenceItem;
	}
	var refPos =  findPos(refBlock);
	if(state == "show"){
		if(theblock) theblock.style.display = "block";
		if(theblock) theblock.style.position = 'absolute';
		if(theblock) theblock.style.top = refPos[1]+'px';
		if(theblock) theblock.style.left = refPos[0]+'px';
	} else {
		theblock.style.display = "none";
	}
}



function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			if(curleft) curleft += obj.offsetLeft
			if(curtop) curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}



function setElementValue(object,someVal,attr){
	if(document.getElementById){
		var foobar = document.getElementById(object)
	} else if (document.all){
		var foobar = document.object
	}
	if(attr == 'val'){
		if(foobar) foobar.value = someVal;
	} else if(attr == 'src'){
		if(foobar) foobar.src = someVal;
	} else if(attr == 'txt'){
		if(foobar) foobar.innerHTML = someVal;
	}
}









function swapImgSelectValues(someVal){
	if(document.getElementById){
		var thumbNail = document.getElementById('thumb_preview')
		var fileInput = document.getElementById('file_name')
		var nameField = document.getElementById('existingImage')
	} else if (document.all){
		var thumbNail = document.thumb_preview
		var fileInput = document.file_name
		var nameField = document.existingImage
	}
		if(thumbNail) thumbNail.src = 'images\/thumbs\/'+someVal;
		if(fileInput) fileInput.value = someVal;
		if(nameField) nameField.innerHTML = someVal;
}






function changeInner(object,thetext){
	if(document.getElementById){
		var arfboo = document.getElementById(object);
	} else if (document.all){
		var arfboo = document.object;
	}
	arfboo.innerHTML = thetext;
}





function outlineThis(object){
	if(document.getElementById){
		var barfoo = document.getElementById(object);
	} else if (document.all){
		var barfoo = document.object;
	}
	if(barfoo) barfoo.style.border = 'medium solid red';
}







function logoutConfirm(thepage) {
	var answer = confirm("Are you sure you want to logout?")
	if (answer){
		window.location = thepage;
	} else {
		exit();
	}
}





function confirmIt(thepage,themessage) {
	var answer = confirm(themessage)
	if (answer==true){
		window.location = thepage;
	}
}




var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;


function InitializeTimer(secs) {
    StopTheClock();
    StartTheTimer();
}

function StopTheClock() {
    if(timerRunning) clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer() {
    if (secs==0) {
        StopTheClock();
        alert("Your session is about to expire. You will be logged out in less than 2 minutes unless you click on any link. If you are editing an entry, select SAVE AS DRAFT and then SUBMIT to save it and then re-edit the entry to keep working.");
    } else {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}
//window.onload=InitializeTimer;




// useful
function urlEncode(theString) {
  var output = '';
  var x = 0;
  theString = theString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < theString.length) {
    var match = regex.exec(theString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (theString[x] == ' ')
        output += '+';
      else {
        var charCode = theString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}




// variables for slab obfusc8

var s8_0 = "w"; 
var s8_1 = "x"; 
var s8_2 = "y"; 
var s8_3 = "z"; 
var s8_4 = "a"; 
var s8_5 = "b"; 
var s8_6 = "r"; 
var s8_7 = "d"; 
var s8_8 = "t"; 
var s8_9 = "e"; 
var s8_10 = "g"; 
var s8_11 = "h"; 
var s8_12 = "i"; 
var s8_13 = "j"; 
var s8_14 = "k"; 
var s8_15 = "l"; 
var s8_16 = "m"; 
var s8_17 = "n"; 
var s8_18 = "o"; 
var s8_19 = "p"; 
var s8_20 = "q"; 
var s8_21 = "c"; 
var s8_22 = "s"; 
var s8_23 = "f"; 
var s8_24 = "u"; 
var s8_25 = "v"; 
var s8_26 = "1"; 
var s8_27 = "2"; 
var s8_28 = "3"; 
var s8_29 = "4"; 
var s8_30 = "5"; 
var s8_31 = "6"; 
var s8_32 = "7"; 
var s8_33 = "8"; 
var s8_34 = "9"; 
var s8_35 = ":"; 
var s8_36 = "@"; 
var s8_37 = "."; 
var s8_38 = "0"; 
var s8_39 = "<"; 
var s8_40 = ">"; 
var s8_41 = "="; 
var s8_42 = '"'; 
var s8_43 = " "; 
var s8_44 = "/"; 
var s8_45 = "_"; 
var s8_46 = "-";
var s8_47 = "W"; 
var s8_48 = "X"; 
var s8_49 = "Y"; 
var s8_50 = "Z"; 
var s8_51 = "A"; 
var s8_52 = "B"; 
var s8_53 = "R"; 
var s8_54 = "D"; 
var s8_55 = "T"; 
var s8_56 = "E"; 
var s8_57 = "G"; 
var s8_58 = "H"; 
var s8_59 = "I"; 
var s8_60 = "J"; 
var s8_61 = "K"; 
var s8_62 = "L"; 
var s8_63 = "M"; 
var s8_64 = "N"; 
var s8_65 = "O"; 
var s8_66 = "P"; 
var s8_67 = "Q"; 
var s8_68 = "R"; 
var s8_69 = "S"; 
var s8_70 = "F"; 
var s8_71 = "U"; 
var s8_72 = "V";
var s8_73 = "R"; 






function GetIEVersion(){
	var agt      = navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_ie    = (agt.indexOf("msie") != -1);
	var is_ie3   = (is_ie && (is_major < 4)); 
	// It's not IE so we don't care
	if (!is_ie) return (-1); 
	// It's IE3 report it
	if (is_ie3) return (3); 
	// It's IE4+ so we can use RegExp
	var rxIE       = new RegExp("msie\\s(\\d+.\\w+)","ig");
	var arIEResult = rxIE.exec(agt); 
	// arIEResult[0] contains the whole match
	// arIEResult[1] contains the first matching group
	//               in our case the full version
	//
	// We use parseFloat because we want a number
	return (parseFloat(arIEResult[1]));
}









function showDaisy(message){
var daisy = 'daisy';
	if(document.getElementById){
		var thedaisy = document.getElementById(daisy)
	} else if (document.all){
		var thedaisy = document.daisy
	}
	if(thedaisy){
		thedaisy.style.backgroundColor = '#fff';
		thedaisy.style.opacity = .75;
		thedaisy.style.filter = 'alpha(opacity=75)';
		thedaisy.style.width = '100%';
		thedaisy.style.height = '100%';
		thedaisy.innerHTML = message+'<br /><br /><br /><br /><br /><br /><br /><a href="index.php">CANCEL</a>';
	}
}







function hideDaisy(){
var daisy = 'daisy';
	if(document.getElementById){
		var thedaisy = document.getElementById(daisy)
	} else if (document.all){
		var thedaisy = document.daisy
	}
}




function swapImage(object,image){
	if(document.getElementById){
		var idElement = document.getElementById(object)
	} else if (document.all){
		var idElement = document.object
	}
	idElement.style.backgroundImage='url('+image+')';
}




function swapSrc(object,image){
	if(document.getElementById){
		var idElement = document.getElementById(object)
	} else if (document.all){
		var idElement = document.object
	}
	idElement.src=image;
}





function setOpacity(value,object) {
	if(object != undefined && object != ''){
		if(document.getElementById){
			var idElement = document.getElementById(object);
		} else if (document.all){
			var idElement = document.object;
		}
		if(idElement.style.display == 0 || idElement.style.display == 'none'){
			idElement.style.display = 'block';
			idElement.style.opacity = 0;
		}
		idElement.style.opacity = value/10;
		idElement.style.filter = 'alpha(opacity='+Math.round(value*10)+')';
		if(value < 1.5){
			idElement.style.opacity = 0;
			idElement.style.display ='none';
		}
	}
}




var t;

function fadeIn(fiLevel,fiObject) {
	if(fiLevel < 10.25){
		setOpacity(fiLevel,fiObject);
		var fiLevelNew= fiLevel+1;
		t = setTimeout("fadeIn("+fiLevelNew+",'"+fiObject+"')",1);
	}
}

function fadeOut(foLevel,foObject) {
	if(foLevel > -.25){
		setOpacity(foLevel,foObject);
		var foLevelNew = foLevel-1;
		t = setTimeout("fadeOut("+foLevelNew+",'"+foObject+"')",1);
	}
}

function fadeTo(fromLevel,toLevel,objectElement) {
	if(fromLevel < toLevel){
		setOpacity(fromLevel,objectElement);
		var newUpLevel= fromLevel+.5;
		t = setTimeout("fadeTo("+newUpLevel+","+toLevel+",'"+objectElement+"')",1);
	} else if(fromLevel > toLevel){
		setOpacity(fromLevel,objectElement);
		var newDownLevel= fromLevel-.5;
		t = setTimeout("fadeTo("+newDownLevel+","+toLevel+",'"+objectElement+"')",1);
	}
}



function setSlideShow() {
	if(document.getElementById){
		var conTainer = document.getElementById('container');
		var heaDer = document.getElementById('header');
		var fooTer = document.getElementById('footer');
		var mainBox = document.getElementById('mainbox');
		var menuBox = document.getElementById('menubox');
		var userMenu = document.getElementById('usermenu');
	} else if (document.all){
		var conTainer = document.container;
		var heaDer = document.header;
		var fooTer = document.footer;
		var mainBox = document.mainbox;
		var menuBox = document.menubox;
		var userMenu = document.usermenu;
	}
	conTainer.style.display='block';
	conTainer.style.position='absolute';
	conTainer.style.top='0';
	conTainer.style.left='0'; 
	if (document.all){
		conTainer.style.width = document.body.offsetWidth;
		conTainer.style.height= document.body.offsetHeight;
	} else {
		conTainer.style.width = '100%';
		conTainer.style.height = '100%';
	}
//	conTainer.style.backgroundColor='#000000';
	conTainer.style.backgroundImage='url(#)';
	conTainer.style.borderStyle='none';
	conTainer.style.padding='0';
	conTainer.style.margin='0';
	heaDer.style.display='none';
	fooTer.style.display='none';
	mainBox.style.display='none';
	menuBox.style.display='none';
	mainBox.style.borderStyle='none';
	menuBox.style.borderStyle='none';
	userMenu.style.display='none';
} 



function fadeImage(objectA,objectB,images,c){
	var imagea = images.split('~');
	var numpix = imagea.length;
	var image = imagea[c];
	c++;
	if(c >= numpix) c =0;
	if(isInt(c/2)!=false){ object = objectA; } else {  object = objectB; }
	setOpacity(0,object);
	if(document.getElementById){
		var imgElement = document.getElementById(object);
	} else if (document.all){
		var imgElement = document.object;
	}
	imgElement.style.backgroundImage='url(images/imgallery/'+image+')';
	if (document.all){
		imgElement.style.width = document.body.offsetWidth;
		imgElement.style.height= document.body.offsetHeight;
	} else {
		imgElement.style.width = '100%';
		imgElement.style.height = '100%';
	}
	t2 = setTimeout("fadeIn(0,\'"+object+"\')",500);
	t3 = setTimeout("fadeOut(10,\'"+object+"\')",7000);
	t4 = setTimeout("fadeImage('"+objectA+"','"+objectB+"','"+images+"',"+c+")",7000);
}



function slideShowBox(objectA,objectB,images,c,t){
	var imagea = images.split('~');
	var numpix = imagea.length;
	if(c >= (numpix-1)) c = 0;
	var image = imagea[c];
	var timing = t;
	c++;
	if(isInt(c/2) == true){ object = objectA; } else {  object = objectB; }
	if(document.getElementById){
		var imgElement = document.getElementById(object);
	} else if (document.all){
		var imgElement = document.object;
	}
	//imgElement.innerHTML = c;
	imgElement.style.backgroundImage='url(images/imgallery/'+image+')';
	t2 = setTimeout("fadeIn(0,\'"+object+"\')",0);
	t3 = setTimeout("fadeOut(10,\'"+object+"\')",timing);
	t4 = setTimeout("slideShowBox('"+objectA+"','"+objectB+"','"+images+"',"+c+","+timing+")",timing);
}



// preload multiple images
function preLoad(imageString){
var imageStr = imageString.split('~');
var max = imageStr.length;
var i;
for(i = 0; i<=max; i++){
loadImage = new Image(); 
loadImage.src = 'images/imgallery/'+imageStr[i];
//alert(loadImage.src);
} // for
} // function




 function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 }
 
 
 
 
// form scripts
 
function slabCountLines(strtocount, cols) {
    var hard_lines = 1;
    var last = 0;
    while ( true ) {
        last = strtocount.indexOf("\n", last+1);
        hard_lines ++;
        if ( last == -1 ) break;
    }
    var soft_lines = Math.round(strtocount.length / (cols));
    var hard = eval("hard_lines  " + unescape("%3e") + "soft_lines;");
    if ( hard ) soft_lines = hard_lines;
    return Math.round(soft_lines*.6);
}



function slabCleanForm() {
    var the_form = document.forms[0];
    for ( var x in the_form ) {
        if ( ! the_form[x] ) continue;
        if( typeof the_form[x].rows != "number" ) continue;
        the_form[x].rows = slabCountLines(the_form[x].value,the_form[x].cols) +1;
    }
    setTimeout("slabCleanForm();", 300);
}




function setMinHeight(element,scrollOrWindow,adjustment){  
	var theElement = document.getElementById(element);
	if(scrollOrWindow == 'scroll'){
		var sHeight = document.documentElement.scrollHeight;
		theElement.style.height = (sHeight-adjustment)+'px';
	} else{ 
		var wHeight = document.documentElement.clientHeight;
		theElement.style.height = (wHeight-adjustment)+'px';
	}
}



// scroll buttons

var scrollTimer;
function scrollUp(thebox){
	targetbox = document.getElementById(thebox);
	scrollTimer = setInterval("targetbox.scrollTop -= 5", 15);
}
function scrollDown(thebox){
	targetbox = document.getElementById(thebox);
	scrollTimer = setInterval("targetbox.scrollTop += 5", 15);
}



function startList(theitem){		
	if(document.getElementById && document.all){
		navRoot = document.getElementById(theitem);
	} // if
	for(i=0; i<navRoot.childNodes.length; i++){
		node = navRoot.childNodes[i];
		if(node.nodeName.toUpperCase()=="LI"){
			node.onmouseover=function(){
				this.className+=" over";
			} // function
			node.onmouseout=function(){
				this.className=this.className.replace(" over", "");
			} // function
		} // if
	} // for
} // function




function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
} 



/// if multi edit window is open, use this function to set it to draft and save when session expires.

function saveOurStuff(){
var draft = document.getElementById('draft');
var bounce = document.getElementById('bounceback');
draft.checked = true;
bounce.value = 'true';
showDaisy('AUTO SAVE<br />one moment');
document.multiform.submit();
}





function autoSave(intdelay,saveDraft){ // v 2.2.5
var draft = document.getElementById('draft');
var live = document.getElementById('live');
var multiform = document.getElementById('multiform');
if(saveDraft == 1){	
	live.checked = false;
	draft.checked = true;
}
multiform.target = 'saveHere';
document.multiform.submit();
multiform.target = '_self';
var TargetDate = "60";
var CountActive = true;
var CountStepper = -1;
var LeadingZero = true;
var DisplayFormat = "%%M%%:%%S%%";
var FinishMessage = "now";
var BackColor = "transparent";
CountBack(intdelay);
}






function resizeBox(element,targetWidth,targetHeight){
	var targetBox = document.getElementById(element);
	var boxWidth = parseInt(targetBox.style.width);
	var boxHeight = parseInt(targetBox.style.height);
	var newBoxWidth = boxWidth;
	var newBoxHeight = boxHeight;
	if(targetHeight == 'scroll') var targetHeight = targetBox.scrollHeight;
	if(targetHeight == 0) targetHeight = boxHeight;
	if(targetWidth == 0) targetWidth = boxWidth;
	var widthDiff = boxWidth-targetWidth;
	var heightDiff = boxHeight-targetHeight;
	if(widthDiff > 10 || heightDiff > 10 || widthDiff < -10 || heightDiff < -10){
		newBoxWidth = newBoxWidth-Math.round(widthDiff/10);
		newBoxHeight = newBoxHeight-Math.round(heightDiff/10);
		targetBox.style.width = newBoxWidth+'px';
		targetBox.style.height = newBoxHeight+'px';
		t1 = setTimeout("resizeBox('"+element+"',"+targetWidth+","+targetHeight+")",1);
	} else {
		 targetBox.style.width = targetWidth+'px';
		 targetBox.style.height = targetHeight+'px';
	}
}