var ajaxData;
var _store;

   function DeSLPOSTRequest(url, parameters, delegate) {
	//phased out. replaced with Invok	
   }

   function DeSLLocalExec() {
      if (this.http_request.readyState == 4) {
         if (this.http_request.status == 200 ) {
            result = this.http_request.responseText;
	    eval(result);
         } else {
            alert('There was a problem with the request.' + this.http_request.status + '. ' + this.http_request.responseText);
         }
      }
   }

   function Invok(strURL, strFunction, objPayload, objDelegate) {
      this.http_request=false;

      var self = this;
      var parameters = "DeSLFunction=" + encodeURI( strFunction ) + '&' + objPayload;
      var url=strURL;

      this.delegate = function(){
              if (self.http_request.readyState == 4) {
	         if (self.http_request.status == 200 ) {
	       	    result = self.http_request.responseText;
	            try {
					eval(result);
					} catch (e) {
           						}
			} else {
	            alert('There was a problem with the request.' + self.http_request.status + '. ' + self.http_request.responseText);
	         }
	      }
	}


      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         this.http_request = new XMLHttpRequest();
         if (this.http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            this.http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!this.http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

	this.http_request.onreadystatechange = this.delegate;
    
      if (window.XMLHttpRequest){
         this.http_request.open('POST', url, true);
         this.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         this.http_request.setRequestHeader("Content-length", parameters.length);
	 //http_request.setRequestHeader("Connection", "close");
      }else{
         this.http_request.open('POST', url, true);
	 this.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         this.http_request.setRequestHeader("Content-length", parameters.length);
	 this.http_request.setRequestHeader("Connection", "close");
      }
      this.http_request.send(parameters);

   }

   function InvokeDeSL(strURL, strFunction, objPayload, objDelegate) { 
         var objs=new Invok(strURL, strFunction,objPayload,objDelegate);     	
   }

function DeSLTbSet(tb,val){var obj;obj=document.getElementById(tb);if (obj){obj.value=val;}}
function DeSLLbSet(tb,val){var obj;obj=document.getElementById(tb);if (obj){if(document.all){obj.innerText=val;}else{obj.textContent=val;}}}
function DeSLLbxSet(pv,tb,val){var obj;obj=document.getElementById(pv+tb);if (obj){if(document.all){obj.innerText=val;}else{obj.textContent=val;}}}
function DeSLLbHSet(tb,val){var obj;obj=document.getElementById(tb);if (obj){obj.innerHTML=val;}}
function gE(id){return document.getElementById(id);}
function gEV(id){var obj;obj=gE(id);if (obj){return obj.value;}}
function gEVx(pv,id){var obj;obj=gE(pv+id);if (obj){return obj.value;}}
function gLVe(pv,lbl){var obj;obj=document.getElementById(pv+lbl);if (obj){if(document.all){return obj.innerText;}else{return obj.textContent;}}}
function gLV(lbl){var obj;obj=document.getElementById(lbl);if (obj){if(document.all){return obj.innerText;}else{return obj.textContent;}}}
function PopSel(id,ar1){
var obj;
var obj=gE(id);
if (obj){
for(i=0;i<ar1.length;i+=1)
{
 obj.options[obj.options.length]=new Option(ar1[i][0],ar1[i][1],obj.options.length);
}}}
function ClrSel(id)
{
var obj;
var obj=gE(id);
if (obj){
obj.options.length=0;}
}
function inpInc(tb){var obj;obj=document.getElementById(tb);if(obj){obj.value=parseInt(obj.value)+1;return obj.value;}}
function inpDec(tb){var obj;obj=document.getElementById(tb);if(obj){obj.value=parseInt(obj.value)-1;return obj.value;}}
function getTb(tb){var obj;obj=document.getElementById(tb);if(obj){return obj.value;}else{return '';}}
function appInc(tb,val){var obj;obj=document.getElementById(tb);if(obj){obj.value=obj.value+val;return obj.value;}}

function getEVENTTARGET()
{

    var theform;
    var obj;

    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    }
    else {
    	theform = document.forms[0];
    }

    if(theform)
    {
	obj=theform.__EVENTTARGET;
    }
    else
    {
       	obj=document.getElementById('__EVENTTARGET');
    }
    return obj;
}

