//********************************************************************
//*-------------------------------------------------------------------
//* Licensed Materials - Property of IBM
//*
//* WebSphere Commerce
//*
//* (c) Copyright IBM Corp. 2007
//*
//* US Government Users Restricted Rights - Use, duplication or
//* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//*
//*-------------------------------------------------------------------
		
	/************************************************************
	 *	WORK PENDING											*
	 *	1. JavaDoc for Compare Function							*
	 *	2. Dependency of HTML forms and element					*
	 *	3. Moving Global variable and Functions to Global.js	*
	 *	4. Fixing few defect in Compare Functions				*
	 *		i.e:Should not accept same item in compareZone		*
	 *			Should allow to frag items from compareZone		* 
	 ************************************************************/


	dojo.require("dojo.widget.PopupContainer");
	dojo.require("dojo.widget.ContentPane");
	
	/******************************************************************************************************************
	 *                                        GLOBAL VARIABLES & FUNCTIONS                                            *
	 *                                                    START                                                       *
	 ******************************************************************************************************************/
function openEnlargePopup(url, divId, currentItemId, replacedId){

	if (productPageLoaded)
	{
		// alert(currentItemId + '+' + replacedId);
		var currentIdDiv = dojo.byId(currentItemId);
		var replacedIdDiv = dojo.byId(replacedId);
		if(currentIdDiv){
			url = url + '&itemId='+ currentIdDiv.innerHTML;
		}else{
			url = url + '&itemId=0';
		}
		if(replacedIdDiv){
			url = url + '&imgId='+ replacedIdDiv.innerHTML;
		}else{
			url = url + '&imgId=0';
		}
	
		// alert(url);
	    var content = dojo.widget.byId(divId);
	    content.show(); 
	    // set popup contents from pURL
	    content.setUrl(url);
		return false;
	}
}

function openPopup(url, divId){
	//if (productPageLoaded)
 //   {
	    var content = dojo.widget.byId(divId);
	    content.show(); 
	    // set popup contents from pURL
	    content.setUrl(url);
		return false;
//	}
}

function openPopupSize(url, divId){
	if (productPageLoaded)
   {
	    var content = dojo.widget.byId(divId);
	    content.show(); 
	    // set popup contents from pURL
	    content.setUrl(url);
		return false;
	}
}


function openRewardPointsPopup(url, divId, itemId){
	if (productPageLoaded)
	{
		var id = dojo.widget.byId("catid").comboBoxSelectionValue.value;
		
		if(id == 0)
			url = url + '&itemid='+ itemId;
		else
			url = url + '&itemid='+ id;
			
	//	alert(url);
	    var content = dojo.widget.byId(divId);
	    content.show(); 
	    // set popup contents from pURL
	    content.setUrl(url);
		return false;
	}
}

function hidePopup(divId)
{
	// get the popup by id to close
	var pane = dojo.widget.byId(divId);
	// close the popup
	if (dojo.byId('bubble'))
 	{
 		dojo.html.setDisplay('bubble',false); 
 	}
	pane.hide();
}
	              
function showPopup(pURL, pWidth, pHeight, pParentId, pPopupId, pContentId){
	// calculate the width and height of the displayed page.
	// Browser window inner width
	iWidth = window.innerWidth?window.innerWidth:document.body.clientWidth;
	// Browser window inner height
	iHeight = window.innerHeight?window.innerHeight:document.documentElement.clientHeight;
	// Browser window vertical scroll height
	sHeight = window.pageYOffset?window.pageYOffset:document.body.scrollTop;
	// Calculate x position of the popup
	x = (iWidth - pWidth) / 2;
	x = Math.round(x);
	// Calculate y position of the popup
	y = (iHeight - pHeight) / 2;               
	y = sHeight + y;
    y = Math.round(y);  
    alert(x+":"+y);
    // get the parent div of the popup
    var parent = dojo.byId(pParentId); 
    // get the popup div  
    var pane = dojo.widget.byId(pPopupId);
    alert(pane);
    // get the content div inside the popup
    var content = dojo.widget.byId(pContentId);
    // open the popup at x, y position
     alert(content);
    pane.open(x, y, parent); 
	content.show();
    // set popup contents from pURL
    content.setUrl(pURL);

	return false;
}      


// update add to cart params, and close the quick view popup
function closePopup(popupId)
{
	try{
		if(document.getElementById('bubble'))
			dojo.dom.removeNode(document.getElementById('bubble'));
		if(popupId.indexOf('qv_popup') >-1){
			
			
		}  
		  
	}catch(e){

	}
	// get the popup by id to close
	var pane = dojo.widget.byId(popupId);
	// close the popup
	pane.close();
}

