/***********************************************
* Orax dataAPI Scripts
***********************************************/


var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;} 


// Auto Select Variables
var autocnt = 0;
var Sautocnt = 0;

var initm = function ( ) {
	// null;
	var subms=document.getElementById('sdimenu').getElementsByTagName("div");
    for (var t=0; t<subms.length; t++){
		if (subms[t].className != "men0") {
			subms[t].style.height = '0';
			subms[t].style.visibility = 'hidden';
		} 
	}
}


var togglem = function ( mdiv ) {
	if (mdiv.style.visibility == 'visible') {
		mdiv.style.height = '0px';
		mdiv.style.visibility = 'hidden';
		var subms=mdiv.getElementsByTagName("div");
		for (var t=0; t<subms.length; t++){
			subms[t].style.height = '0';
			subms[t].style.visibility = 'hidden';
		}
	} else {
		mdiv.style.height = '';
		mdiv.style.visibility = 'visible';
		if (mdiv.className == 'men1') {
			var subms=document.getElementById('sdimenu').getElementsByTagName("div");
			for (var t=0; t<subms.length; t++){
				if (subms[t].className != "men0" && subms[t] != mdiv) {
					subms[t].style.height = '0';
					subms[t].style.visibility = 'hidden';
				} 
			}
		} else if (mdiv.className == 'men2') {
			var subms=document.getElementById('sdimenu').getElementsByTagName("div");
			for (var t=0; t<subms.length; t++){
				if (subms[t].className != "men0" && subms[t].className != "men1" && subms[t] != mdiv) {
					subms[t].style.height = '0';
					subms[t].style.visibility = 'hidden';
				} 
			}
		}
	}
}



if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }


function makeitbold_test( textA ){
  var $tb = document.getElementById( textA );
 
  if (document.selection){
    var str=document.selection.createRange().text;
    var sel=document.selection.createRange();
    sel.text="<b>"+str+"</b>";
  }else if (typeof $tb.selectionStart != 'undefined'){
    var $before, $after, $selection;
    $before= $tb.value.substring(0, $tb.selectionStart)
    $selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd)
    $after = $tb.value.substring($tb.selectionEnd, $tb.value.length)
 
    $tb.value= String.concat($before, "<b>", $selection, "</b>", $after)
  }
   $tb.focus();
 
}


function AssignPosition(d,wid,hei) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	} else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	} else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}

	if(document.all) {
		cX += rX;
		cY += rY;
	}
	cX -= (50 + (wid / 2));
	cY -= 50;
	var xB = 800 - wid;
	var yB = 600 - hei;
	if (cX >= xB) { cX = xB; }
	if (cX < 50) { cX = 50; }
	if (cY >= yB) { cY = yB; }
	d.style.left = cX + "px";
	d.style.top = cY + "px";
}

var getStyle = function() {
	//loadSilent('skinloader','my_skin&&&&SILENT');
	//MM_preloadImages('images/side_menu_button.jpg','images/side_menu_roll.jpg','images/side_ex_button.jpg');
}

// ORAX XMLHttpRequest and DynamicDisplays




//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

function buildsubmenus(){
var menuids=["sdimenu"] //Enter id(s) of SuckerTree UL menus, separated by commas
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}




// Resize Text Areas
function resize_textarea(t) {
a = t.value.split('\n');
b=1;
for (x=0;x < a.length; x++) {
 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
 }
b+= a.length;
if (b > t.rows) t.rows = b;
}




var xPos, yPos;
var oraxLoadCnt = 0;

function oraxLoad(divID,url) {
	var xhr = false;
	oraxLoadCnt++;
	var xhrCnt = oraxLoadCnt;
	if (divID == '') { divID = 'sContent'; }
	var tDiv = document.getElementById(divID);
	tDiv.innerHTML = loading_flag;
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
	if (xhr) {
		xhr.open("GET", fullPath + url, true);
		xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200 && xhrCnt == oraxLoadCnt ) { tDiv.innerHTML = xhr.responseText; } }
		xhr.send(null);
	} else { tDiv.innerHTML = 'Error loading data!'; }	
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function showPreview(evt,trig,outMsg,onClick) {
	xPos = evt.clientX;
	yPos = evt.clientY;
	if( typeof( window.pageYOffset ) == 'number' ) {
    	rY = window.pageYOffset;
    	rX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    	rY = document.body.scrollTop;
    	rX = document.body.scrollLeft;
  	} else {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}
	xPos += rX;
	yPos += rY;
	var prevWin = document.getElementById('oraxPreview');
	prevWin.innerHTML = outMsg;
	prevWin.style.top = parseInt(yPos)+2 + "px";
	prevWin.style.left = parseInt(xPos)+12 + "px";
	prevWin.style.visibility = 'visible';
	
	if (onClick == 'onclick') {
		prevWin.onclick = function() {
			document.getElementById('oraxPreview').style.visibility = 'hidden';
		}
	} else {
		trig.onmouseout = function() {
			document.getElementById('oraxPreview').style.visibility = 'hidden';
		}
	}
}

// #### ORAX SCRIPT TO START MENUS and WIDGETS (Called from Footer)  ###################

function toggle_class_visible(theClass) {

    var allHTMLTags=document.getElementsByTagName('*');

    for (i=0; i<allHTMLTags.length; i++) {
	    if (allHTMLTags[i].className==theClass) {
    		if (allHTMLTags[i].style.display != 'none') { allHTMLTags[i].style.display ='none'; }
			else { allHTMLTags[i].style.display = ''; }
		}
    }
}



function autoSelect(sourceID,listDiv,target,formField) {
	var source = document.getElementById(sourceID);
	var autoFV = source.value;
	if (currentContent == 'sContent') { currentContent = listDiv; }
	if (autoFetchVal != autoFV && autoFV != '' && autoFV) { 
		oraxLoad(listDiv, target + '&' + autoFV + '&' + formField + '&' + listDiv + '&' + sourceID);
		autocnt = -1;
		Sautocnt = -1;
	}
	autoFetchVal = autoFV;
	autoFetchInput = source;
}

function autoItemMove( cnt ) {
	var oldI = document.getElementById('auto' + autocnt);
	autocnt  = autocnt + cnt;
	var newI = document.getElementById('auto' + autocnt);
	if (newI) { 
		if (oldI) { oldI.className = 'autoitem'; }
		newI.className = 'autoitems';
	} else { autocnt  = autocnt - cnt; }
}


