var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 
var dialogWindow;
var debugWindow;
var cselrow = null;


function writeWhosOn(sGateway,sDomain,sDepartment,sResponse,sChatstart){
	var sSession;
	var sUrl;
	var dt=new Date();
	var sCookie=document.cookie.toString();
	
	if(sCookie.indexOf("whoson")==-1){
	    sSession=parseInt(Math.random()*1000)+"-"+dt.getTime();
	    document.cookie="whoson="+sSession+";expires=Fri, 31-Dec-2010 00:00:00 GMT;";}
	sCookie=document.cookie.toString();
	if(sCookie.indexOf('whoson')==-1){sSession="";}
	else{
	    var s=sCookie.indexOf("whoson=")+7;
	    var e=sCookie.indexOf(";",s);
	    if(e==-1)e=sCookie.length;
	    sSession=sCookie.substring(s,e);}
	sUrl=sGateway+"?u="+sSession+"&d="+sDomain;
	if(sDepartment.length>0)sUrl+="&t="+sDepartment;
	sUrl+="&p="+window.location+"&r="+escape(document.referrer);
	if(sResponse==""){
	    if(document.layers){document.write("<layer name=\"WhosOn\" visibility=hide><img src=\""+sUrl+"\" height=1 width=1></layer>");}
	    else{document.write("<div id=\"WhosOn\" STYLE=\"position:absolute;visibility:hidden;\"><img src=\""+sUrl+"\" height=1 width=1></div>");}}
	else {
	    sUrl+="&response=g";sChatstart+="?domain="+sDomain;
	    if(sDepartment.length>0)sChatstart+="&department="+sDepartment;
	    document.write("<a target=\"_blank\" href=\""+sChatstart+"\" onclick=\"javascript:window.open('"+sChatstart+"','new_win','width=484,height=361');return false;\"><img border=\"0\" src=\""+sUrl+"\"></a>");}
}



function FilterInterlock(name, value){
	var item = document.getElementById(name + value);
	var target = document.getElementById(name);
	var targetplaceholder = document.getElementById(name + '_placeholder');
	
	item.value = "" ;
	myString = new String(target.outerHTML)
	myString = myString.replace(target.innerHTML, "");
	mystring = myString.replace('><', '>' + item.innerHTML + '<');
	targetplaceholder.innerHTML = mystring;
}

function zzzFilterInterlock(name, value){
	
	var item = document.getElementById(name + value);
	var target = document.getElementById(name);
	var targetplaceholder = document.getElementById(name + '_placeholder');

	myString = new String(target.outerHTML)
	myString = myString.replace(target.innerHTML, "");
	mystring = myString.replace('><', '>' + item.innerHTML + '<');
	targetplaceholder.innerHTML = mystring;
	//for(var i=0; i<target.options.length; i++){
	//	target.options[i] = null;
	//}
	//if(item.options.length > 0){
	//	for(var i=0; i<item.options.length; i++){
	//		var sela = false;
	//		if(i==0){sela = true;}
	//		var option = new Option(item.options[i].text, item.options[i].value, false, sela);
	//		target.options[i] = option;
	//	}
	//}
}

function openDebug(path){
	var margin = 100;
	var height = 300;
	var width = screen.width - margin;
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var options = 'width=' + width + 'px,height=' + height + 'px,toolbar=no,scrollbars,left=' + winl + ',top=' + wint;
	try{debugWindow.close();}catch(e){}
	debugWindow = window.open(path + 'debug.html', 'debug', options);
}

function writeDebug(){
	try{debugWindow.debugdiv.innerHTML = window.debugdiv.innerHTML;}catch(e){}
}

function openDialog(path, mode, height, width){
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var options = 'width=' + width + 'px,height=' + height + 'px,toolbar=no,left=' + winl + ',top=' + wint;
	try{dialogWindow.close();}catch(e){}
	dialogWindow = window.open(path + '/siteadmin/dialog.aspx?mode=' + mode, 'dialog', options);
}

function openVisualEditor(path, mode){
	var margin = 100;
	var height = screen.height - margin;
	var width = screen.width - margin;
	var winl = (screen.width - width) / 2;
	var wint = ((screen.height - height) - 80) / 2;
	var options = 'width=' + width + 'px,height=' + height + 'px,toolbar=no,scrollbars,resizable,left=' + winl + ',top=' + wint;
	try{dialogWindow.close();}catch(e){}
	dialogWindow = window.open(path + '/siteadmin/dialog.aspx?mode=' + mode, 'dialog', options);
}

function FxWebselectRowChangeClass(row){
	for(var z=0; z<row.children.length; z++){
		if(row.children[z].oclass != undefined){
			row.children[z].className = row.children[z].oclass + '_sel';
		}
		FxWebselectRowChangeClass(row.children[z]);
	}
}

function FxWebselectRowChangeClassUnselect(row){
	for(var z=0; z<row.children.length; z++){
		if(row.children[z].oclass != undefined){
			row.children[z].className = row.children[z].oclass;
		}
		FxWebselectRowChangeClassUnselect(row.children[z]);
	}
}

