// $Revision: 1.1 $
// $Id: standard.js,v 1.1 2004/05/21 21:23:20 cvsapril Exp $

menusOpen = new Object();// to track open menu ids used by clearMenus()
clearMenusExemption = new Object();



function clearMenus(activeMenuSwitch){ // will hide all open menus that used: menusOpen[anchor_id + '_menu']
	// if(window.doDrag){clearDragEvent()};
	for(var id in menusOpen){
		if((document.getElementById(id) != null) && (clearMenusExemption[id] != true))  {
	           document.getElementById(id).style.visibility = 'hidden';
	           menusOpen[id] =  null;// remove from openMenus obj property list
		}
	}
	if(activeMenuSwitch != 'activemenu=true'){// activemenu=true keeps the onmouseover showMenu() active
		window.activemenu=false
	}
}// end fn


function truncate(theString, max, ellipsis) {
  if(theString.length <= max){
    return theString; // don't process if it's short already
  }
    var tempArray = theString.split(' ');
    var theCurrentlength = 0;
    var theNewString = new Array();
    if(ellipsis==true){max -= 3};
    var truncated = false;

    for (var i=0; i<tempArray.length; i++){
      theCurrentlength += tempArray[i].length + 1;
      theNewString.push(tempArray[i]);
      if (theCurrentlength > max){
        truncated = true;
        break;
      }
    }// end for
  if(truncated && ellipsis){theNewString.push('...')};
  return(theNewString.join(' '));
}// end fn




function replaceAll(objId, replaceWhat, replaceWith ){ // this replaces all innerHTML of an element called objId
     var obj = document.getElementById(objId);
     var regX = new RegExp(replaceWhat,"g");
     obj.innerHTML = obj.innerHTML.replace(regX, unescape(replaceWith));
}// end fn





function getAnchorPosition(anchor_id) {// This function will return an Object with x and y properties
	var position=new Object();
	// Logic to find position
	position.x=AnchorPosition_getPageOffsetLeft(document.getElementById(anchor_id));
	position.y=AnchorPosition_getPageOffsetTop(document.getElementById(anchor_id));
	return position;
}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while((el=el.offsetParent) != null) {
	  ol += el.offsetLeft;
	}
	return ol;
}// end fn



function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while( (el=el.offsetParent) != null) {
	  ot += el.offsetTop;
	}
	return ot;
}// end fn



function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
    	return false;
    }
} // end fn


function getObjById(id) { // 
    return document.getElementById(id);
}


function getStyleObject(objectId) {
     if(document.getElementById(objectId)){
	   return (document.getElementById(objectId).style);
     } else {
	   return false;
     }
} // end fn


function moveObject(objectId, newXCoordinate, newYCoordinate) {
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
    }
} // end fn



function showElement(){ //usage showElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=showElement.arguments.length; i++) {
    element = document.getElementById(showElement.arguments[i]);
      if(element){
         element.style.display='block';
      }
 }
}// end fn



function hideElement(){  //usage hideElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=hideElement.arguments.length; i++) {
    element = document.getElementById(hideElement.arguments[i]);
      if(element == null) { continue };
    element.style.display='none';
 }
}// end fn




function toggleView(){ //usage toggleView('id1','id2','id3','id4','etc')
  var element;
  for (var i=0; i<=toggleView.arguments.length; i++) {
    element = document.getElementById(toggleView.arguments[i]);
       if(element == null) { continue };
    element.style.display=='' ?  element.style.display='none' : element.style.display='';
  }// end for
 }



function toggleImg(img, fromThis, toThat) {// toggles images usage is toggleImg(this,img1,img2)
     var regX = new RegExp(fromThis,'');
     img.src.match(regX) ? img.src=img.src.replace(fromThis,toThat) : img.src=img.src.replace(toThat,fromThis);
}// end fn