function SautoItemMove( cnt ) {
	var oldI = document.getElementById('Sauto' + Sautocnt);
	Sautocnt  = Sautocnt + cnt;
	var newI = document.getElementById('Sauto' + Sautocnt);
	if (newI) { 
		if (oldI) { oldI.className = 'autoitem'; }
		newI.className = 'autoitems';
	} else { Sautocnt  = Sautocnt - cnt; }
}



var autoFetchVal = '';
var autoFetchInput = '';

function autoFetch(sourceID,listDiv,target,formField) {
	var source = document.getElementById(sourceID);
	var autoFV = source.value;
	if (currentContent == 'sContent') { currentContent = listDiv; }
	if (autoFetchVal != autoFV && autoFV != '' && autoFV) { 
		oraxLoad(listDiv, target + '&' + autoFV + '&' + formField + '&' + listDiv + '&' + sourceID);
	}
	autoFetchVal = autoFV;
	autoFetchInput = source;
}

function autoLookup( dynamicID, searchID, lookupID, ValID, DescID, Type, ForKey, ForCol ) {
	var source = document.getElementById(searchID);
	var autoFV = source.value;
	if (currentContent == 'sContent') { currentContent = dynamicID; }
	if (autoFetchVal != autoFV && autoFV != '' && autoFV) { 
		oraxLoad( lookupID, 'lookup&' + dynamicID + ';' + searchID + ';' + lookupID + ';' + ValID + ';' + DescID + ';' + autoFV + ';' + Type + ';' + ForKey + ';' + ForCol);
		autocnt = -1;
	}
	autoFetchVal = autoFV;
	autoFetchInput = source;
}


function loadfile( lookupID, ValID ) {
	
	var lD = document.getElementById(lookupID);
	if (currentContent == 'sContent') { currentContent = lookupID; }
	if (lD.style.visibility == 'hidden') {
		lD.style.height = '';
		lD.style.visibility = '';
		lD.innerHTML = loading_flag;
		var Value = document.getElementById(ValID).value;
		Spry.Utils.updateContent( lookupID, fullPath + 'loadfile&' + lookupID + ';' + ValID);
	} else {
		lD.innerHTML = '';
		lD.style.visibility = 'hidden';
		lD.style.height = '0';
	}

}


function hlookup( lookupID, ValID, DescID, Type, ForKey, ForCol ) {
	
	var lD = document.getElementById(lookupID);
	if (currentContent == 'sContent') { currentContent = lookupID; }
	if (lD.style.visibility == 'hidden') {
		lD.style.height = '';
		lD.style.visibility = '';
		lD.innerHTML = loading_flag;
		var Value = document.getElementById(ValID).value;
		Spry.Utils.updateContent( lookupID, fullPath + 'hlookup&' + lookupID + ';' + ValID + ';' + DescID + ';' + Value + ';' + Type + ';' + ForKey + ';' + ForCol);
	} else {
		lD.innerHTML = '';
		lD.style.visibility = 'hidden';
		lD.style.height = '0';
	}

}

function lookup( lookupID, ValID, DescID, Type, ForKey, ForCol ) {
	
	var lD = document.getElementById(lookupID);
	if (lD.style.visibility == 'hidden') {
		lD.style.height = '';
		lD.style.visibility = '';
		lD.innerHTML = loading_flag;
		var Value = document.getElementById(ValID).value;
		Spry.Utils.updateContent( lookupID, fullPath + 'lookup&' + lookupID + ';' + ValID + ';' + DescID + ';' + Value + ';' + Type + ';' + ForKey + ';' + ForCol);
	} else {
		lD.innerHTML = '';
		lD.style.visibility = 'hidden';
		lD.style.height = '0';
	}

}
 
function link_many( lookupID, DescID, Type, ForKey, ForCol, recID ) {
	
	var lD = document.getElementById(lookupID);
	if (currentContent == 'sContent') { currentContent = lookupID; }
	if (lD.style.visibility == 'hidden') {
		lD.style.height = '';
		lD.style.visibility = '';
		lD.innerHTML = loading_flag;
		Spry.Utils.updateContent( lookupID, fullPath + 'list_links&' + lookupID + ';' + DescID + ';' + Type + ';' + ForKey + ';' + ForCol + ';' + recID);
	} else {
		lD.innerHTML = '';
		lD.style.visibility = 'hidden';
		lD.style.height = '0';
	}

}
 

function showNotices( ) {
  var helpC = document.getElementById('noticeContent');
  if (helpC.innerHTML == '') {
	  helpC.style.height = '';
	  helpC.style.visibility = '';
	  //helpC.innerHTML = 'Loading messages...';
	  document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>';
	  Spry.Utils.updateContent('noticeContent', fullPath + 'rs24hD0z42a4d40dc71ff5944d911df39350ad16efee0eab46f9d10cfd42a48401fa4af9df0fab40aed60aaa45fddf5faf40a5835dff');
  } else {
	  helpC.innerHTML = '';
	  helpC.style.visibility = 'hidden';
	  helpC.style.height = '0';
  }
}

function showHelp( ) {
  var helpC = document.getElementById('helpContent');
  if (helpC.innerHTML == '') {
	  helpC.style.height = '';
	  helpC.style.visibility = '';
	  //helpC.innerHTML = 'Loading help...';
	  document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>';
	  //loadContent('helpContent','show_help&' + helpTarget);
	  Spry.Utils.updateContent('helpContent', fullPath + 'show_help&' + helpTarget);
  } else {
	  helpC.innerHTML = '';
	  helpC.style.visibility = 'hidden';
	  helpC.style.height = '0';
  }
}

function showFloating( divID, width, height, target ) {
		//var floatWin=dhtmlwindow.open("floatDiv", "inline", "<div id=\"" + divID + "Content\">Loading...</div>", "New", "width=" + width + "px,height=" + height + "px,left=250px,top=200px,resize=1,scrolling=1", "recal");
		
		var floatWin=dhtmlwindow.open('divbox', 'div', divID, 'New', 'width=450px,height=300px,left=200px,top=150px,resize=1,scrolling=1');
		Spry.Utils.updateContent( divID + 'Content', fullPath + target);
		//AssignPosition(floatWin,width,height);
		//var floatWin=dhtmlwindow.open("popUpFloater", "ajax", fullPath + target, "#3: Ajax Win Title", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
		}