function FxWebselectRow(row, db, position){
	if(cselrow != null){
		FxWebselectRowChangeClassUnselect(cselrow);
	}
	if(row != cselrow){
		FxWebselectRowChangeClass(row);
		var colList = eval(db + '_columnlist');
		var colArray = colList.split(',');
		for(var i=0; i<colArray.length-1; i++){
			var currentItem = document.getElementById(db + '.' + colArray[i]);
			var selectedItem = document.getElementById(db + '.' + colArray[i] + '.' + position);
			if(selectedItem.children.length > 0){
				currentItem.innerText = GetChildValue(selectedItem);
			}else{
				currentItem.innerText = selectedItem.innerText;
			}
			//alert(currentItem.innerText);
		}
		
		cselrow = row;
	}else{
		var colList = eval(db + '_columnlist');
		var colArray = colList.split(',');
		for(var i=0; i<colArray.length-1; i++){
			var currentItem = document.getElementById(db + '.' + colArray[i]);
			var selectedItem = document.getElementById(db + '.' + colArray[i] + '.' + position);
			currentItem.innerText = null;
		}
		cselrow = null;
	}
}

function GetChildValue(item){
	var value = "";
	for(var i=0; i<item.children.length; i++){
		if(item.children[i].alt == undefined){
			value = GetChildValue(item.children[i]);
		}else{
			value = item.children[i].alt;
		}
	}
	return value;
}



function paste(){
	var rng = document.selection.createRange();
	rng.execCommand('Paste');
}
function copy(){
	var rng = document.selection.createRange();
	rng.execCommand('Copy');
}
function cut(){
	var rng = document.selection.createRange();
	rng.execCommand('Cut');
}
function GetFileOverHTTP(file, xmlhttp){
	xmlhttp.open("GET", file, true);
	xmlhttp.send(null);
}
function SendFileOverHTTP(file, xmlhttp, contents){
	xmlhttp.open("POST", file, false);
	xmlhttp.send(contents);
}

function printFrame(frame) {
	if (pr && da) { // IE5
		parent.frames[frame].focus();
		parent.frames[frame].print();
	}else if (pr){ // NS4
		parent.frames[frame].print();
	}else if (da && !mac){ // IE4 (Windows)
		parent.frames[frame].focus();
		parent.frames[frame].print();
	} else { // other browsers
		alert("Sorry, your browser doesn't support this feature.");
	}
}

function togglemenu(){
	try{
		var item = document.getElementById('editormenubody');
		var img = document.getElementById('editormenuimage');
		if(item.style.display == 'none'){
			item.style.display = '';
			img.src = img.path + "toggle_up.gif";
		}else{
			item.style.display = 'none';
			img.src = img.path + "toggle_down.gif";
		}
	}catch(e){}
}

function moveeditormenu() {
	try{
		if (document.layers) {
	       	document.layers['editormenu'].pageX = window.pageXOffset + 10;
	        document.layers['editormenu'].pageY = window.pageYOffset + 10;
	    }
	    else if (document.all) {
	        document.all['editormenu'].style.position = 'absolute';
	        
	        if(document.all['editormenu'].style.posLeft <= document.body.scrollLeft){
	        	document.all['editormenu'].style.posLeft = document.body.scrollLeft + 10;
	        }
	        if(document.all['editormenu'].style.posTop <= document.body.scrollTop){
	        	document.all['editormenu'].style.posTop = document.body.scrollTop + 10;
	        }
	
			if(document.all['editormenu'].style.posTop > document.body.clientHeight + document.body.scrollTop){
				document.all['editormenu'].style.posTop = document.body.scrollTop + 10
			}
			
			if(document.all['editormenu'].style.posLeft > document.body.clientWidth + document.body.scrollLeft){
				document.all['editormenu'].style.posLeft = document.body.scrollLeft + 10
			}
	    }
	}catch(e){}
    setTimeout('moveeditormenu()',100);
}

var popupwindow;
var popup_width = '650px';
var popup_height = '400px';

function Popup(target, height, width){
	try{popupwindow.close();
	}catch(e){}
	
	var pHeight = popup_height;
	var pWidth = popup_width;
	var winl = (screen.width - width) / 2;
	var wint = ((screen.height - height) - 80) / 2;
	
	if(height != ''){pHeight = height;}
	if(width != ''){pWidth = width;}
	
	var settings = "scroll=no,toolbar=no,resizable=yes,width=" + pWidth + ",height=" + pHeight + ",left=" + winl + ",top=" + wint;
	popupwindow = window.open(appPath + "fxpopup.aspx?target=" + target , 'link', settings);
}

function SetPopupLocation(target){
	var a = null;
	while(a == null){
		try{
			a = popupwindow.document.getElementById('popup_body');
			a.src = appPath + target;
		}catch(e){}
	}
}
			
function CheckTab(el){
	if ((document.all) && (9==event.keyCode)) {
	    el.selection=document.selection.createRange(); 
	    setTimeout("ProcessTab('" + el.id + "')",0);
  	}
}

function ProcessTab(id) {
	document.all[id].selection.text=String.fromCharCode(9);
	document.all[id].focus();
}

function CheckForm(formitems){
	var req = true;	
	var fields = "";
	for(i=0; i<formitems.length; i++){
		var aa = document.getElementById(formitems[i]);
		if(aa.value == ''){
			req = false;
		}
	}
	if(!req){
		alert('All required must be completed.');
	}
	return req;
}


//Macromedia Javascript Functions
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_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_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_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];}
}