

// *********************************************************************
// Function to create pop-up windows at a custom size.
// w = width
// h = height
// d = directories
// l = location
// m = menubar
// r = resizeable
// sc = scrollbars
// st = status
// t = toolbar
// EXAMPLE CALL: <a href="javascript:popUp('[URL]','[WINDOW NAME]',400,300,1,1,0,0,0,0,0);">LINK</a>
// *********************************************************************
function popUp(URL,name,w,h,d,l,m,r,sc,st,t) {
	var featureStr = "";
	featureStr = "width=" + w + ",height=" + h + ",directories=" + d + ",location=" + l + ",menubar=" + m + ",resizable=" + r + ",scrollbars=" + sc + ",status=" + st + ",toolbar=" + t;
	window.open(URL,name,featureStr);
}

// ***** Show/Hide for email, save, print page icons ***************************************
var state = "none"; 
function showHideUtility(layer) { 
	if (state == "block") { 
		state = "none"; 
	} else { 
		state = "block"; 
	} 
	if (document.getElementById) {
		eval( "document.getElementById('" + layer + "').style.display = state"); 
	}
}
// *********************************************************************

// *********************************************************************
function returnimgcode(theimg) {
	var imghtml = ""
	if (theimg[1] != "") imghtml = '<a href="' + theimg[1] + '" target="' + optlinktarget + '">'
	imghtml += '<img src="' + theimg[0] + '" border="' + imgborderwidth + '">'
	if (theimg[1] != "") imghtml += '</a>'
	imghtml += '<br /><br /><p>' + theimg[2] + '</p>'
	return imghtml
}
function modifyimage(loadarea, imgindex) {
	if (document.getElementById) {
	var imgobj = document.getElementById(loadarea)
	if (imgobj.filters && window.createPopup) {
	imgobj.style.filter = filterstring
	imgobj.filters[0].Apply()
	}
	imgobj.innerHTML = returnimgcode(dynimages[imgindex])
	if (imgobj.filters && window.createPopup)
	imgobj.filters[0].Play()
	return false
	}
}

// *********************************************************************

// ***** Show/Hide Div blocks that need to replace each other  ***************************************
function hideAll() {
	if (document.getElementById) {
		var index = 0;
		while (document.getElementById("block" + index)) {
			document.getElementById("block" + index).style.display="none";
			index++;
		}
	}
}
function showBlock(index) {
	var currentId = "block" + index;
	hideAll();
	document.getElementById(currentId).style.display = "block";
}
// *********************************************************************


// ***** Show/Hide Dynamic DIV Popup Window (ex: ProductInformation - View Larger)  ***************************************

var req;

function showPopUp( url, w, h, event ) {
	
	var posX = 0;
	var posY = 0;
	var screenWidth = 0;
	var screenHeight = 0;
	var totalWindowX = 0;
	var totalWindowY = 0;
	var divOffsetX = 0;
	var divOffsetY = 0;
	
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	var theBody = document.documentElement;
  	var scTop = parseInt(theBody.scrollTop,10);
 	var scLeft = parseInt(theBody.scrollLeft,10);
  	posY = scTop + ((fullHeight - h) / 2);
	posX =  scLeft + ((fullWidth - w) / 2);
	
	//if (event.pageX || event.pageY)
	//{
	//	totalWindowX = window.pageXOffset;
	//	screenWidth  = screen.width;
	//	divOffsetX	 = w / 2;
	//	posX 		 = totalWindowX + (screenWidth / 2) - (divOffsetX);
		
	//	totalWindowY = window.pageYOffset;
	//	screenHeight = screen.height;
	//	divOffsetY	 = h / 2;
	//	posY 		 = totalWindowY + (screenHeight / 2.5) - (divOffsetY);
	//}
	//else if (event.clientX || event.clientY)
	//{
	//	totalWindowX = document.documentElement.scrollLeft;
	//	screenWidth  = screen.width;
	//	divOffsetX	 = w / 2;
	//	posX 		 = (totalWindowX + (screenWidth / 2)) - (divOffsetX);
		//alert("IE = " + posX);
		
	//	totalWindowY = document.documentElement.scrollTop;
	//	screenHeight  = screen.height;
	//	divOffsetY	 = h / 2;
	//	posY 		 = totalWindowY + (screenHeight / 2.5) - (divOffsetY);
		//alert("IE = " + posY);
	//}
	
   	var divToProcess = document.getElementById( "popUp" );
	divToProcess.style.left = posX + 'px';
	//alert(window.pageXOffset);
	divToProcess.style.top = posY + 'px';
	//alert(window.pageYOffset);

	
   	if( window.XMLHttpRequest) {
		
      	req = new XMLHttpRequest();
      	req.onreadystatechange = processStateChange;
      	try {
         	req.open( "GET", url, true );
      	} catch( e ) {}

      	req.send( null );
   	} else if( window.ActiveXObject ) {
      	req = new ActiveXObject( "Microsoft.XMLHTTP" );
      	if( req ) {
         	req.onreadystatechange = processStateChange;
         	req.open( "GET", url, true );
         	req.send();
      	}
   	}
}

function processStateChange() {
   	if( req.readyState == 4 ) {
      	var divToProcess = document.getElementById( "popUp" );
      	divToProcess.innerHTML = req.responseText;
      	divToProcess.style.display = 'block';
   	}
}

function getViewportHeight() {
 if (window.innerHeight!=window.undefined) return window.innerHeight;
 if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
 if (document.body) return document.body.clientHeight; 
 return window.undefined; 
}
function getViewportWidth() {
 if (window.innerWidth!=window.undefined) return window.innerWidth; 
 if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
 if (document.body) return document.body.clientWidth; 
 return window.undefined; 
}


function closeParent() {
   	document.getElementById( "popUp" ).style.display = 'none';
}
