// GOSPLightBox.js

//
//-------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (c) Copyright IBM Corp. 2006
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//-------------------------------------------------------------------
//
//GLOBAL VARIABLES
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var nameOffset,verOffset;
var yPageScroll;



//Function to Show Light box.
function browserDetect(){
    // In MSIE, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
	 browserName = "Microsoft Internet Explorer";
	}
	// In Opera, the true version is after "Opera" 
	else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
	 browserName = "Opera";
	}
	// In Chrome, the true version is after "Chrome" 
	else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
	 browserName = "Chrome";
	}
	// In Safari, the true version is after "Safari" 
	else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
	 browserName = "Safari";
	}
	// In Firefox, the true version is after "Firefox" 
	else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
	 browserName = "Firefox";
	}
	// In most other browsers, "name/version" is at the end of userAgent 
	else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
	{
	 browserName = nAgt.substring(nameOffset,verOffset);
	 if (browserName.toLowerCase()==browserName.toUpperCase()) {
	  browserName = navigator.appName;
	 }
	}
}

function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//Get the page scroll
function getPageScroll(){
	if (self.pageYOffset) {
		yPageScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yPageScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yPageScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yPageScroll) 
	return arrayPageScroll;
}

//SET SCROLL		    
function setScroll(x,y){
	window.scrollTo(x,y);
}

function hideSelect(){
	// Hide select boxes as they will 'peek' through the image in IE
	selects = document.getElementsByTagName("select");
	if (null != selects) {
		for (i = 0; i != selects.length; i++) {
            selects[i].style.visibility = "hidden";
    	}			
	}        
}
function showSelect(){
	selects = document.getElementsByTagName("select");
	if (null != selects) {
	    for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
	}
}
function hideLightbox(targetForm){
	if (browserName == 'Microsoft Internet Explorer'){
		setScroll(0,yPageScroll);
	}
	//HIDE
	document.getElementById(targetForm).style.display='none';
	document.getElementById('fade').style.display='none';
	 if (browserName == 'Microsoft Internet Explorer'){
		showSelect();
	}	
}// end of hideLightbox
 
function onPageLoad(targetForm,url){
	browserDetect();
	showFormLightBox(targetForm,url);
}// end of onPageLoad