function isIE()
{
  if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    return true;
  }
  else
  {
    return false;
  }
}

function cbut(cid)
{
  var cod;
  var fi=0;
  var li=0;

  if(isIE())
  {
    gE(cid).click();
  }
  else
  {

    cod=document.getElementById(cid).onclick;

    if(!cod)
    {
      cod=document.getElementById(cid).href;
    }

    cod=cod.toString();

    if(cod.toLowerCase().indexOf(":")>-1)
    {
      fi=cod.indexOf(':');
      li=cod.length+1;
    }
    else
    {
      fi=cod.indexOf('{');
      li=cod.lastIndexOf('}');
    }

    fi=fi+1;
    li=li-1;

    eval(cod.substring(fi,li));

  }

}

function getEVENTARGUMENT()
{

    var theform;
    var obj;

    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    }
    else {
    	theform = document.forms[0];
    }

    if(theform)
    {
	obj=theform.__EVENTARGUMENT;
    }
    else
    {
       	obj=document.getElementById('__EVENTARGUMENT');
    }
    return obj;
}

function SetInputVals(strparent, cid){
    var inputs = document.getElementById(strparent).getElementsByTagName('INPUT');
    
    //get the child divs
    var divs = document.getElementById(strparent).getElementsByTagName('DIV');
    var input;
    var div;
    var val='';
    var diver='';
    
    for (var i = divs.length-1; i > -1; i--) { 
        div=divs[i];
        if (div.id.indexOf("_ctlDA") > -1)
        {
            diver=diver+replaceAll(div.id,'ctlDA','')+',';
        }
    }

    for (var i = 0; i < inputs.length; i++) { 
        input=inputs[i];

	if (input.id.indexOf('ctlVS')>-1){}
	else if (input.id.indexOf('ctlINP')>-1){}
	else if (input.id=='__EVENTARGUMENT'){}
	else if (diver.indexOf(input.id)>-1){}
        else if (input.type=='checkbox')
        {
            if (input.checked==true){
            val=val+'&' + input.name + '=checked';
            }
        }
	else if (input.type=='radio')
        {
            if (input.checked==true){
            val=val+'&' + input.name + '=' + input.value;
            }
        }
	else if (input.type=='submit')
	{
		//ignore
	}
	else if (input.type=='button')
	{
		//ignore
	}
	else if (input.type=='image')
	{
		//ignore
	}
	else if (input.type=='reset')
	{
		//ignore
	}
        else
        {
            val=val+'&' + input.name + '=' + encodeURIComponent(input.value);
        }
    }

    inputs = document.getElementById(strparent).getElementsByTagName('TEXTAREA');
    for (var i = 0; i < inputs.length; i++) { 
        input=inputs[i];
        val=val+'&' + input.name + '=' + encodeURIComponent(input.value).replace(/%0D/g,'');
    }
    inputs = document.getElementById(strparent).getElementsByTagName('SELECT');
    for (var i = 0; i < inputs.length; i++) { 
        input=inputs[i];
	for (var o = 0; o < input.options.length; o++){
		if (input.options[o].selected==true || input.options[o].checked==true)
		        val=val+'&' + input.name + '=' + encodeURIComponent(input.options[o].value);
	}
    }

    val=val+'&__EVENTTARGET='+getEVENTTARGET().value;
    val=val+'&__EVENTARGUMENT='+getEVENTARGUMENT().value;
    
    regAjaxVSY(cid,val);
    //document.getElementById(strfield).value=val;  
}

function TextboxTotal(strparent, strlabel){
    var inputs = document.getElementById(strparent).getElementsByTagName('INPUT');
    var input;
    var val=0;
    for (var i = 0; i < inputs.length; i++) { 
        input=inputs[i];
        if (input.type=='text')
        {
	    try
	    {
            val=val+parseInt(input.value);
	    }
            catch(e)
            {}
        }
    }
    document.getElementById(strlabel).innerText=val;  
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		if (func){
		window.onload = func;}
	} else {
		window.onload = function() {
		if (oldonload) {
			oldonload();
		}
		if (func){
		func();}
		}
	}
}
	
