//********************************************************************
//*-------------------------------------------------------------------
//* 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;
		var id;
		if(resolvedItem != 'undefined' && resolvedItem != null)
			id = resolvedItem;
		else
			id = 0;
		
		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();
}

function replaceMainImageAltView(imageName,divName, altView, replacedImgId)
{
	var replacedIdDiv = dojo.byId(replacedImgId);
	try{
		replacedIdDiv.innerHTML = altView; 
	}catch(e){}    
		
	var mainimg = dojo.byId(divName);

	// change the button image back
    mainimg.setAttribute('src','http://s7ondemand1.scene7.com/is/image/MoosejawMB/'+imageName);
    
    dojo.lfx.html.fadeShow(mainimg, 600).play();
}

function replaceAltAndGearView(altViewId, newAltViewId, iid, currentId) 
{
	var currentIdDiv = dojo.byId(currentId);
	try{
		currentIdDiv.innerHTML = '0'; 
		if(currentIdDiv){
			currentIdDiv.innerHTML = iid;
		}
	}catch(e){}        
	// replace the main image with the first altview
	var altDiv = dojo.byId(altViewId);
	var id = newAltViewId;
	var img1 = dojo.byId(iid+'_img1');
	if (img1)
	{
		dojo.byId(iid+'_imgsrc1').src = img1.innerHTML;
		dojo.byId(iid+'_imgsrc1').width = 50;
		dojo.byId(iid+'_imgsrc1').height = 50;
	}
	var img2 = dojo.byId(iid+'_img2');
	if (img2)    
	{ 
		dojo.byId(iid+'_imgsrc2').src = img2.innerHTML;
		dojo.byId(iid+'_imgsrc2').width = 50;
		dojo.byId(iid+'_imgsrc2').height = 50;  
	}
	var img3 = dojo.byId(iid+'_img3');
	if (img3)
	{
		dojo.byId(iid+'_imgsrc3').src = img3.innerHTML;
		dojo.byId(iid+'_imgsrc3').width = 50;
		dojo.byId(iid+'_imgsrc3').height = 50;
	}
	var img4 = dojo.byId(iid+'_img4');
	if (img4)
	{
		dojo.byId(iid+'_imgsrc4').src = img4.innerHTML;
		dojo.byId(iid+'_imgsrc4').width = 50;
		dojo.byId(iid+'_imgsrc4').height = 50;
	}
	var img5 = dojo.byId(iid+'_img5');
	if (img5)
	{
		dojo.byId(iid+'_imgsrc5').src = img5.innerHTML;
		dojo.byId(iid+'_imgsrc5').width = 50;
		dojo.byId(iid+'_imgsrc5').height = 50;
	}
	var img6 = dojo.byId(iid+'_img6');
	if (img6)
	{
		dojo.byId(iid+'_imgsrc6').src = img6.innerHTML;
		dojo.byId(iid+'_imgsrc6').width = 50;
		dojo.byId(iid+'_imgsrc6').height = 50;
	}
	var img7 = dojo.byId(iid+'_img7');
	if (img7)
	{
		dojo.byId(iid+'_imgsrc7').src = img7.innerHTML;
		dojo.byId(iid+'_imgsrc7').width = 50;
		dojo.byId(iid+'_imgsrc7').height = 50;
	}
	var img8 = dojo.byId(iid+'_img8');
	if (img8)
	{
		dojo.byId(iid+'_imgsrc8').src = img8.innerHTML;
		dojo.byId(iid+'_imgsrc8').width = 50;
		dojo.byId(iid+'_imgsrc8').height = 50;
	}
	var img9 = dojo.byId(iid+'_img9');
	if (img9)
	{
		dojo.byId(iid+'_imgsrc9').src = img9.innerHTML;
		dojo.byId(iid+'_imgsrc9').width = 50;
		dojo.byId(iid+'_imgsrc9').height = 50;
	}
	var img10 = dojo.byId(iid+'_img10');
	if (img10)
	{
		dojo.byId(iid+'_imgsrc10').src = img10.innerHTML;
		dojo.byId(iid+'_imgsrc10').width = 50;
		dojo.byId(iid+'_imgsrc10').height = 50;
	}
	var newAltDiv = document.getElementById(id);
	var altHTML = trim(newAltDiv.innerHTML);  
	altDiv.innerHTML = '';
	if(altHTML != ''){ 
		altDiv.innerHTML = altHTML;
	}
	dojo.lfx.html.fadeShow(dojo.byId(altViewId), 600).play();
	return false;  
}

function removeThisImg(imgRef){ 

	dojo.html.setDisplay(imgRef,false);
	
}