//SHOW LIGHT BOX METHOD - STARTS
function showFormLightBox(targetForm, url, displayError){
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objOverlay = document.getElementById('fade');
	
	var objLightbox = document.getElementById(targetForm);
	
	// alert(targetForm);
	
	//NOTIFY ME LIGHTBOX: STARTS
	if(targetForm == 'prodAvailNoticeRegForm'){
		if(displayError != undefined)
		{	
			var objErrDiv = document.getElementById("errorDiv");
			if(objErrDiv!=null)
			{
				if(displayError == "hide")			
					objErrDiv.style.display = 'none';
				else
					objErrDiv.style.display = 'block';
					document.getElementById('email_addr').value='';
			}
		}
	}
	//NOTIFY ME LIGHTBOX: ENDS
	// start for order cancel light box 
	if(targetForm == 'orderCancelWindow'){
		if(displayError != undefined)
		{	
			var objErrDiv = document.getElementById("errorDiv");
			if(objErrDiv!=null)
			{
				if(displayError == "hide")			
					objErrDiv.style.display = 'none';
				else
					objErrDiv.style.display = 'block';
					//document.getElementById('email_addr').value='';
			}
		}
	}	
	//end for order cancel light box
	//SEND TO FRIEND LIGHTBOX - STARTS
	if(targetForm == 'productEmailFriend'){
	
		if(displayError != undefined)
		{	
			if(displayError == "hide"){
				document.getElementById('yourEmail').value='';
				document.getElementById('friendEmail').value='';
				document.getElementById('messageText1').value='';				
				var mainErrorMsg = document.getElementById("mainErrMessage");
				if(mainErrorMsg != undefined){
					document.getElementById("mainErrMessage").style.display = 'none';
				}				
			}
			var objErrDiv = document.getElementById("errYourMail");
			var objErrFrndDiv = document.getElementById("errFrndMail");
			
			//YOUR EMAIL ERROR HANDLING
			if(objErrDiv!=null)
			{
				if(displayError == "hide"){
					document.getElementById('yourEmailDiv').style.left='0px';
					objErrDiv.style.display = 'none';					
					document.getElementById("errorIcon").style.display = 'none';					
				}
				else {					
					objErrDiv.style.display = 'block';
					document.getElementById("errorIcon").style.display = 'block';	 				
				}
			}
			
			//FRIENDS EMAIL ERROR HANDLING
			if(objErrFrndDiv!=null)
			{
				if(displayError == "hide"){
					document.getElementById('friendEmailDiv').style.left='0px';					
					objErrFrndDiv.style.display = 'none';
					document.getElementById("errorfrndIcon").style.display = 'none';
				}
				else {
					objErrFrndDiv.style.display = 'block';
					document.getElementById("errorfrndIcon").style.display = 'block';
					}		
			}		
		}
	}	
	//SEND TO FRIEND LIGHTBOX - ENDS
	
	
	//SEND SHOPPING CART TO FRIEND LIGHTBOX - STARTS
	
	if(targetForm == 'shoppingCartEmailFriend'){
		if(displayError != undefined)
		{	
			if(displayError == "hide"){
				document.getElementById('yourEmail').value='';
				document.getElementById('friendEmail').value='';
				document.getElementById('messageText1').value='';				
				var mainErrorMsg = document.getElementById("mainErrMessage");
				if(mainErrorMsg != undefined){
					document.getElementById("mainErrMessage").style.display = 'none';
				}				
			}
			var objErrDiv = document.getElementById("errYourMail");
			var objErrFrndDiv = document.getElementById("errFrndMail");
			
			//YOUR EMAIL ERROR HANDLING
			if(objErrDiv!=null)
			{
				if(displayError == "hide"){
					document.getElementById('yourEmailDiv').style.left='0px';
					objErrDiv.style.display = 'none';					
					document.getElementById("errorIcon").style.display = 'none';				

	
				}
				else {					
					objErrDiv.style.display = 'block';
					document.getElementById("errorIcon").style.display = 'block';				

	
				}
			}
			
			//FRIENDS EMAIL ERROR HANDLING
			if(objErrFrndDiv!=null)
			{
				if(displayError == "hide"){
					document.getElementById('friendEmailDiv').style.left='0px';				

	
					objErrFrndDiv.style.display = 'none';
					document.getElementById("errorfrndIcon").style.display = 'none';
				}
				else {
					objErrFrndDiv.style.display = 'block';
					document.getElementById("errorfrndIcon").style.display = 'block';
					}		
			}		
		}
	}	  
	
	//SEND SHOPPING CART TO FRIEND LIGHTBOX - ENDS
	
	//GOSP Review Rating LIGHTBOX - STARTS
	if(targetForm == 'productReviewRating'){
	if(displayError != undefined)
		{			
		var objErrDiv = document.getElementById("productReviewRating");				
				if(displayError == "hide")			
					objErrDiv.style.display = 'none';
				else
					objErrDiv.style.display = 'block';
					
			
		}
	}	
	//GOSP Review Rating LIGHTBOX - ENDS
	
	//GOSP Review Rating Details LIGHTBOX - STARTS
	if(targetForm == 'productReviewDetails'){
	if(displayError != undefined)
		{			
		var objErrDiv = document.getElementById("productReviewDetails");				
				if(displayError == "hide")			
					objErrDiv.style.display = 'none';
				else
					objErrDiv.style.display = 'block';
					
			
		}
	}	
	//GOSP Review Rating Details LIGHTBOX - ENDS
	/*COMMON PORTION FOR ALL PAGES: STARTS*/
	//FIX POSITION OF LIGHTBOX TO CENTER
	 if(targetForm == 'prodAvailNoticeRegForm' || targetForm == 'productEmailFriend' || targetForm ==  'productEmailFriendConfirm'
	|| targetForm ==  'prodInstockEmailConfirm' || targetForm == 'emailSuccessFrm' || targetForm == 'resetPasswordFrm' || targetForm == 'order_window' || targetForm == 'shoppingCartEmailFriend'
	||targetForm == 'productReviewRating' || targetForm == 'productReviewDetails' || targetForm == 'addtocartcrosssell' || targetForm == 'shopCartEmailFriendConfirm'){
		objLightbox.style.left = (((screen.width)/2)-250) + "px";
		objLightbox.style.top = (((screen.height)/2)-300) + "px";
	}	
	//OVERLAY FOR WHOLE PAGE   
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	
	objOverlay.style.width = (arrayPageSize[0] + 'px');	
	   
	//HIDE SELECT
	if (browserName == 'Microsoft Internet Explorer'){
		setScroll(0,0);
		hideSelect();
    }    
    //Show Lightbox and Overlay
    objOverlay.style.display = 'block';
   
    objLightbox.style.display='block';    
	/*COMMON PORTION FOR ALL PAGES: ENDS*/
	
   if(targetForm == 'resetPasswordFrm'){
	    
	    //CAPTCHA SECTION
		var time = new Date();
		var currentTime = time.getTime();
		var captchaImage1 = document.getElementById('captchaImg');
		captchaImage1.src = url + '?time='+currentTime;
		
		if(displayError != undefined)
		{			
			if(displayError == 'hide')
			{	
				document.getElementById('emailAddrValue').value='';
				document.getElementById('captchaAnswer').value='';			
				if(errFlag != '' && ncimErrMsg == ''){
					document.getElementById('emailDiv').style.left='0px';					
					document.getElementById('errorIcon').style.visibility='hidden';
					document.getElementById('errorIcon').style.display='none';
					document.getElementById('emailErrMessage').style.visibility='hidden';
					document.getElementById('emailErrMessage').style.display='none';					
				}				
				if(captchaAnswer == 'true'){
					document.getElementById("captchaDiv").style.left='0px';
					document.getElementById('errorIconForCaptcha').style.visibility='hidden';
					document.getElementById('errorIconForCaptcha').style.display='none';
					document.getElementById('captchaErrMessage').style.visibility='hidden';
					document.getElementById('captchaErrMessage').style.display='none';
				}
				if(ncimErrMsg != ''){
					document.getElementById('errorMsgFromNcim').style.visibility='hidden';
					document.getElementById('errorMsgFromNcim').style.display='none';
				}
			}
		}
    }        
}// end of showFormLightBox
//SHOW LIGHT BOX METHOD - ENDS



