if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=hide;

var current_sub='';	
var current_img='';
var img_height=30;
var img_width=15;
var xOffset=12;
var yOffset=22;


function hideDivs(sub_menu){
	if(current_sub!='' && current_sub!=sub_menu){
		changeObjectVisibility(current_sub,'hidden');
		current_sub='';
	}			
}


function show(sel_img,sub_menu){
	var x = getImageLeft(sel_img) - img_width + xOffset;
	var y = getImageTop(sel_img) + yOffset;

	hideDivs(sub_menu);
	
	current_sub=sub_menu;
	current_img=sel_img;

	moveXY(sub_menu, x, y);
	changeObjectVisibility(sub_menu,'visible');
}


function hide(e) {
	if(current_sub!=''){
		var xTopLeftCorner = getImageLeft(current_img) - img_width + xOffset;
		var yTopLeftCorner = getImageTop(current_img) - img_height + yOffset;
		var xBottomRightCorner = xTopLeftCorner + getElementWidth(current_sub);
		var yBottomRightCorner = yTopLeftCorner + getElementHeight(current_sub) + img_height;		
		var xmouse;
		var ymouse;

//alert(xTopLeftCorner + "," + yTopLeftCorner + " - " + xBottomRightCorner + "," + yBottomRightCorner);
		
		if (document.layers){
			xmouse=e.pageX;
			ymouse=e.pageY;			  
		}else if(document.all){
			xmouse=event.x;
			ymouse=event.y+document.documentElement.scrollTop;
		}else{ 
			xmouse=e.pageX;
			ymouse=e.pageY;						
		}
//alert(xmouse + "," + ymouse);
		
		if(!(xmouse>=xTopLeftCorner && xmouse<=xBottomRightCorner && ymouse>=yTopLeftCorner && ymouse<=yBottomRightCorner)){
			changeObjectVisibility(current_sub,'hidden');
			current_sub='';
		}					
	}
}


function trim(strText) { 
	// this will get rid of leading spaces 
	while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);
	
	// this will get rid of trailing spaces 
	while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, strText.length-1);
	
	return strText;
}


String.prototype.right = function (numOf) { 
	var tmp = "";
	for (i=this.length-numOf; i<this.length; i++) {
		tmp += this.charAt(i);
	}
	return tmp;
};


function validDOC(docSrc){
	var isValid=false;
	
	docSrc=docSrc.toLowerCase();
	
	for(x=0;x<validExt.length;x++){
		if(docSrc.right(validExt[x].length)==validExt[x]){
			isValid=true;
			break;
		}
	}
	
	return isValid;
}		


function popUp(picPath,picWidth,picHeight){
	var winLeft = screen.availWidth;
	winLeft=(winLeft/2)-(picWidth/2);
	window.open("/pic.asp?picPath=" + picPath,"Informations","width=" + picWidth + ",height=" + picHeight + ",left=" + winLeft + ",top=0,menubar=0,location=0,toolbar=0,personalbar=0,status=0,resizable=1,scrollbars=0");
}


function GetXmlHttpObject(){    
  var xmlHttp=null;
  
  try{    // Firefox, Opera 8.0+, Safari    
    xmlHttp=new XMLHttpRequest();
  }catch (e){    // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
    }
  }
	
	return xmlHttp;
}


function blockAccess(newState){
	changeObjectVisibility('showModal',newState);
	changeObjectVisibility('designKit',newState);
}


function openDesignKit(strType, strName, strDescription, intImgID, strImage) {
  document.getElementById('designKitType').value = strType;
  document.getElementById('designKitTitle').innerHTML = '<h2>' + strName + '</h2>';
  document.getElementById('designKitDescription').innerHTML = '<font class="txtWhite">' + strDescription + '</font>';
  document.getElementById('designKitImageID').value = intImgID;
  document.getElementById('designKitImage').src = strImage;

  document.getElementById('designKit').style.left = (document.body.offsetWidth - 400) / 2 + "px";
  document.getElementById('designKit').style.top = (document.body.offsetHeight - 310) / 2 + "px";
  
	blockAccess('visible');
}


function addToDesignKit(strType, ID, strComments) {
  xmlHttp = GetXmlHttpObject();
//alert(strType);
  if (xmlHttp != null){
    xmlHttp.open("GET", "/_add_to_design_kit.asp?type=" + strType + "&id=" + ID + "&comment=" + strComments);
    xmlHttp.send(null);    
  }
}


function displayBig(ID, name, imageLarge, imageSmall) {
  document.getElementById("divName").innerHTML = name;
  document.getElementById("imgImage").src = imageLarge;
  //Set the image ID for the My Design Kit
  document.getElementById("hdnImageID").value = ID;
  //Change the picture in the My Design Kit window
  //document.getElementById("imgDesignKit").src = imageSmall;
  document.getElementById("lnkLargeImg").href = imageSmall;
  document.getElementById("lnkLargeImg").title = name;

}