function showFloating_old( divID, width, height, target ) {
		var fDiv = document.getElementById(divID);
		fDiv.style.overflow = 'scroll';
		AssignPosition(fDiv,width,height);
		fDiv.style.height = height + 'px';
		fDiv.style.width = width + 'px';
		fDiv.style.visibility = '';
		fDiv.innerHTML = '<a href="javascript:void(0);" id=\"floatclose\" onclick="document.getElementById(\'' + divID + '\').style.visibility = \'hidden\';">Close</a><a href="javascript:void(0);" id=\"up\" onclick=\"var Flt = document.getElementById(\'' + divID + '\'); Flt.style.top = parseInt(Flt.style.top) - 50 + \'px\';\">up</a><a href="javascript:void(0);" id=\"dwn\" onclick=\"var Flt = document.getElementById(\'' + divID + '\'); Flt.style.top = parseInt(Flt.style.top) + 50 + \'px\';\">down</a><a href="javascript:void(0);" id=\"lft\" onclick=\"var Flt = document.getElementById(\'' + divID + '\'); Flt.style.left = \'0px\';\">left</a><a href="javascript:void(0);" id=\"rght\" onclick=\"var Flt = document.getElementById(\'' + divID + '\'); Flt.style.left = parseInt(Flt.style.left) + 50 + \'px\';\">right</a><a href="javascript:void(0);" id=\"stick\" onclick=\"document.getElementById(\'stick\').mouseout = function () { alert(\'test\'); }\">stick</a><div id="' + divID + 'Content">' + loading_flag + '</div>';
		fDiv.style.position = 'absolute';
		fDiv.style.zIndex = '10000';
}

function printPage( ) { 
   	var print_win = window.open( '/portal/indexr.app?rs24hD0z47acd500c703ee8e57ba2cec865eab7aab820cab45a9d408f610a4d300ab4baa820afc42af830faf4bfa860af717f8d6', 'Print','menubar=0,scrollbars=1,resizable=0,width=710,height=680,left=20,top=20');
}

 

// #### SPRY FORM NUMBER VALIDATION ###################

var IsNumeric = function(value, options) {
   var ValidChars = "0123456789.- ";
   var IsNumber=true;
   var Char;
   for (i = 0; i < value.length && IsNumber == true; i++) {
      Char = value.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
   }
   return IsNumber;
}

var IsDateTime = function(iDate, options) {
   var IsValid=true;
   var day    = iDate.substring(0,2);
   var month  = iDate.substring(3,5);
   var year   = iDate.substring(6,11);
   var hour   = iDate.substring(11,13);
   var minute = iDate.substring(14,16);
   var maxDay = 1;
   var nMonth = month * 1;
   var nYear  = year * 1;
   
   switch (nMonth) {
						case 1:	// January
						case 3: // March
						case 5: // May
						case 7: // July
						case 8: // August
						case 10: // October
						case 12: // December
							maxDay = 31;
							break;
						case 4:	// April
						case 6: // June
						case 9: // September
						case 11: // November
							maxDay = 30;
							break;
						case 2: // February
							if ((parseInt(nYear/4, 10) * 4 == nYear) && (nYear % 100 != 0 || nYear % 400 == 0)) {
								maxDay = 29;
							} else {
								maxDay = 28;
							}
							break;
					}
					
   if (day <= 0 || day > maxDay) { IsValid = false; }
   if (month > 12 || month <= 0) { IsValid = false; }
   if (year > 2011 || year <= 2006) { IsValid = false; }
   if (hour > 23 || hour < 0) { IsValid = false; }
   if (minute > 59 || minute < 0) { IsValid = false; }
   
   
   
   return IsValid;
}


// #### SPRY FORM PASSWORD VALIDATION ###################

var passwordStrength = function(value, options){

	if (value.length < 8 || value.length > 10)
		return false;

	if (value.replace(/[^0-9]*/ig, '').length < 2)
		return false;
	
	if (value.replace(/[^a-z]/ig, '').length < 2)
		return false;

	if (value.replace(/[0-9a-z]/ig, '').length == 0)
		return false;

	return true;
}

var passwordTheSame = function(value, options){
	var other_value = document.getElementById('text212').value;
	if (value != other_value){
		return false;
	}
	return true;
}



// #### SPRY FORM PASSWORD VALIDATION ###################

var characterCorrect = function(id, value, options) {

//if ( value.search(/`/) >= 0 ) { var tempstr = id.value; var newstr = tempstr.replace(/`/gi, \"&rsquo;\"); id.value = newstr;  }
//if ( value.search(/'/) >= 0 ) { var tempstr = id.value; var newstr = tempstr.replace(/'/gi, \"&rsquo;\"); document.ins.$iname.value = newstr;  }
//if ( value.search(/\"/) >= 0 ) { var tempstr = document.ins.$iname.value; var newstr = tempstr.replace(/\"/gi, \"&quot;\"); document.ins.$iname.value = newstr;  }
//if ( value.search(/\\|/) >= 0 ) { subcnt = 'yes'; alert('$ilabel has an invalid character!  Please remove the \"\|\"'); }";
//if ( value.search(/\\+/) >= 0 ) { var tempstr = document.ins.$iname.value; var newstr = tempstr.replace(/\\+/gi, \"&#43;\"); document.ins.$iname.value = newstr;  }

}




// #### LEGACY NEW WINDOWS ###################

 function new_cs_win( targ ) { 
   cs_win = window.open( targ,"Search","menubar=0,scrollbars=yes,resizable=yes,width=400,height=620,left=50,top=50")
 }

 function print_window ( icode, doc_type ) {
   print_win = window.open( '/portal/print_doc.app?$employer&' + doc_type + '&' + icode + '&NOLOG', 'Print','menubar=0,scrollbars=1,resizable=0,width=710,height=680,left=20,top=20')
 }

 function approve_window ( icode ) {
   email_win = window.open( '/portal/approve_email.app?$employer&' + doc_type + '&' + icode, 'Email','menubar=0,scrollbars=1,resizable=0,width=650,height=680,left=20,top=20')
 }


 function email_window ( icode, doc_type ) {
   email_win = window.open( '/portal/doc_email.app?$employer&' + doc_type + '&' + icode, 'Email','menubar=0,scrollbars=1,resizable=0,width=650,height=680,left=20,top=20')
 }


 
 function htmlSave( source, target ) {
  var cont = document.getElementById( source ).innerHTML;
  document.getElementById( target ).innerHTML = cont;
 }

function get_date( targ, cvalue ) {
  dt_win = window.open( targ+'&'+cvalue ,"Date","menubar=0,scrollbars=0,resizable=yes,width=320,height=280,left=300,top=200")
 }