function addResizeEvent(func) {
	var oldonload = window.onresize;
	if (typeof window.onresize != 'function') {
		if (func){
		window.onresize = func;}
	} else {
		window.onresize = function() {
		if (oldonload) {
			oldonload();
		}
		func();
		}
	}
}

function replaceAll(str,c1,c2){
 var strReplaceAll = str;
 var intIndexOfMatch = strReplaceAll.indexOf(c1);

 while (intIndexOfMatch != -1){

	strReplaceAll = strReplaceAll.replace(c1, c2);
	intIndexOfMatch = strReplaceAll.indexOf(c1);
 }
 return strReplaceAll;
}

function __desldopostback(invfunc,divid,inpid,vsid,cid,uid,tabid,stabid,moduleid,target,argument)
{

 	var ViewState='';
	var strParams=' ';
	var inpState='';
	var theform;

	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
	}
	else {
		theform = document.forms[0];
	}

	if(theform)
	{
		theform.__EVENTTARGET.value=replaceAll(target,'$',':');
	        theform.__EVENTARGUMENT.value=argument;
	}
	else
	{
        	document.getElementById('__EVENTTARGET').value=replaceAll(target,'$',':');
	        document.getElementById('__EVENTARGUMENT').value=argument;
	}
	SetInputVals(divid,cid);
	SetChildInputVals(divid);

        //ViewState=gEV(vsid);
        ViewState=getAjaxVS(cid);
	strParams='&ViewState='+ViewState;
	strParams=strParams+getAjaxInp(cid);
	
	InvokeDeSL('Applications/DeSLAJAXCon/Modules/ACall.aspx',invfunc,'&CID='+cid+'&UID='+uid+'&TabId='+tabid+'&STabId='+stabid+'&ModuleId='+moduleid+'&DIVID='+divid+'&VSID='+vsid+'&ModuleIsPostback=True&INPID='+inpid+strParams,DeSLLocalExec);
}

function SetChildInputVals(par)
{
    
    var divs;
    var div;
    
    divs = document.getElementById(par).getElementsByTagName('DIV');
    
     for (var i = 0; i < divs.length; i++) { 
        div=divs[i];
                
        //check if it ends with ctlDA
        if (div.id.indexOf('ctlDA') > -1)
        {
            SetInputVals(div.id,replaceAll(div.id,'_ctlDA',''));
        }       
    }
    
}

function SetChildInputValsEx()
{
    
    var divs;
    var div;
    
    divs = document.getElementsByTagName('DIV');
    
     for (var i = 0; i < divs.length; i++) { 
        div=divs[i];
                
        //check if it ends with ctlDA
        if (div.id.indexOf('ctlDA') > -1)
        {
            SetInputVals(div.id,replaceAll(div.id,'_ctlDA',''));
        }       
    }
    
}

