//-------------------------------------------------------------------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function popupEditWindow(obj,url_name,w,h,t,l){

if (obj=='scroll'){
	viewer=window.open(" ","remotewin","resizable=1,scrollbars='yes',width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}else{
	viewer=window.open(" ","remotewin2","resizable=1,scrollbars='yes',width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);

}

if (viewer.blur) viewer.focus();

viewer.location.href=url_name;
if(viewer.opener==null)viewer.opener=window;

}


//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function switchDiv(div1,div2){

	var obj1=document.getElementById(div1);
	var obj2=document.getElementById(div2);

	obj1.style.display='block';
	obj2.style.display='none';

}

// tick all thing for reportgen
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function selectAll(formName,typ,ext){

	var num=formName.elements.length
	for (i=0;i<num ;i++ )	{
		if (formName.elements[i].type.toLowerCase()=='checkbox')	{
			if (formName.elements[i].name.substring(0,ext.length)==ext){

				if (typ=='tick'){
					formName.elements[i].checked=true;
				}else{
					formName.elements[i].checked=false;
				}
			}
		}
	}
}


//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function flipMenus(show,hide1,hide2){

	flip(show + 'Div');
	flip(show + 'Up');
	flip(show + 'Down');

	obj=document.getElementById(show + 'Div');

	if (obj.style.display!='none'){

		var obj1=document.getElementById(hide1 + 'Div');
		var obj2=document.getElementById(hide1 + 'Up');
		var obj3=document.getElementById(hide1 + 'Down');

		obj1.style.display='none';
		obj2.style.display='none';
		obj3.style.display='block';

		var obj1=document.getElementById(hide2 + 'Div');
		var obj2=document.getElementById(hide2 + 'Up');
	  	var obj3=document.getElementById(hide2 + 'Down');

        if (obj1 != null){
			obj1.style.display='none';
			obj2.style.display='none';
			obj3.style.display='block';
		}
	}
}


// buttons float at side of screen
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function floatBtn(divName){
		var obj=document.getElementById(divName);
		if (obj!=null){
			obj.style.top=document.body.scrollTop+15;
		}
}



function putDate(){
	var now = new Date() ;
	var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday') ;
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December') ;
	var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

	today =  days[now.getDay()] + " " +
				  date + " " +
				   months[now.getMonth()] + ", " +
					(y2k(now.getYear()));
	document.write(today);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function y2k(number) { return (number < 1000) ? number + 1900 : number; }


//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function flip(divName){
	var obj=document.getElementById(divName);

	if (obj.style.display=='none')	{
		obj.style.display='block';
	}else{
		obj.style.display='none';
	}
}