function get_datetime( targ, cvalue ) {
  dt_win = window.open( targ+'&'+cvalue ,"Time","menubar=0,scrollbars=0,resizable=yes,width=320,height=360,left=300,top=200")
 }
 

function SetCookie(cookieName,cookieValue,nDays,cUrl) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = 'UNAME=' + escape(cookieName) + ";expires="+expire.toGMTString() + "; path=/; secure";
 document.cookie = 'SESSID=' + escape(cookieValue) + ";expires="+expire.toGMTString() + "; path=/; secure";
}



// ###############  SPRY ROLLOVER IMAGES #############################

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_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];}
}




// ###############  SPRY DYNAMIC FORM SUBMISSION #############################


var myUrl = '';
var ieLink = 0;
var myUrla = window.location.href.split( '/' ); myUrl = myUrla[0] + '//' + myUrla[2];
var currentURL 	= 'my_space';
var reloadURL  	= currentURL;
var backURL 	= currentURL;
var backURL1 	= currentURL;
var backURL2 	= currentURL;
var backURL3 	= currentURL;
var backURL4 	= currentURL;
var backURL5 	= currentURL;
var forwURL 	= currentURL;
var forwURL1 	= currentURL;
var forwURL2 	= currentURL;
var forwURL3 	= currentURL;
var forwURL4 	= currentURL;
var forwURL5 	= currentURL;
var loading_flag = '<img src="/images/loader_small.gif" width="26" height="24" alt="loading" border="0" />';
var currentContent = 'sContent';
var helpTarget	= 'my_space';
var pageStyle = '/css/main.css';
var submitURL = '/portal/xContent.app?&show_page&submit';
var fullPath = '/portal/xContent.app?';
var log_stat;
var formSubmitTarget = 'sContent';
var elementList = new Array(80);
var listNew = 0;
var linkCounter = 0;
var currentTime = new Date();
var logonTime = currentTime.getDate() + '.' + currentTime.getHours() + '.' + currentTime.getMinutes() + '.' + currentTime.getSeconds() + '.';