function CalShowClick( theDivName, btnShowCal )
{
	var ContainerDiv = document.getElementById(theDivName);
	var but = document.getElementById(btnShowCal);

	if( ContainerDiv.style.display == 'none') 
		{
		ContainerDiv.style.zIndex=1000;
		ContainerDiv.style.display = "inline";

		if (elementLeft(but) - (ContainerDiv.clientWidth - but.clientWidth) > 0) 
		{
			ContainerDiv.style.left=elementLeft(but) - (ContainerDiv.clientWidth - but.offsetWidth);
		} 
		else 
		{
			ContainerDiv.style.left=0;
		}

		ContainerDiv.style.top=elementTop(but)+but.offsetHeight;

		//hideCalElement("SELECT",ContainerDiv);
		} 
	else {
		//showCalElement("SELECT",ContainerDiv);
		ContainerDiv.style.display = "none";
	}
}

	function hideCalElements( theDivName )
	{
		var ContainerDiv = document.getElementById(theDivName);
			
		if( ContainerDiv.style.display == "none")
			{
				
			}
		else 
			{
				
				hideCalElement("SELECT",ContainerDiv);
				hideCalElement("INPUT",ContainerDiv);
				
			}
	}

	function showCalElements( theDivName )
	{
		var ContainerDiv = document.getElementById(theDivName);

		ContainerDiv.style.display='inline';
				
		showCalElement("SELECT",ContainerDiv);
		showCalElement("INPUT",ContainerDiv);
		
	}

	function hideCalElement(elmID, eMenu)
	{
		var objs;
		var obj;
		var doR=false;

		objs=document.all.tags(elmID);
		
		// Hide any element that overlaps with the dropdown menu
		for (i = 0; i < objs.length; i++)
		{
			obj = objs[i];

			doR=false;

			if (obj.tagName=='INPUT')
			{
				if (obj.type.toLowerCase()=='button' || obj.type.toLowerCase()=='submit')
				{
					doR=true;
				}
			}
			else
			{
				doR=true;
			}

			if (doR==true){
			
				if (elementTop(obj) > elementTop(eMenu) + eMenu.offsetHeight)
				{
					
					//if element is below bottom of menu then do nothing
				}
				else if (elementLeft(obj) > elementLeft(eMenu) + eMenu.offsetWidth)
				{
					
				//if element is to the right of menu then do nothing
				}
				else if (elementLeft(obj) + obj.offsetWidth < elementLeft(eMenu))
				{
					
					//if element is to the left of menu then do nothing
				}
				else if (elementTop(obj) + obj.offsetHeight < elementTop(eMenu))
				{
					
					//if element is to the top of menu then do nothing
				}
				else
				{

					obj.deslhid=1;
					obj.style.visibility = "hidden";
				}
			}
		}
	}

	function showCalElement(elmID, eMenu)
	{
		var objs;
		var obj;
		var doR=false;

		objs=document.all.tags(elmID);

		// Hide any element that overlaps with the dropdown menu
		for (i = 0; i < objs.length; i++)
		{
			obj = objs[i];

			doR=false;

			if (obj.tagName=='INPUT')
			{
				if (obj.type.toLowerCase()=='button' || obj.type.toLowerCase()=='submit')
				{
					doR=true;
				}
			}
			else
			{
				doR=true;
			}

			if (doR==true){

			if (elementTop(obj) > elementTop(eMenu) + eMenu.offsetHeight)
			{
				//if element is below bottom of menu then do nothing
			}
			else if (elementLeft(obj) > elementLeft(eMenu) + eMenu.offsetWidth)
			{
				//if element is to the right of menu then do nothing
			}
			else if (elementLeft(obj) + obj.offsetWidth < elementLeft(eMenu))
			{
				//if element is to the left of menu then do nothing
			}
			else if (elementTop(obj) + obj.offsetHeight < elementTop(eMenu))
			{
			
				//if element is to the top of menu then do nothing
			}
			else
			{
				obj.deslhid=0;
				obj.style.visibility = "visible";
			}
			}
			
		}
	}
	
	function elementTop(eSrc)
	{
		var iTop = 0;
		var eParent;
		eParent = eSrc;
		while (eParent.tagName.toUpperCase() != "BODY")
		{
			iTop += eParent.offsetTop - eParent.scrollTop;
			eParent = eParent.offsetParent;
			if (!eParent) break;
		}
		return iTop;
	}
	
	function elementLeft(eSrc)
	{	
		var iLeft = 0;
		var eParent;
		eParent = eSrc;
		while (eParent.tagName.toUpperCase() != "BODY")
		{
			iLeft += eParent.offsetLeft;
			eParent = eParent.offsetParent;
			if (!eParent) break;
		}
		return iLeft;
	}

function fCur(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return dblValue + '.' + strCents;
}
function mo(o){ 
		o.style.backgroundColor='#ddddff';
		o.style.border='1px solid #000000';
		o.style.cursor='hand';
	}
	function mt(o){ 
		o.style.backgroundColor='transparent';
		o.style.border='1px solid #d4d0c8';
	}
	function clickButton(buttonid){
		document.getElementById(buttonid).click(); return false; 
	}

