//show the loading indicator
function showLoader(where){

	if(where != null && where != ""){
	document.getElementById(where).innerHTML = "Loading...";
	}
	
	else{
		
		}
	//return;
}

function toggleDisp(ID){
var obj			= document.getElementById(ID);
var state		= obj.style.display;

//alert(state);

if(state == "none" || state == ""){
obj.style.display	= "block";
obj.style.height	= "";
}

else {
obj.style.display	= "none";
obj.style.height	= "1px";
}

}

//retrieve the width of the current window
function getClientWidth(){
	if(window.innerWidth){
	return window.innerWidth;
	}

    if(document.body.clientWidth){
	return document.body.clientWidth;
	}
}

//retrieve the width of the current window
function getClientHeight(){
	if(window.innerHeight){
	return window.innerHeight;
	}

    if(document.body.clientHeight){
	return document.body.clientHeight;
	}
}

function openWin(url,name,params){

var winOpen         = window.open(url,name,params);
if(winOpen){
    return true;
}

else{
alert("Your popup blocker may have stoped an important window from being open. Please add this site to your trusted site list and try again!");
return false;
}

return false;
}


function deleteNode(ID){
        node		= document.getElementById(ID);
		if(node == undefined || node == null || node == ''){
		alert("Could not delete....");
		return;
		}
		//alert(node.childNodes.length);
		while (node.childNodes.length > 0) {
		node.removeChild(node.childNodes[0]);
		}
		//alert("Deleting....");	
		node.removeNode(true);
		currDeleteID			= "";
}

function cancBubbling(evt)
	{
		//alert(e);
		//alert("Cancelling event..");
		if (!e) var e = (window.event) ? window.event : evt;
			e.cancelBubble = true;
			if (e.stopPropagation){
				e.cancelBubble = true;
				e.stopPropagation();
				e.returnValue=false;
				e.cancel = true;
				//alert("OH MOZILLA YOU FOOL!");
		}
		
	}
    
   
//set short hand document.getElementById
function $(id) { 
    return document.getElementById(id); 
}
    
function findElemWidth(elem){
     return($(elem).style.width);
}

function findElemHeight(elem){
    return($(elem).style.width);
}

function findElemPosY(elem){
     return($(elem).style.top);
}

function findElemPosX(elem){
     return($(elem).style.left);
}

function makePositionABS(elem,posX,posY){
    if($(elem).style.position != 'absolute'){
        $(elem).style.position = 'absolute';
        $(elem).style.left     = posX;
        $(elem).style.top      = posY;
        return true
    }
    
    return false;
}

//get the highlighted text
//make it easier to Blackball by just higlighting the text
function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;

    if(txt != ""){
        alert(txt);
    }
}

function setCurrent(holder,sel,activator){
	//first we need to get the holder object
	var navHolder			= document.getElementById(holder);
	//get the a tags
	aTags					= navHolder.getElementsByTagName('a');
	//now set all there id's to nothing
	for(i=0;i<aTags.length;i++){
		aTags[i].id			= "";
	}
	
	//now set the selected a tag to current
	sel.id 					= activator;
	
}

//manage multiple onLoad events
/************ USAGE ***************
addOnloadEvent(myFunctionName);

// Or to pass arguments

addOnloadEvent(function(){ myFunctionName('myArgument') });
********************************** */
function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}


function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
}

function openBrWindow(theURL,winName,features) { 
  win		= window.open(theURL,winName,features);
  
  if(!win){
	  alert("Your popup blocker may have blocked an important window. please add this site to your list of trusted sites!");
	  }
}

function goToUrl(url){
    if(url != ""){
        window.location                 = url;
        return;
    }
}

//set up the dojo requester
function doRequest(address,contentDiv,returnFunct,query,isGet,showProgressDiv,returnMime){
        //we will use the dojo lib as the xmlHTTPRequest library
        //if we need to pass a wquery to the script then we will store it in a vairable in the form 
        //query              = {drugs:"love"};

               
        //determine wether to show the div
		if(showProgressDiv){
			if(contentDiv != "" && contentDiv != null){
			 document.getElementById(contentDiv).innerHTML = "Loading Content.... ";
			}
		}
		
        
        //set up the posttype default value
		if(isGet){
				requestType = 'GET';
			}
		else{
                requestType = 'POST'; 
        }
        
        if(!returnMime || returnMime == ""){
            returnMime          = "text/plain";
        }
         
    //do the dojo bind    
    dojo.io.bind({
        url: address,
        method: requestType,
        content: query,
        load: function(type, data, evt){
                eval(returnFunct+'(data,\''+contentDiv+'\')');
        },
        mimetype: returnMime
        });
         
}


//set up the dojo requester
function doFormRequest(address,contentDiv,formNam,returnFunct,isGet,showProgressDiv,returnMime){
        //we will use the dojo lib as the xmlHTTPRequest library
        //if we need to pass a wquery to the script then we will store it in a vairable in the form 
        //query              = {drugs:"love"};
        
        //determine wether to show the div
		if(showProgressDiv){
			if(contentDiv != "" && contentDiv != null){
			showLoader(contentDiv);
			}
			
			else{
				alert("You need to pass the name of the div where the loader must show!");
				}
		}
        
        //set up the posttype default value
		if(isGet){
				requestType = 'GET';
			}
		else{
                requestType = 'POST'; 
        }
        
        if(!returnMime || returnMime == ""){
            returnMime          = "text/plain";
        }
    //do the dojo bind    
    dojo.io.bind({   
        url: address,
        method: requestType,
        formNode: document.getElementById(formNam),
        load: function(type, data, evt){
           eval(returnFunct+'(data,\''+contentDiv+'\')');
        },
        mimetype: returnMime
        }); 
        return false
}
    