var replaceIllegal = function(form) {
	var listNum = 0;
	do {
		var thisEle = document.getElementById(elementList[listNum]);
		if (thisEle) {
			var newTxt  = thisEle.value;
			if (newTxt.search(/\|/) != -1) { newTxt  = newTxt.replace(/\|/gi, '[PIPE]'); };
			
			if (thisEle.id.search(/_txt/) != -1) {
				if (newTxt.search(/`/) != -1) { newTxt  = newTxt.replace(/`/gi, '&rsquo;'); }
				if (newTxt.search(/'/) != -1) { newTxt  = newTxt.replace(/'/gi, '&#39;'); }
				if (newTxt.search(/"/) != -1) { newTxt  = newTxt.replace(/\"/gi, '&quot;'); }
				if (newTxt.search(/\+/) != -1) { newTxt  = newTxt.replace(/\+/gi, '&#43;'); }
				//alert(thisEle.id + ' is a text field');
			} else if (thisEle.id.search(/_cde/) != -1) {
				if (newTxt.search(/`/) != -1) { newTxt  = newTxt.replace(/`/gi, '&rsquo;'); }
				if (newTxt.search(/'/) != -1) { newTxt  = newTxt.replace(/'/gi, '&#39;'); }
				if (newTxt.search(/"/) != -1) { newTxt  = newTxt.replace(/\"/gi, '&quot;'); }
				if (newTxt.search(/\+/) != -1) { newTxt  = newTxt.replace(/\+/gi, '&#43;'); }
				if (newTxt.search(/\-/) != -1) { newTxt  = newTxt.replace(/\-/gi, ''); }
				//alert(thisEle.id + ' is a code');
			} else if (thisEle.id.search(/_tarea/) != -1) {
				//if (newTxt.search(/'/) != -1) { newTxt  = newTxt.replace(/'/gi, '&#39;'); }
				//alert(thisEle.id + ' is a textarea');
			} else {
				//alert(thisEle.id + ' is other');
			}
				
			thisEle.value = newTxt;
		}
		listNum++;
	} while (elementList[listNum]);
}

function updateResponseDiv(req) {
       Spry.Utils.setInnerHTML(formSubmitTarget,req.xhRequest.responseText);
       document.getElementById('head_center').innnerHTML = log_stat;
	   formSubmitTarget = 'sContent';
}

var validateonsubmit = function(form,targetDiv) {
	
	var taids=document.getElementsByTagName("textarea")
	for (var i=0; i<taids.length; i++){ 
		if (tinyMCE.getInstanceById(taids[i].id)) tinyMCE.execCommand('mceRemoveControl', false, taids[i].id);
	}
	
	replaceIllegal(form);
	formSubmitTarget = targetDiv;
	
			
    var ret = Spry.Widget.Form.validate(form);
    if (ret){
        log_stat = document.getElementById('head_center').innerHTML;
        //document.getElementById('head_center').innerHTML = '<p>Sending...</p>';
        document.getElementById('head_center').innerHTML = loading_flag;
        Spry.Utils.submitForm(form, updateResponseDiv);
     }
     return false;
};


function removeNotice (ndiv) {
	if (document.getElementById(ndiv)) { document.getElementById(ndiv).innerHTML = ''; }
}

var SubmitNotice = function(ndiv,nText) {
	document.getElementById(ndiv).innerHTML = '<p><span id="SubmitNotice">' + nText + '</span></p>';
	setTimeout("removeNotice('" + ndiv + "')",2000);
}

function reload() {
	//oraxLoad('sContent',currentURL);
	document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>';
	Spry.Utils.updateContent('sContent', fullPath + currentURL);
}

function goBack() {
	document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>';
	Spry.Utils.updateContent('sContent', fullPath + backURL);
	//oraxLoad('sContent',backURL);
	
	forwURL5 = forwURL4;
	forwURL4 = forwURL3;
	forwURL3 = forwURL2;
	forwURL2 = forwURL1;
	forwURL1 = forwURL;
	forwURL  = currentURL;
	
	currentURL = backURL;
	backURL = backURL1;
	backURL1 = backURL2;
	backURL2 = backURL3;
	backURL3 = backURL4;
	backURL4 = backURL5;
	backURL5 = '';
}

function goForward() {
	document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>';
	Spry.Utils.updateContent('sContent', fullPath + forwURL);
	//oraxLoad('sContent',forwURL);
	
	backURL5 = backURL4;
	backURL4 = backURL3;
	backURL3 = backURL2;
	backURL2 = backURL1;
	backURL1 = backURL;
	backURL  = currentURL;
	
	currentURL = forwURL;
	forwURL  = forwURL1;
	forwURL1 = forwURL2;
	forwURL2 = forwURL3;
	forwURL3 = forwURL4;
	forwURL4 = forwURL5;
}

// ###############  SPRY DYNAMIC CONTENT #############################

function loadContent(ele,url,dummyCounter){

        linkCounter++;
		currentContent = ele;
        //document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>';
        document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>';
        
	Spry.Utils.updateContent(ele, fullPath + url + 'DDSF44SLW' + linkCounter);
							 
				
		if (document.getElementById('divbox')) { document.getElementById('divbox').style.display = 'none'; }
		if (document.getElementById('calendarDiv')) { closeCalendar(); }
		if (ele == 'sContent') {
			if (backURL != currentURL) { 
				backURL5 = backURL4;
				backURL4 = backURL3;
				backURL3 = backURL2;
				backURL2 = backURL1;
				backURL1 = backURL;
				backURL = currentURL;
			}
        	currentURL = url;
			reloadURL  = currentURL;
			helpTarget  = currentURL;
		}
		
		// Hide help
		if (document.getElementById('helpContent')) {
			var helpC = document.getElementById('helpContent');
			if (helpC.innerHTML != '') {
				helpC.innerHTML = '';
				helpC.style.visibility = 'hidden';
				helpC.style.height = '0';
			}
		}
		// Hide Popups
		if (document.getElementById('oraxPreview').style.visibility == 'visible') {
			document.getElementById('oraxPreview').style.visibility = 'hidden';
		}
}

function openContent(url){
		window.open( url,"New")
}

function loadSilent(ele,url,safe){

        linkCounter++;
	Spry.Effect.DoFade(ele,{ duration: 500, from: 100, to: 0, finish: function() {
		Spry.Utils.updateContent(ele, fullPath + url + '&&&&&' + logonTime + linkCounter, function() { Spry.Effect.DoFade(ele,{ duration: 500, from: 0, to: 100 }); }); }
        });
        // since it is async - no good. if ( document.getElementById(ele).innerHTML == '' && safe != '' ) { document.getElementById(ele).innerHTML = safe; }
}


// ###############  SORT PRESENT QUERY FUNCTIONS #############################

var orderDiv;

function updateOrderDiv(req) {
       Spry.Utils.setInnerHTML(orderDiv,req.xhRequest.responseText);
       document.getElementById('head_center').innnerHTML = log_stat;
       //document.getElementById('contentTop').innerHTML = '';
}

function toggle_sort( col, order, orderdiv, notoggle ) {

   orderDiv = orderdiv;
   var orddr = order.orddir.value;
   var ordcl = order.ordcol.value;
   if (notoggle != 'NOTOGGLE') {
	   if (orddr == 'DESC') { orddr = 'ASC'; } else { orddr = 'DESC'; }
	   if (ordcl != col) { orddr = 'ASC'; } 
   }
   order.orddir.value = orddr;
   order.ordcol.value = col;

   document.getElementById('head_center').innerHTML = '<p>' + loading_flag + '</p>'; //'<p>Sorting...</p>';
   //document.getElementById('contentTop').innerHTML = '<img src="/images/loader_small.gif" width="31" height="29" alt="loading" border="0" />';

   Spry.Utils.submitForm(order, updateOrderDiv);
   return false;
 

}

function toggle_add_column(col, order, orderdiv ) {
	var tempq = order.query.value; 
	var tempqn = tempq.replace(' from',', ' + order.add_field.value + ' from'); 
	order.query.value = tempqn;
	var temphl = order.add_field.options[order.add_field.selectedIndex].text;
	var temph = order.colhd.value; temphn = temph + '\|' + temphl + ':50'; 
	order.colhd.value = temphn; 
	toggle_sort( 1, order, orderdiv );
}



function toggle_hide_column(col, order, orderdiv ) {
	var tempx = order.excol.value; 
	order.excol.value = tempx + ',' + col; 
	//alert(order.excol.value);
	toggle_sort( 1, order, orderdiv );
}


function toggle_add_filter(col, order, orderdiv ) {
	var tempf = order.mfilter.value; 
	var ncol  = order.add_filter.value; 
	var nop   = order.add_filter_op.value; 
	var nval  = order.add_filter_val.value; 
	var ncond = ncol + nop + '\'' + nval + '\' and ';
	order.mfilter.value = tempf + ncond;
	toggle_sort( 1, order, orderdiv );
}

function toggle_del_filter(col, order, orderdiv ) {
	var tempf = order.mfilter.value; 
	var tempo = col.replace(/sMs/g, '\'');
	var temp2 = tempf.replace(tempo + ' and ', '');
	//alert('"' + tempf + '" , "' + tempo + '"');
	order.mfilter.value = temp2;
	toggle_sort( 1, order, orderdiv );
}

function toggle_save_query( order, orderdiv ) {
	document.getElementById('save_q').innerHTML = 'Hello World';
}

function toggle_update_query(col, order, orderdiv ) {
	var tempq = order.cquery.value; 
	order.query.value = tempq;
	toggle_sort( 1, order, orderdiv );
}


// ###############  LEGACY FUNCTIONS #############################

function validate_number( nm, vall, nm2, nulla ) {
  if (nm/nm != 1 && nm != 0) { alert("Not a number!")
                    nm2.select() }
  if (nm > vall) { alert("Value too large!")
                   nm2.select() }
  if (nulla == '' && nm == '') { alert("This field is required!")
                   nm2.select() }
}

function check_required( nm, nm2, nulla ) {
  //if (nulla == '' && nm == '') { alert("This field is required!")
  //                nm2.select() }
}



var myFilterFunc = function(dataSet, row, rowNumber)
{
	if (row["name"].search(/.s/) != -1)
		return row; 
	return null; 
}

var firstFive = function(dataSet, row, rowNumber)
{
	if (row["ds_RowID"] <= 5)
		return row; 
	return null; 
}




// -------------------------------------------------------------------
// DHTML Window Widget- By Dynamic Drive, available at: http://www.dynamicdrive.com
// v1.0: Script created Feb 15th, 07'
// v1.01: Feb 21th, 07' (see changelog.txt)
// v1.02: March 26th, 07' (see changelog.txt)
// v1.03: May 5th, 07' (see changelog.txt)
// v1.1:  Oct 29th, 07' (see changelog.txt)
// -------------------------------------------------------------------

var dhtmlwindow={
imagefiles:['/images/min.gif', '/images/close.gif', '/images/restore.gif', '/images/resize.gif', '/images/max.gif'], //Path to 4 images used by script, in that order
ajaxbustcache: true, //Bust caching when fetching a file via Ajax?
ajaxloadinghtml: '<b>Loading Page. Please wait...</b>', //HTML to show while window fetches Ajax Content?

minimizeorder: 0,
zIndexvalue:10000,
tobjects: [], //object to contain references to dhtml window divs, for cleanup purposes
lastactivet: {}, //reference to last active DHTML window

init:function(t){
	var domwindow=document.createElement("div") //create dhtml window div
	domwindow.id=t
	domwindow.className="dhtmlwindow"
	var domwindowdata=''
	domwindowdata='<div class="drag-handle">'
	domwindowdata+='DHTML Window <div class="drag-controls"><img src="'+this.imagefiles[0]+'" title="Minimize" /><img src="'+this.imagefiles[4]+'" title="Maximize" /><img src="'+this.imagefiles[1]+'" title="Close" /></div>'
	domwindowdata+='</div>'
	domwindowdata+='<div class="drag-contentarea"></div>'
	domwindowdata+='<div class="drag-statusarea"><div class="drag-resizearea" style="background: transparent url('+this.imagefiles[3]+') top right no-repeat;">&nbsp;</div></div>'
	domwindowdata+='</div>'
	domwindow.innerHTML=domwindowdata
	document.getElementById("dhtmlwindowholder").appendChild(domwindow)
	//this.zIndexvalue=(this.zIndexvalue)? this.zIndexvalue+1 : 100 //z-index value for DHTML window: starts at 0, increments whenever a window has focus
	var t=document.getElementById(t)
	var divs=t.getElementsByTagName("div")
	for (var i=0; i<divs.length; i++){ //go through divs inside dhtml window and extract all those with class="drag-" prefix
		if (/drag-/.test(divs[i].className))
			t[divs[i].className.replace(/drag-/, "")]=divs[i] //take out the "drag-" prefix for shorter access by name
	}
	//t.style.zIndex=this.zIndexvalue //set z-index of this dhtml window
	t.handle._parent=t //store back reference to dhtml window
	t.resizearea._parent=t //same
	t.controls._parent=t //same
	t.onclose=function(){return true} //custom event handler "onclose"
	t.onmousedown=function(){dhtmlwindow.setfocus(this)} //Increase z-index of window when focus is on it
	t.handle.onmousedown=dhtmlwindow.setupdrag //set up drag behavior when mouse down on handle div
	t.resizearea.onmousedown=dhtmlwindow.setupdrag //set up drag behavior when mouse down on resize div
	t.controls.onclick=dhtmlwindow.enablecontrols
	t.show=function(){dhtmlwindow.show(this)} //public function for showing dhtml window
	t.hide=function(){dhtmlwindow.hide(this)} //public function for hiding dhtml window
	t.close=function(){dhtmlwindow.close(this)} //public function for closing dhtml window (also empties DHTML window content)
	t.setSize=function(w, h){dhtmlwindow.setSize(this, w, h)} //public function for setting window dimensions
	t.moveTo=function(x, y){dhtmlwindow.moveTo(this, x, y)} //public function for moving dhtml window (relative to viewpoint)
	t.isResize=function(bol){dhtmlwindow.isResize(this, bol)} //public function for specifying if window is resizable
	t.isScrolling=function(bol){dhtmlwindow.isScrolling(this, bol)} //public function for specifying if window content contains scrollbars
	t.load=function(contenttype, contentsource, title){dhtmlwindow.load(this, contenttype, contentsource, title)} //public function for loading content into window
	this.tobjects[this.tobjects.length]=t
	return t //return reference to dhtml window div
},

open:function(t, contenttype, contentsource, title, attr, recalonload){
	var d=dhtmlwindow //reference dhtml window object
	function getValue(Name){
		var config=new RegExp(Name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,)
		return (config.test(attr))? parseInt(RegExp.$1) : 0 //return value portion (int), or 0 (false) if none found
	}
	if (document.getElementById(t)==null) //if window doesn't exist yet, create it
		t=this.init(t) //return reference to dhtml window div
	else
		t=document.getElementById(t)
	this.setfocus(t)
	t.setSize(getValue(("width")), (getValue("height"))) //Set dimensions of window
	var xpos=getValue("center")? "middle" : getValue("left") //Get x coord of window
	var ypos=getValue("center")? "middle" : getValue("top") //Get y coord of window
	//t.moveTo(xpos, ypos) //Position window
	if (typeof recalonload!="undefined" && recalonload=="recal" && this.scroll_top==0){ //reposition window when page fully loads with updated window viewpoints?
		if (window.attachEvent && !window.opera) //In IE, add another 400 milisecs on page load (viewpoint properties may return 0 b4 then)
			this.addEvent(window, function(){setTimeout(function(){t.moveTo(xpos, ypos)}, 400)}, "load")
		else
			this.addEvent(window, function(){t.moveTo(xpos, ypos)}, "load")
	}
	t.isResize(getValue("resize")) //Set whether window is resizable
	t.isScrolling(getValue("scrolling")) //Set whether window should contain scrollbars
	t.style.visibility="visible"
	t.style.display="block"
	t.contentarea.style.display="block"
	t.moveTo(xpos, ypos) //Position window
	t.load(contenttype, contentsource, title)
	if (t.state=="minimized" && t.controls.firstChild.title=="Restore"){ //If window exists and is currently minimized?
		t.controls.firstChild.setAttribute("src", dhtmlwindow.imagefiles[0]) //Change "restore" icon within window interface to "minimize" icon
		t.controls.firstChild.setAttribute("title", "Minimize")
		t.state="fullview" //indicate the state of the window as being "fullview"
	}
	return t
},

setSize:function(t, w, h){ //set window size (min is 150px wide by 100px tall)
	t.style.width=Math.max(parseInt(w), 150)+"px"
	t.contentarea.style.height=Math.max(parseInt(h), 100)+"px"
},

moveTo:function(t, x, y){ //move window. Position includes current viewpoint of document
	this.getviewpoint() //Get current viewpoint numbers
	t.style.left=(x=="middle")? this.scroll_left+(this.docwidth-t.offsetWidth)/2+"px" : this.scroll_left+parseInt(x)+"px"
	t.style.top=(y=="middle")? this.scroll_top+(this.docheight-t.offsetHeight)/2+"px" : this.scroll_top+parseInt(y)+"px"
},

isResize:function(t, bol){ //show or hide resize inteface (part of the status bar)
	t.statusarea.style.display=(bol)? "block" : "none"
	t.resizeBool=(bol)? 1 : 0
},

isScrolling:function(t, bol){ //set whether loaded content contains scrollbars
	t.contentarea.style.overflow=(bol)? "auto" : "hidden"
},

load:function(t, contenttype, contentsource, title){ //loads content into window plus set its title (3 content types: "inline", "iframe", or "ajax")
	if (t.isClosed){
		alert("DHTML Window has been closed, so no window to load contents into. Open/Create the window again.")
		return
	}
	var contenttype=contenttype.toLowerCase() //convert string to lower case
	if (typeof title!="undefined")
		t.handle.firstChild.nodeValue=title
	if (contenttype=="inline")
		t.contentarea.innerHTML=contentsource
	else if (contenttype=="div"){
		var inlinedivref=document.getElementById(contentsource)
		t.contentarea.innerHTML=(inlinedivref.defaultHTML || inlinedivref.innerHTML) //Populate window with contents of inline div on page
		if (!inlinedivref.defaultHTML)
			inlinedivref.defaultHTML=inlinedivref.innerHTML //save HTML within inline DIV
		inlinedivref.innerHTML="" //then, remove HTML within inline DIV (to prevent duplicate IDs, NAME attributes etc in contents of DHTML window
		inlinedivref.style.display="none" //hide that div
	}
	else if (contenttype=="iframe"){
		t.contentarea.style.overflow="hidden" //disable window scrollbars, as iframe already contains scrollbars
		if (!t.contentarea.firstChild || t.contentarea.firstChild.tagName!="IFRAME") //If iframe tag doesn't exist already, create it first
			t.contentarea.innerHTML='<iframe src="" style="margin:0; padding:0; width:100%; height: 100%" name="_iframe-'+t.id+'"></iframe>'
		window.frames["_iframe-"+t.id].location.replace(contentsource) //set location of iframe window to specified URL
		}
	else if (contenttype=="ajax"){
		this.ajax_connect(contentsource, t) //populate window with external contents fetched via Ajax
	}
	t.contentarea.datatype=contenttype //store contenttype of current window for future reference
},

setupdrag:function(e){
	var d=dhtmlwindow //reference dhtml window object
	var t=this._parent //reference dhtml window div
	d.etarget=this //remember div mouse is currently held down on ("handle" or "resize" div)
	var e=window.event || e
	d.initmousex=e.clientX //store x position of mouse onmousedown
	d.initmousey=e.clientY
	d.initx=parseInt(t.offsetLeft) //store offset x of window div onmousedown
	d.inity=parseInt(t.offsetTop)
	d.width=parseInt(t.offsetWidth) //store width of window div
	d.contentheight=parseInt(t.contentarea.offsetHeight) //store height of window div's content div
	if (t.contentarea.datatype=="iframe"){ //if content of this window div is "iframe"
		t.style.backgroundColor="#F8F8F8" //colorize and hide content div (while window is being dragged)
		t.contentarea.style.visibility="hidden"
	}
	document.onmousemove=d.getdistance //get distance travelled by mouse as it moves
	document.onmouseup=function(){
		if (t.contentarea.datatype=="iframe"){ //restore color and visibility of content div onmouseup
			t.contentarea.style.backgroundColor="white"
			t.contentarea.style.visibility="visible"
		}
		d.stop()
	}
	return false
},

getdistance:function(e){
	var d=dhtmlwindow
	var etarget=d.etarget
	var e=window.event || e
	d.distancex=e.clientX-d.initmousex //horizontal distance travelled relative to starting point
	d.distancey=e.clientY-d.initmousey
	if (etarget.className=="drag-handle") //if target element is "handle" div
		d.move(etarget._parent, e)
	else if (etarget.className=="drag-resizearea") //if target element is "resize" div
		d.resize(etarget._parent, e)
	return false //cancel default dragging behavior
},

getviewpoint:function(){ //get window viewpoint numbers
	var ie=document.all && !window.opera
	var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
	this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
	this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)
	this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
},

rememberattrs:function(t){ //remember certain attributes of the window when it's minimized or closed, such as dimensions, position on page
	this.getviewpoint() //Get current window viewpoint numbers
	t.lastx=parseInt((t.style.left || t.offsetLeft))-dhtmlwindow.scroll_left //store last known x coord of window just before minimizing
	t.lasty=parseInt((t.style.top || t.offsetTop))-dhtmlwindow.scroll_top
	t.lastwidth=parseInt(t.style.width) //store last known width of window just before minimizing/ closing
},

move:function(t, e){
	t.style.left=dhtmlwindow.distancex+dhtmlwindow.initx+"px"
	t.style.top=dhtmlwindow.distancey+dhtmlwindow.inity+"px"
	if (parseInt(t.style.top) < 10) { t.style.top = 10+"px"; }
},

resize:function(t, e){
	t.style.width=Math.max(dhtmlwindow.width+dhtmlwindow.distancex, 150)+"px"
	t.contentarea.style.height=Math.max(dhtmlwindow.contentheight+dhtmlwindow.distancey, 100)+"px"
},

enablecontrols:function(e){
	var d=dhtmlwindow
	var sourceobj=window.event? window.event.srcElement : e.target //Get element within "handle" div mouse is currently on (the controls)
	if (/Minimize/i.test(sourceobj.getAttribute("title"))) //if this is the "minimize" control
		d.minimize(sourceobj, this._parent)
	else if (/Maximize/i.test(sourceobj.getAttribute("title"))) //if this is the "restore" control
		d.maximize(sourceobj, this._parent)
	else if (/Restore/i.test(sourceobj.getAttribute("title"))) //if this is the "restore" control
		d.restore(sourceobj, this._parent)
	else if (/Window/i.test(sourceobj.getAttribute("title"))) //if this is the "restore" control
		d.restoreW(sourceobj, this._parent)
	else if (/Close/i.test(sourceobj.getAttribute("title"))) //if this is the "close" control
		d.close(this._parent)
	return false
},

minimize:function(button, t){
	dhtmlwindow.rememberattrs(t)
	button.setAttribute("src", dhtmlwindow.imagefiles[2])
	button.setAttribute("title", "Restore")
	t.state="minimized" //indicate the state of the window as being "minimized"
	t.contentarea.style.display="none"
	t.statusarea.style.display="none"
	if (typeof t.minimizeorder=="undefined"){ //stack order of minmized window on screen relative to any other minimized windows
		dhtmlwindow.minimizeorder++ //increment order
		t.minimizeorder=dhtmlwindow.minimizeorder
	}
	t.style.left="10px" //left coord of minmized window
	//t.style.width="200px"
	var windowspacing=t.minimizeorder*10 //spacing (gap) between each minmized window(s)
	//t.style.top=dhtmlwindow.scroll_top+dhtmlwindow.docheight-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px"
	t.style.top=dhtmlwindow.scroll_top+80-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px"
},

maximize:function(button, t){
	dhtmlwindow.rememberattrs(t)
	button.setAttribute("src", dhtmlwindow.imagefiles[2])
	button.setAttribute("title", "Window")
	t.state="maximized" //indicate the state of the window as being "minimized"
	//t.contentarea.style.display="none"
	//t.statusarea.style.display="none"
	//if (typeof t.minimizeorder=="undefined"){ //stack order of minmized window on screen relative to any other minimized windows
	//	dhtmlwindow.minimizeorder++ //increment order
	//	t.minimizeorder=dhtmlwindow.minimizeorder
	//}
	t.style.left="10px" //left coord of minmized window
	t.style.width="810px"
	t.style.top="80px";
	t.style.height=parseInt(document.getElementById('sContent').style.height) - 100 + "px";
	if (parseInt(document.getElementById('sContent').style.height) <= 100) { t.style.height="400px"; }
	//var windowspacing=t.minimizeorder*10 //spacing (gap) between each minmized window(s)
	//t.style.top=dhtmlwindow.scroll_top+dhtmlwindow.docheight-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px"
	//t.style.top=dhtmlwindow.scroll_top+80-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px"
},


restore:function(button, t){
	dhtmlwindow.getviewpoint()
	button.setAttribute("src", dhtmlwindow.imagefiles[0])
	button.setAttribute("title", "Minimize")
	t.state="fullview" //indicate the state of the window as being "fullview"
	t.style.display="block"
	t.contentarea.style.display="block"
	if (t.resizeBool) //if this window is resizable, enable the resize icon
		t.statusarea.style.display="block"
	t.style.left=parseInt(t.lastx)+dhtmlwindow.scroll_left+"px" //position window to last known x coord just before minimizing
	t.style.top=parseInt(t.lasty)+dhtmlwindow.scroll_top+"px"
	t.style.width=parseInt(t.lastwidth)+"px"
},

restoreW:function(button, t){
	dhtmlwindow.getviewpoint()
	button.setAttribute("src", dhtmlwindow.imagefiles[4])
	button.setAttribute("title", "Maximize")
	t.state="fullview" //indicate the state of the window as being "fullview"
	//t.style.display="block"
	//t.contentarea.style.display="block"
	//if (t.resizeBool) //if this window is resizable, enable the resize icon
		//t.statusarea.style.display="block"
	t.style.left=parseInt(t.lastx)+dhtmlwindow.scroll_left+"px" //position window to last known x coord just before minimizing
	t.style.top=parseInt(t.lasty)+dhtmlwindow.scroll_top+"px"
	t.style.width=parseInt(t.lastwidth)+"px"
},

close:function(t){
	try{
		var closewinbol=t.onclose()
	}
	catch(err){ //In non IE browsers, all errors are caught, so just run the below
		var closewinbol=true
 }
	finally{ //In IE, not all errors are caught, so check if variable isn't defined in IE in those cases
		if (typeof closewinbol=="undefined"){
			alert("An error has occured somwhere inside your \"onclose\" event handler")
			var closewinbol=true
		}
	}
	if (closewinbol){ //if custom event handler function returns true
		if (t.state!="minimized") //if this window isn't currently minimized
			dhtmlwindow.rememberattrs(t) //remember window's dimensions/position on the page before closing
		if (window.frames["_iframe-"+t.id]) //if this is an IFRAME DHTML window
			window.frames["_iframe-"+t.id].location.replace("about:blank")
		else
			t.contentarea.innerHTML=""
		t.style.display="none"
		t.isClosed=true //tell script this window is closed (for detection in t.show())
	}
	return closewinbol
},


setopacity:function(targetobject, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
	if (!targetobject)
		return
	if (targetobject.filters && targetobject.filters[0]){ //IE syntax
		if (typeof targetobject.filters[0].opacity=="number") //IE6
			targetobject.filters[0].opacity=value*100
		else //IE 5.5
			targetobject.style.filter="alpha(opacity="+value*100+")"
		}
	else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
		targetobject.style.MozOpacity=value
	else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
		targetobject.style.opacity=value
},

setfocus:function(t){ //Sets focus to the currently active window
	this.zIndexvalue++
	t.style.zIndex=this.zIndexvalue
	t.isClosed=false //tell script this window isn't closed (for detection in t.show())
	this.setopacity(this.lastactivet.handle, 0.5) //unfocus last active window
	this.setopacity(t.handle, 1) //focus currently active window
	this.lastactivet=t //remember last active window
},


show:function(t){
	if (t.isClosed){
		alert("DHTML Window has been closed, so nothing to show. Open/Create the window again.")
		return
	}
	if (t.lastx) //If there exists previously stored information such as last x position on window attributes (meaning it's been minimized or closed)
		dhtmlwindow.restore(t.controls.firstChild, t) //restore the window using that info
	else
		t.style.display="block"
	this.setfocus(t)
	t.state="fullview" //indicate the state of the window as being "fullview"
},

hide:function(t){
	t.style.display="none"
},

ajax_connect:function(url, t){
	var page_request = false
	var bustcacheparameter=""
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE6 or below
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	t.contentarea.innerHTML=this.ajaxloadinghtml
	page_request.onreadystatechange=function(){dhtmlwindow.ajax_loadpage(page_request, t)}
	if (this.ajaxbustcache) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)
},

ajax_loadpage:function(page_request, t){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
	t.contentarea.innerHTML=page_request.responseText
	}
},


stop:function(){
	dhtmlwindow.etarget=null //clean up
	document.onmousemove=null
	document.onmouseup=null
},

addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
},

cleanup:function(){
	for (var i=0; i<dhtmlwindow.tobjects.length; i++){
		dhtmlwindow.tobjects[i].handle._parent=dhtmlwindow.tobjects[i].resizearea._parent=dhtmlwindow.tobjects[i].controls._parent=null
	}
	window.onload=null
}

} //End dhtmlwindow object

//document.write('<div id="dhtmlwindowholder"><span style="display:none">.</span></div>') //container that holds all dhtml window divs on page
window.onunload=dhtmlwindow.cleanup