//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function keyCap() { //v1.0
	if (navigator.appName != 'Netscape') {
		if (window.event.keyCode == 13){
			loginform.submit();
		}
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function showDiv(divName){
	var obj=document.getElementById(divName);
		obj.style.visibility='visible';
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function confirmLink(theLink, msg)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm( msg);


    return is_confirmed;
} // end of the 'confirmLink()' function

// for tree
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function showMenu( divNum,minusGif, plusGif,nodeChr){

    if (getIdProperty( nodeChr + divNum, "display") != "block" )
    {
        setIdProperty(nodeChr + divNum, "display", "block");
        document.images[nodeChr+ "img" + divNum].src = minusGif;
		document.cookie= nodeChr + "_" + divNum + '=y';
    }
    else
    {
        setIdProperty(nodeChr + divNum, "display", "none");
        document.images[nodeChr + "img" + divNum].src = plusGif;
		document.cookie=nodeChr + "_" + divNum + "=''; expires=Sun, 09-Nov-97 01:00:00";

    }
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function getIdProperty( id, property ){

        var styleObject = document.getElementById( id );
        if (styleObject != null){
            styleObject = styleObject.style;
            if (styleObject[property]) {
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;

}

// turns on all the hidden edit buttons.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function switchAllButtons(){


	for (i=0;i<document.images.length; i++){
		if (document.images[i].id.length>0){
			obj=document.getElementById(document.images[i].id);
			if (obj.style.display=='none')	{
				obj.style.display='block';
				document.cookie="btnsOn'=y'";
			}else{
				obj.style.display='none';
				document.cookie="btnsOn'=n'";
			}
		}
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function setIdProperty( id, property, value ){

        var styleObject = document.getElementById( id );
        if (styleObject != null){
            styleObject = styleObject.style;
            styleObject[ property ] = value;
       }
  }



//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function FlashInstalled()
{
	result = false;

	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
	{
		result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
	}
	else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
	{
		// IE Windows only -- check for ActiveX control, have to hide code in eval from Netscape (doesn't like try)
		eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)	result = true; xObj = null;	} catch (e)	{}');
	}

	return result;
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function FlashWrite(url,width,height)
{
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	document.write('  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ');
	document.write('  WIDTH=' + width + ' HEIGHT=' + height + '>');
	document.write(' <PARAM NAME=movie VALUE="' + url + '"> <PARAM NAME=quality VALUE=high> <PARAM NAME=salign VALUE=tl> <PARAM NAME=bgcolor VALUE=#FFFFFF>  ');
	document.write(' <EMBED salign="TL" src="' + url + '" quality=high bgcolor=#FFFFFF  ');
	document.write(' swLiveConnect=FALSE WIDTH=' + width + ' HEIGHT=' + height);
	document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
	document.write(' </EMBED></OBJECT>');
}




// ajax stuff - based on Richard's code.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------

function xhtmlresultcallback(responseArray,resultParams) {
	//alert(responseArray['errstring']);

	ctlip=document.getElementById(resultParams['inputFieldId']);
	if(responseArray['result']=='OK') {
		ctlip.style.color='green';
	} else {
	ctlip.style.color='red';

	outnode=document.getElementById(resultParams['resultSpaceId']);

	offset=responseArray['errbyte'];
	outnode.innerHTML=responseArray['report']+'<br />'+responseArray['errstring']+"<br /> <a href=\"javascript:highlightError('htmltemplate','"+offset+"')\">Attempt to highlight</a> (won't scroll!)<br /> To find the error, highlight it, hold down SHIFT, and press right-arrow<p><a href=\"javascript:auto_html_to_xhtml('" + resultParams['inputFieldId']  + "')\">Convert to (dirty) XHTML for manual fix</a> (may not change simple templates)</p>";
	}
}


//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function highlightError(ctl,offset) {
	selectRange(ctlip,offset-1,offset);
	ctlip.focus();
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function selectRange(ctl,from,to) {
	if( ctl.setSelectionRange ) {
		ctl.setSelectionRange(from,to);
	}
	else if( ctl.createTextRange ) {
		range = ctl.createTextRange();
		range.collapse(true);
		range.moveEnd('character',to);
		range.moveStart('character',from);
		range.select();
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function auto_html_to_xhtml(ctlid) {

	ctl=document.getElementById(ctlid);
	html=ctl.value;

	xhtml=html.replace(/<br>/g,'<br />');

	xhtml=xhtml.replace(/\n\s*\n/g,"\n");
	xhtml=xhtml.replace(/(<img\s[^>]+[" ])>/g,"$1 />");
	xhtml=xhtml.replace(/(<meta\s[^>]+[" ])>/g,"$1 />");
	ctl.value=xhtml;
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function xmlhttpPost(ajaxURL, queryString, resultFunc, resultParams) {

	var xmlHttpReq = false;


	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('POST', ajaxURL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			eval(resultFunc + '(xmlHttpReq.responseText, resultParams );');
		}
	}
	xmlHttpReq.send(queryString);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxValidateSingleInput(inputFieldId,resultSpaceId,ajaxURL,extraResponseHandler) {
// alert('VSA');

	inputField=document.getElementById(inputFieldId);
	queryString=(inputField.name+'='+escape(inputField.value));

	resultParams= new Array();
	resultParams['inputFieldId']=inputFieldId;
	resultParams['resultSpaceId']=resultSpaceId;
	resultParams['ajaxURL']=ajaxURL;
	resultParams['extraResponseHandler']=extraResponseHandler;

	xmlhttpPost(ajaxURL,queryString,'ajaxValidateSingleInputResponse',resultParams);

}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxValidateSingleInputResponse(rawResponse,resultParams) {
	var outstr='';
// alert(rawResponse);
//document.write(rawResponse);
	responseArray= new Array();
	responseLines=rawResponse.split("\n");
	numResponseLines=responseLines.length;
	for(i=0;i<numResponseLines;i++) {
		responseParts=responseLines[i].split("|");
		responseArray[responseParts[0]]=responseParts[1];
	}

	if(resultParams['resultSpaceId'].length) {
		resultSpace=document.getElementById(resultParams['resultSpaceId']);
		resultSpace.innerHTML=outstr+responseArray['report'];
	}
	if(resultParams['extraResponseHandler']) {
		eval(resultParams['extraResponseHandler'] + '(responseArray,resultParams);');
	}
}









//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxShowProcessList(resultSpaceId,ajaxURL){



	resultParams= new Array();
	resultParams['resultSpaceId']=resultSpaceId;
	resultParams['ajaxURL']=ajaxURL;

	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('POST', ajaxURL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			eval('stringToDiv(xmlHttpReq.responseText, resultParams );');
		}
	}
		xmlHttpReq.send('');	// we're not actually sending any params atm

	setTimeout("ajaxShowProcessList('" + resultSpaceId + "', '" + ajaxURL+  "')",1000);

}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function stringToDiv(str,resultParams) {
	outnode=document.getElementById(resultParams['resultSpaceId']);
	outnode.innerHTML=str;
}


//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxGeneric(resultSpaceId,ajaxURL){

	resultParams= new Array();
	resultParams['resultSpaceId']=resultSpaceId;
	resultParams['ajaxURL']=ajaxURL;

	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('POST', ajaxURL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			eval('stringToDiv(xmlHttpReq.responseText, resultParams );');
		}
	}
	xmlHttpReq.send('');

}

