<!--

window.onload = firstLoad;
//xajax_test2('test');

function firstLoad() {
	initSpinner();
	setupEvents();
	/*xajax.call2 = xajax.call;
	xajax.call = function(sFunction,aArgs,sRequestType) {
		el('loaderDiv').style.visibility = 'visible';
		xajax.call2(sFunction,aArgs,sRequestType);
		el('loaderDiv').style.visibility = 'hidden';
	}*/
}

function setfocus(myForm, myInput) {
  document.forms[myForm].elements[myInput].focus(); 
}

function initSpinner()
{
	//keep around the old call function
	xajax.realCall = xajax.call;
	//override the call function to bend to our wicked ways
	xajax.call = function(sFunction, aArgs, sRequestType)
	{
		//show the spinner
		this.$('loaderDiv').style.visibility = 'visible';
		//call the old call function
		return this.realCall(sFunction, aArgs, sRequestType);
	}
	
	//save the old processResponse function for later
	xajax.realProcessResponse = xajax.processResponse;
	//override the processResponse function
	xajax.processResponse = function(xml)
	{
		//hide the spinner
		this.$('loaderDiv').style.visibility = 'hidden';
		//call the real processResponse function
		return this.realProcessResponse(xml);
	}
}
function el(id) {
	return document.getElementById(id);
}

function toggleFilters() {
	if (el('filter').style.display == 'block') {
		el('filterPlus').style.display  = 'block';
		el('filterMinus').style.display = 'none';
		el('filter').style.display      = 'none';
	}
	else {
		el('filterPlus').style.display  = 'none';
		el('filterMinus').style.display = 'block';
		el('filter').style.display      = 'block';
	}
}

function toggle(id)
{	
	var md = document.getElementById(id);		
	if (md !== null) 
	{
		//alert(typeof(md) + ": '" + md + "'");
		if (md.style.display == 'none' || md.style.display == '') {
			md.style.display = 'block';
		}
		else if (md.style.display == 'block') {
			md.style.display = 'none';
		}
	}	
}

function displayBlock(id)
{
	el(id).style.display = 'block';
}

function displayNone(id)
{
	el(id).style.display = 'none';
}

function logout()
{
	if(confirm('Are you sure you wish to logout?')) { 
	  document.location.href='index.php?action=logout'; 
	}	
	return true;
}

function setupEvents() {
	// Shortcuts: Trigger event on keypress
	//document.onkeypress
	document.onkeyup = function(e) {
		//alert(e.keyCode);
		if (typeof(e) == "undefined") {
			e = event;
		}
		
//		switch (e.keyCode) {
//      case 45: // Insert Key
//  		  toggle('debugDiv');
//			  break;
//		}
	}	
}

function formFocus(form, element)
{
	var lf = document.forms[form];
	if (typeof(lf) !== 'undefined') {
		lf.elements[element].focus();
	}
	return 0;
}

function hidestatus()
{
		window.status='';
    return true;
}

if (document.layers) {
    document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
}

/*document.onmousedown = hidestatus;
document.onmouseover = hidestatus;
document.onmouseout  = hidestatus;
document.onclick     = hidestatus;*/

function submitForm(formId)
{    
		if ( xajax.$('submitButton') !== null ) {
			xajax.$('submitButton').disabled=true;
			xajax.$('submitButton').value="please wait...";
		}    
		if ( xajax.$('processed') !== null ) {
		  xajax.$('processed').style.visibility="hidden";				
		}
    xajax_processForm(formId, xajax.getFormValues(formId));
    return false;
}

function exchangeFormResetSelect(selectId) 
{
	for (var i = 0; i < el(selectId).length; i++) {
		el(selectId).options[i].disabled = false;		
	}
	el('ecuapi').innerHTML = '';
}

function refresh()
{
		//alert(document.baseURI); 
		document.location.href = document.baseURI;
}

// ------------------------------------------------------------


// cssJsMenu
function cssJsMenu(elemId) {
  if (document.getElementById(elemId)) {
    var navroot = document.getElementById(elemId);
    var lis=navroot.getElementsByTagName("LI");

    for (i = 0; i < lis.length; i++) {
      for (j = 0; j < lis[i].getElementsByTagName("UL").length; j++) {
        lis[i].onmouseover = function() {
          this.getElementsByTagName("UL")[j].style.visibility = 'visible';
        }

        lis[i].onmouseout = function() {
          this.getElementsByTagName("UL")[j].style.visibility = 'hidden';
        }
      }
    }
  }
}