function IsNumeric(sText)

{
   var ValidChars = '0123456789.';
   var IsNumber=true;
   var Char;

   if (sText=='') { return false;}
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function cbToStr(fval,cb)
{
	var c;
	var str='';

	c=gE(cb);
	if(c)
	{
		if (c.checked==true)
		{
			str='&' + fval + '=checked'
		}
	}
	return str
}
function cbC(cb)
{
	var c;
	var b=false;

	c=gE(cb);
	if(c)
	{
		if (c.checked==true)
		{
			b=true;
		}
	}
	return b
}

function initAjaxData(){

    var parser;

    //if (document.implementation && document.implementation.createDocument){
    if(!window.ActiveXObject)
    {
        parser= new DOMParser();
	ajaxData=parser.parseFromString("<base><_dat></_dat></base>","text/xml");
    }
    else
    {
        ajaxData = new ActiveXObject("Microsoft.XMLDOM");   
        ajaxData.loadXML("<base><_dat></_dat></base>");
    }
 
}

function loadXMLDocument(doc,str)
{

  var parser;

  if(!window.ActiveXObject)
  {
    try
    {
      parser= new DOMParser();
      ajaxData=parser.parseFromString(str,"text/xml");
    }
    catch(err)
    {
       alert(err.message);
    }
  }
  else
  {
    ajaxData.loadXML(str);
  }
}

function getXMLString(doc)
{
  if(!window.ActiveXObject)
  {
    var serializer = new XMLSerializer();
    var xml = serializer.serializeToString(doc);
    return xml;
  }
  else
  {
    return doc.xml;
  }
}

function regAjaxVS(clid, vs, inp)
{
    var base;
    var nodes;
    var node;
    
    base=ajaxData.documentElement;
    
    nodes=base.getElementsByTagName(clid);
    
    //Doesn't exist yet
    if (nodes.length==0)
    {
        node=ajaxData.createElement(clid);
        ajaxData.documentElement.appendChild(node);        
    }
    else
    {
        node=nodes[0];
    }
    
    node.setAttribute('vs',vs);
    node.setAttribute('inp',inp);
}

//get int store item
function gISI(ent)
{
    var val;
    
    val=gSI(ent);
    
    if (!val)
    {
        val=0;
    }
    
    return val;
}

//get store item
function gSI(ent)
{
    var workerStore;
    
    workerStore=getStore('wS');
    
    if (!workerStore)
    {
        workerStore=createStore('wS');
    }
    
    return workerStore.getAttribute(ent);
}

//set store item
function sSI(ent,val)
{
    var workerStore;
    
    workerStore=getStore('wS');
    
    if (!workerStore)
    {
        workerStore=createStore('wS');
    }
    
    workerStore.setAttribute(ent,val);
    
    return val;
}

function createStore(id)
{
    var base;
    var nodes;
    var node;
    var store;
    
    if (!_store)
    {
        base=ajaxData.documentElement;
    
        nodes=base.getElementsByTagName('_dat');
    
        _store=nodes[0];
    }

    store=ajaxData.createElement(id);    
    _store.appendChild(store);
    
    return store;
       
}

function getStore(id)
{

    var base;
    var nodes;
    var node;
    var stores;
    
    if (!_store)
    {
        base=ajaxData.documentElement;
    
        nodes=base.getElementsByTagName('_dat');
    
        _store=nodes[0];
    }

    stores = _store.getElementsByTagName(id);
    
    if (stores.length>0)
    {
        return stores[0];
    }

}

function removeStore(id)
{

    var base;
    var nodes;
    var node;
    var store;
    
    if (!_store)
    {
        base=ajaxData.documentElement;
    
        nodes=base.getElementsByTagName('_dat');
    
        _store=nodes[0];
    }
    
    store=getStore(id);

    if(store)
    {
        _store.removeChild(store);
    }

}

function regAjaxVSX(clid, vs)
{
    var base;
    var nodes;
    var node;
    
    base=ajaxData.documentElement;
    
    nodes=base.getElementsByTagName(clid);
    
    //Doesn't exist yet
    if (nodes.length==0)
    {
        node=ajaxData.createElement(clid);
        ajaxData.documentElement.appendChild(node);        
    }
    else
    {
        node=nodes[0];
    }
    
    node.setAttribute('vs',vs);
}

function regAjaxVSY(clid, inp)
{
    var base;
    var nodes;
    var node;
    
    base=ajaxData.documentElement;
    
    nodes=base.getElementsByTagName(clid);
    
    //Doesn't exist yet
    if (nodes.length==0)
    {
        node=ajaxData.createElement(clid);
        ajaxData.documentElement.appendChild(node);        
    }
    else
    {
        node=nodes[0];
    }
    
    node.setAttribute('inp',inp);
}

function getAjaxVS(clid)
{
    var base;
    var nodes;
    var node;
    
    base=ajaxData.documentElement;
    
    nodes=base.getElementsByTagName(clid);
    
    //Doesn't exist yet
    if (nodes.length==0)
    {
        return '';       
    }
    else
    {
        node=nodes[0];
    }
    
    return node.getAttribute('vs');
}

function getAjaxInp(clid)
{
    var base;
    var nodes;
    var node;
    
    base=ajaxData.documentElement;
    
    nodes=base.getElementsByTagName(clid);
    
    //Doesn't exist yet
    if (nodes.length==0)
    {
        return '';       
    }
    else
    {
        node=nodes[0];
    }
    
    return node.getAttribute('inp');
}

function getAjaxDat()
{
    return getXMLString(ajaxData);
}

function setAjaxDat(dat)
{
    loadXMLDocument(ajaxData,dat);
}

function loadAjaxDat()
{

    if (gE('aj').value)
    {
        if (gE('aj').value.length>0)
        {
            setAjaxDat(gE('aj').value);
        }
    }
}

function bottomLevelAjaxInpSet()
{
    
    SetChildInputValsEx();
    
}

function saveAjaxState()
{
    //save the inputs firstly
    bottomLevelAjaxInpSet();

    gE('aj').value=getAjaxDat();
}

//matrix row highlight
function maH(con)
{

    var obj=con;
    var cell;
    
    while (!(obj.nodeName=='TR'))
    {
        obj=obj.parentNode;
    }
	
	for (i = 0; i < obj.cells.length; i++) 
    	{ 
       	 	if (obj.cells[i].className=='mf')
        	{
	        	obj.cells[i].className='mfh';
	        }
	        if (obj.cells[i].className=='mb')
        	{
	        	obj.cells[i].className='mbh';
	        }
	}
	
}

//matrix row de-highlight
function maD(con)
{
	var obj=con;
    
    while (!(obj.nodeName=='TR'))
    {
        obj=obj.parentNode;
    }
	
	for (i = 0; i < obj.cells.length; i++) 
    { 
	    if (obj.cells[i].className=='mfh')
        {
	        obj.cells[i].className='mf';
	    }
	if (obj.cells[i].className=='mbh')
        {
	        obj.cells[i].className='mb';
	    }
	}
	
}

function cie(cid)
{
 if (gE(cid))
 {
  cbut(cid);
 }
 else
 {
  setTimeout(function(){cie(cid);},50);
 }
}

function cig(cid)
{
 cigx(cid,0,50);
}

function cigx(cid,count,max)
{
 if(count>max) 
 {
	alert('The event for '+cid+' timed out.');
	return;
 }
 if (gE(cid))
 {
  cbut(cid);
 }
 else
 {
  setTimeout(function(){cig(cid,count+1,max);},50);
 }
}

function cif(cid)
{
 if (gE(cid))
 {
  cbut(cid);
 }
}

//File management change bg
function fm_cb(Obj, strCssClass)
{
 Obj.className = strCssClass;
}

function pm_r(obj)
{
 if(obj.checked)
 {
  return '&MOD=1'
 }
 else
 {
  return '&MOD=2'
 }
}

function hvrOv(inId,div)
{
	setTimeout('hvrOu(' + inpInc(inId) + ',\'' + inId + '\',\'' + div + '\')',500);
}
function hvrOu(xx,inId,div)
{
	if(!gE(inId)) return;
	if(!gE(div)) return;

	if(xx==parseInt(gE(inId).value))
	{
		gE(div).style.display='none';
	}
}

function syncTab(t1,t2)
{
    
    var tab1;
    var tab2;
    var tbody1;
    var tbody2;
    
    var rows1;
    var row1;
    var rows2;
    var row2;
    
    var rowCount;
    var dif=0;
    var count=0;
    var aver=0;
    
    if (!t1) return;
    if (!t2) return;
    
    tab1=gE(t1);
    tab2=gE(t2);
    
    tbody1=tab1.getElementsByTagName("tbody");
    tbody2=tab2.getElementsByTagName("tbody");
    
    rows1=tbody1[0].childNodes;
    rows2=tbody2[0].childNodes;
    
    //Make rows as small as possible
    for(rowCount=0;rowCount<rows1.length;rowCount++)
    {
        row1=rows1[rowCount];
        row2=rows2[rowCount];
        
        row1.style.height=1;
        row2.style.height=1;  
    }
    
    //See if we can average the rows firstly
    aver=tab1.clientHeight / rows1.length;
    
    for(rowCount=0;rowCount<rows1.length;rowCount++)
    {
        row1=rows1[rowCount];
        row2=rows2[rowCount];
        
        row1.style.height=aver;
        row2.style.height=aver;  
    }
    
    for(rowCount=0;rowCount<rows1.length;rowCount++)
    {
        
        row1=rows1[rowCount];
        row2=rows2[rowCount];
        
        dif=0;
        count=0;
        
        while (row1.clientHeight!=row2.clientHeight && count<100)
        {
            row1.style.height=row2.clientHeight+dif;
            if (row1.clientHeight!=row2.clientHeight)
            {
                row2.style.height=row1.clientHeight;
            }
            dif=row1.clientHeight-row2.clientHeight;
            count=count+1;
        }
                
    }
         
}

function endWi(obj,off)
{

    var tobj;

    if (!obj) return;
    
    tobj=gE(obj); 
    
    endWo(tobj,off);
}

function endWo(obj,off)
{

    if (!obj) return;
    
    obj.style.width = document.body.clientWidth - (elementLeft(obj)+off);

}

function apHead(src)
{

    var fileref=document.createElement('script')
    
    fileref.setAttribute("type","text/javascript")
    fileref.setAttribute("src", src)
    
    document.getElementsByTagName("head")[0].appendChild(fileref)

}

function apCSS(src)
{

    var fileref=document.createElement('link')
    
    fileref.setAttribute("type","text/css")
    fileref.setAttribute("href", src)
    fileref.setAttribute("rel", "stylesheet")
    
    document.getElementsByTagName("head")[0].appendChild(fileref)

}

function expandPortal()
{

	var obj1;
	var obj2;
	
	obj1=gE('deslr1');
	if (obj1)
	{
		obj1.style.display='inline';
	}

	obj2=gE('deslr2');
	if (obj2)
	{
		obj2.style.display='inline';
	}

}

function minimizePortal()
{

	var obj1;
	var obj2;

	obj1=gE('deslr1');
	if (obj1)
	{
		obj1.style.display='none';
	}

	obj2=gE('deslr2');
	if (obj2)
	{
		obj2.style.display='none';
	}

}

function DeSLRegJSQuery()
{
    apHead(DeSLJSJQuery);
}

function DeSLRegJSFancyBox()
{
    apHead(DeSLJSFancyBox);
}

function DeSLRegJSPngFix()
{
    apHead(DeSLJSJPngFix);
}

function DeSLRegFancyCSS()
{
    apCSS(DeSLCSSFancyBox);
}

function dMv(obj){ var el=document.getElementById(obj); var im=document.getElementById(obj + '_img');if (el.value==1) { el.value=0; im.src='SysImages/A/B3.gif';} else { el.value=1; im.src='SysImages/A/B1.gif'; }}

function ajEx(val)
{
	
	var lit = ['<table','cellpadding','cellspacing','</table>','SysImages/Standard','inline-block','window.showModalDialog(','/Applications/SharedControls/Controls/PopupQuestion.aspx?Message=','document.getElementById','border-width'];

	var count=0;

	for(count=0;count<lit.length;count++)
	{
		val=val.replace(new RegExp("\\$\\["+count+"\\]", "g" ),lit[count]);
	}

	return val;

}

function centdiv(ctl)
{

	var obj;
	var x,y,w,h;

	if(!ctl) return;

	obj=gE(ctl);

	if (!obj) return;	

	w=obj.clientWidth;
	h=obj.clientHeight;

	x=(document.documentElement.clientWidth/2) - (w/2);
	y=(document.documentElement.clientHeight/2) - (h/2) + document.documentElement.scrollTop;

	if (y<0) y=0;
	if (x<0) x=0;

	obj.style.left = x;
	obj.style.top = y;

}

function dCE(objId)
{
	var theObject = gE(objId);
	var level = 0;
	TraverseDOM(theObject, level, disableElement);
}

function TraverseDOM(obj, lvl, actionFunc)
{
	for (var i=0; i<obj.childNodes.length; i++) {
		var childObj = obj.childNodes[i];
		if (childObj.tagName) {
			actionFunc(childObj);
		}
		TraverseDOM(childObj, lvl + 1, actionFunc);
	}
}

function disableElement(obj)
{
	obj.disabled = true;
}

function moveAXTB(tbid)
{
	var thistoolbar;
	var uppertoolbar;
	var row;
	var c=0;

	thistoolbar=findUpperToolbar(gE(tbid + '_swcs').parentNode);
	uppertoolbar=findUpperToolbar(thistoolbar.parentNode.parentNode);

	if (!thistoolbar) return;
	if (!uppertoolbar) return;

	for(c=uppertoolbar.rows.length-1;c>-1;c--)
	{
		uppertoolbar.deleteRow(c);
	}

	if(thistoolbar.getElementsByTagName('tr').length==0) return;

	uppertoolbar.getElementsByTagName('tbody')[0].appendChild(thistoolbar.getElementsByTagName('tr')[0].cloneNode(true));

	thistoolbar.deleteRow(0);
	
}

function findUpperToolbar(obj)
{
	
	var i=0;
	var childNode;

	if(!obj) return null;

	for (i=0;i<obj.childNodes.length;i++)
	{
		childNode=obj.childNodes[i];
		if(childNode)
		{
			if(childNode.id=='tblToolbar' && childNode.nodeName=='TABLE')
			{
				return childNode;
			}
		}
	}
	
	return findUpperToolbar(obj.parentNode);

}


function LoadThreadReport(c1, c2, data)
{
	gE(c2).value = data;
	cie(c1);
}

function moveCtrl(id1,id2)
{
	var obj1 = gE(id1)
	var obj = gE(id2);
	
	if (!obj1) return;
	if (!obj) return;

	obj.appendChild(obj1);
}

function cwe(ev,cid)
{
 if (eval(ev))
 {
  cbut(cid);
 }
 else
 {
  setTimeout(function(){cwe(ev,cid);},50);
 }
}


//------------------------------------------------
//Paths
//------------------------------------------------
var DeSLPA1 = 'Applications/RFD/Modules/AJAX/RFDRequirementQuantity/F1.aspx';
var DeSLPA2 = 'Applications/RFD/Modules/AJAX/RFDRequirementQuantity/F2.aspx';

var DeSLJSJQuery = 'Controls/jquery-1.2.3.pack.js';
var DeSLJSFancyBox = 'Controls/jquery.fancybox-1.0.0.js';
var DeSLJSJPngFix = 'Controls/jquery.pngFix.pack.js';
var DeSLCSSFancyBox = 'Portals/Company/fancy.css';

//Initialise the ajax
initAjaxData();