//SHOW LIGHT BOX METHOD FOR EW - STARTS
function showLightBox_EW(targetForm, url, displayError){
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objOverlay = document.getElementById('fade');
	var objLightbox = document.getElementById(targetForm);
	
	if(targetForm=='resetPasswordFrm')
	{
		
		objLightbox.style.left = (((screen.width)/2)-200) + "px";
		objLightbox.style.top = (((screen.height)/2)) + "px";
	}
	else
	{
		objLightbox.style.left = (((screen.width)/2)-200) + "px";
		objLightbox.style.top = (((screen.height)/2)-250) + "px";
	}
	
	//OVERLAY FOR WHOLE PAGE
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.width = (arrayPageSize[0] + 'px');	
	//HIDE SELECT
	if (browserName == 'Microsoft Internet Explorer'){
		setScroll(0,0);
		hideSelect();
    }    
    //Show Lightbox and Overlay
    objOverlay.style.display = 'block';
    objLightbox.style.display='block';   
    
    var yesButton = document.getElementById('yesButton');
    if(yesButton!=null)
    {
	    yesButton.focus();
        yesButton.select();
	    yesButton.setActive();
	}
	
	yesButton = document.getElementById('yesButtonZip');
    if(yesButton!=null)
    {
	    yesButton.focus();
        yesButton.select();
	    yesButton.setActive();
	}
	
	yesButton = document.getElementById('dkitReplaceYes');
    if(yesButton!=null)
    {
	    yesButton.focus();
        yesButton.select();
	    yesButton.setActive();
	}     
	/*COMMON PORTION FOR ALL PAGES: ENDS*/
	
         
}// end of showFormLightBox


// OrderCancel Light Box
function showLightBoxOrderCancel(targetForm, url, displayError,orderId){
		var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objOverlay = document.getElementById('fade');
	var objLightbox = document.getElementById(targetForm);
	
	// start for order cancel light box order_window    
	//alert(orderId);
	if(targetForm == 'orderCancelWindow_' + orderId){
		if(displayError != undefined)
		{	
			var objErrDiv = document.getElementById("errorDiv");
			if(objErrDiv!=null)
			{
				if(displayError == "hide")			
					objErrDiv.style.display = 'none';
				else
					objErrDiv.style.display = 'block';
					//document.getElementById('email_addr').value='';    
			}
		}
	}	
	//end for order cancel light box
	//alert(orderId);
	 if( targetForm == 'orderCancelWindow_' + orderId){
	 //alert(targetForm);
		objLightbox.style.left = (((screen.width)/2)-300) + "px";
		objLightbox.style.top = (((screen.height)/2)-300) + "px";
	}	
	//OVERLAY FOR WHOLE PAGE
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.width = (arrayPageSize[0] + 'px');	
	//HIDE SELECT
	if (browserName == 'Microsoft Internet Explorer'){
		setScroll(0,0);
		hideSelect();
    }    
    //Show Lightbox and Overlay
    objOverlay.style.display = 'block';
    objLightbox.style.display='block'; 


}



//SHOW LIGHT BOX METHOD FOR EW  - ENDS
function displayShopcartcheck(lightBox,url){
   //  alert("href before "+document.getElementById('continueURL').href);
    document.getElementById('continueURL').href=url;
  
    var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objOverlay = document.getElementById('fade');
	var objLightbox = document.getElementById(lightBox);
	//document.getElementById('vaterrmsg').style.display='none';

	if(lightBox=='shoppingcartcheck')
	{
		objLightbox.style.left = (((screen.width)/2)-250) + "px";
		objLightbox.style.top = (((screen.height)/3)) + "px";
	}
	else
	{
		objLightbox.style.left = (((screen.width)/2)-200) + "px";
		objLightbox.style.top = (((screen.height)/2)-250) + "px";
	}

	//OVERLAY FOR WHOLE PAGE
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.width = (arrayPageSize[0] + 'px');	
	//HIDE SELECT
	if (browserName == 'Microsoft Internet Explorer'){
		setScroll(0,0);
		hideSelect();
    }    
    //Show Lightbox and Overlay
    objOverlay.style.display = 'block';
    objLightbox.style.display='block';   
  //  document.getElementById('shoppingcartcheck').style.display='none';
}