// MM functions
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.0
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&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.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];}
}





/***********************************************
* Switch Content script II- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated April 2nd, 2005.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var memoryduration="7" //persistence in # of days

var contractsymbol='images/minus.gif' //Path to image to represent contract state.
var expandsymbol='images/plus.gif' //Path to image to represent expand state.

/////No need to edit beyond here //////////////////////////

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=(ec=="contract")? "none" : ""
inc++
}
revivestatus()
}


function expandcontent(curobj, cid){
if (ccollect.length>0){
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="none")? "none" : ""
curobj.src=(document.getElementById(cid).style.display=="none")? expandsymbol : contractsymbol
}
}

function revivecontent(){
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="none"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="none")
statecollect[inc].src=expandsymbol
else
statecollect[inc].src=contractsymbol
inc++
}
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
if (typeof(ccolect) !== "undefined"){
while (ccollect[inc]){
if (ccollect[inc].style.display=="none")
selectedItem+=ccollect[inc].id+"|"
inc++
}
}
if (get_cookie(window.location.pathname)!=selectedItem){ //only update cookie if current states differ from cookie's
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()+parseInt(memoryduration))
document.cookie = window.location.pathname+"="+selectedItem+";path=/;expires=" + expireDate.toGMTString()
}
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && get_cookie(window.location.pathname)!="" && ccollect.length>0)
revivecontent()
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

/***********************************************
* Tab Content script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]

////////Stop editting////////////////

function cascadedstyle(el, cssproperty, csspropertyNS){
if (el.currentStyle)
return el.currentStyle[cssproperty]
else if (window.getComputedStyle){
var elstyle=window.getComputedStyle(el, "")
return elstyle.getPropertyValue(csspropertyNS)
}
}

var previoustab=""

function expandcontent(cid, aobject){
if (document.getElementById){
highlighttab(aobject)
detectSourceindex(aobject)
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
document.getElementById(cid).style.display="block"
previoustab=cid
if (aobject.blur)
aobject.blur()
return false
}
else
return true
}

function highlighttab(aobject){
if (typeof tabobjlinks=="undefined")
collecttablinks()
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].style.backgroundColor=initTabcolor
var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : initTabpostcolor
aobject.style.backgroundColor=document.getElementById("tabcontentcontainer").style.backgroundColor=themecolor
}

function collecttablinks(){
var tabobj=document.getElementById("tablist")
if (tabobj!=null){
tabobjlinks=tabobj.getElementsByTagName("A")
}
}

function detectSourceindex(aobject){
for (i=0; i<tabobjlinks.length; i++){
if (aobject==tabobjlinks[i]){
tabsourceindex=i //source index of tab bar relative to other tabs
break
}
}
}

function do_onload(){
var cookiename=(typeof persisttype!="undefined" && persisttype=="sitewide")? "tabcontent" : window.location.pathname
var cookiecheck=window.get_cookie && get_cookie(cookiename).indexOf("|")!=-1
collecttablinks()
if (typeof(tabobjlinks)!="undefined"){
initTabcolor=cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
initTabpostcolor=cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
if (typeof enablepersistence!="undefined" && enablepersistence && cookiecheck){
var cookieparse=get_cookie(cookiename).split("|")
var whichtab=cookieparse[0]
var tabcontentid=cookieparse[1]
expandcontent(tabcontentid, tabobjlinks[whichtab])
}
else
expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload
/***********************************************
* End Tab Content script-
***********************************************/

function addElement() {
  var ni = document.getElementById('bodyContainer');
  var numi = document.getElementById('messageContainer');
  var num = (document.getElementById('messageContainer').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = 'Element Number '+num+' has been added! <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div \"'+divIdName+'\"</a>';
  ni.appendChild(newdiv);
}

function removeElement(divNum) {
  /*var d = document.getElementById('bodyContainer');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);*/

	var nodetoremove = el(divNum);
	nodetoremove.parentNode.removeChild(nodetoremove);
}


//-->