function toggleClass(objId, fromThisClass, toThatClass) {// toggles classes, usage is toggleClass(id,class1,class2)
     var obj = document.getElementById(objId);
     obj.className == fromThisClass ? obj.className = toThatClass : obj.className = fromThisClass;
}// end fn

 


 
function positionDiv(divId,xAlign,yAlign,newWidth,newHeight,nudgeX,nudgeY,closeAfterMs) { // only divId is mandatory
        var horiz,vert,obj;
	obj=document.getElementById(divId);
	if(newWidth!=null) {obj.style.width=newWidth + 'px'};
        if(newHeight!=null) {obj.style.height=newHeight + 'px'};
        if(nudgeX==null){nudgeX=0};
	if(nudgeY==null){nudgeY=0};
         // use either DOM or NS4+ to get window size and position
        document.body.clientWidth ? horiz=document.body.clientWidth : horiz=window.innerWidth;
       // first is IE because it does not do innerHeight *BUT* Safari does body.clientHeight, differently.  DOM is second for Mozilla and Safari
        document.body.clientHeight  && !window.innerHeight ? vert=document.body.scrollTop+document.body.clientHeight : vert=window.innerHeight+window.pageYOffset;

        if (xAlign=='right') {
              horiz = (horiz-parseInt(obj.style.width) - 40);
        } else if (xAlign=='left')  {
        	horiz = horiz - (horiz - 20);
        } else {// center it
               horiz = (horiz - parseInt(obj.style.width))/2;
        }
        if (yAlign=='top') {
            if(window.pageYOffset){document.body.scrollTop=window.pageYOffset};// kludge for IE
             vert = 20 + document.body.scrollTop;
        } else if (yAlign=='bottom')  {
        	vert = vert - (parseInt(obj.style.height) +  40);
        } else {// middle
        	document.body.clientHeight && !window.innerHeight ? vert=document.body.scrollTop+document.body.clientHeight/2 : vert=window.innerHeight/2+window.pageYOffset;
        	vert -= parseInt(obj.style.height)/2;
        }
        obj.style.left = horiz + nudgeX;
        obj.style.top = vert + nudgeY;
        obj.style.visibility='visible';
        if(closeAfterMs!=null) { // optional hide after x ms
        	positionDiv[divId]=  setTimeout("changeObjectVisibility('" + divId + "', 'hidden') ", closeAfterMs);
        }

        if(window.scrollTo){scrollTo(0,document.body.scrollTop)};//  Mozilla bug fix to prevent window jumping

}// end fn




function safeFormUpdate(formName,formField,formProperty,newValue){ // avoids js errors when form fields do not exist
	if(document[formName] && document[formName][formField] && document[formName][formField][formProperty]!=null){
	   document[formName][formField][formProperty] = newValue;
	   return true;
	} else {
	   return false;
	}
}// end fn


function eveMenu(anchor_id, nudgeX, nudgeY, noClear){ // shows the div called id + '_menu'; NudgeX/Y If noClear=true it will skip closing the other active menus
	if(window.activemenu!=true) {return};
	if(nudgeX==null){nudgeX=0};
	if(nudgeY==null){nudgeY=0};
	if(noClear!=true){clearMenus('activemenu=true')};

	var position = getAnchorPosition(anchor_id);
	if(document.getElementById('gs_menu_y_baseline')) {position.y = getAnchorPosition('gs_menu_y_baseline').y};
        moveObject(anchor_id + '_menu', position.x-1+nudgeX,position.y + nudgeY);
        changeObjectVisibility(anchor_id + '_menu','visible');
	menusOpen[anchor_id + '_menu'] = true;// track open ids - this obj was instantiated on script load
} // end fn

// begin stuff moved out of master.inc



function nameWin()
{
window.name = "launcher";
}

  function changeWindow(value){
                if (value != 'Category'){
                        window.location=value;
                }
                else{
                        return false;
                }
        }
        
        function showElement(){ //usage showElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=showElement.arguments.length; i++) {  
    element = document.getElementById(showElement.arguments[i]);
      if(element == null) { continue };
    element.style.display=''; 
 }   
}// end fn

  
  
function hideElement(){  //usage hideElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=hideElement.arguments.length; i++) {  
    element = document.getElementById(hideElement.arguments[i]);
      if(element == null) { continue };
    element.style.display='none';
 } 
}// end fn


function toggleView(){ //usage toggleView('id1','id2','id3','id4','etc')
  var element;
  for (var i=0; i<=toggleView.arguments.length; i++) {  
    element = document.getElementById(toggleView.arguments[i]);
       if(element == null) { continue };
    element.style.display=='' ?  element.style.display='none' : element.style.display='';
  }// end for   
 }
 
  function domainType(value){
                if (value == 'new_domain'){
                     showElement('suffix');
                     hideElement('infopop_suffix');
                      showElement('desired');
                }
                else if (value == 'infopop_new'){
                        hideElement('suffix');
                         showElement('infopop_suffix');
                         showElement('desired');
                }
                else if (value == 'existing_infopop'){
                        hideElement('suffix');
                         showElement('infopop_suffix');
                         hideElement('desired');
                } else {
                     hideElement('suffix');
                        hideElement('infopop_suffix');
                        hideElement('desired');
                }
        }
        


