// commonpopup.js
 
// popup window Function

function popup(pf,height,width,scrollbars,top,left,name)
{
	if(height == null)
	{
		height=340;
	}
	if(width == null)
	{
		width=488;
	}
	if(top == null)
	{
		top=100;
	}
	if(left == null)
	{
		left=200;
	}
	if(scrollbars == null)
	{
		scrollbars='YES'; 
	}
	var s = "height="+height+",width="+width+",top="+top+",left="+left+",scrollbars="+scrollbars;
    if(name == null)
    {
		window.open(pf,null,s);
	}
	else
	{
		// Focus security code field after clicking "Close Window" button of What is this popup.
		if(document.getElementById("securityCode") != null && name == "WhatIsSecurityCode")
		{
			document.getElementById("securityCode").focus();
		}
		window.open(pf,name,s);
	}	
}

function goBack()
{
	history.back();
}

function popupCalendarBasket(productPrice, productSKU, locationType, quantityIndex, dateIndex)
{
    var month = document.getElementById("cartItem(" + dateIndex + ").deliveryMonth").value;
    var year = document.getElementById("cartItem(" + dateIndex + ").deliveryYear").value;
    var zip = document.getElementById("cartItem(" + dateIndex + ").zip").value;
    var itemCount = document.getElementById("cartItem(" + quantityIndex + ").quantity").value;
    var international  = document.getElementById("cartItem(" + dateIndex + ").international").value;

    var country = "";
    if(international == 'true')
	{
		zip = '00000';
	}
    var pf = "calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+itemCount+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&dateIndex="+dateIndex;
    window.open(pf, null, "height=412,width=312,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function popupShippingCalendar(productPrice, productSKU, zip, quantity, country, groupIndex, itemId)
{
    var month = document.getElementsByName("giftMessages(" + itemId + ").deliveryMonth")[0].value;
    var year = document.getElementsByName("giftMessages(" + itemId + ").deliveryYear")[0].value;
    var locationType = document.getElementById("shippingMethods(" + groupIndex + ").locationType").value;
    var pf = "calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+quantity+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&itemId="+itemId;
    window.open(pf, null, "height=412,width=312,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function popupDeliDateCalendar(itemIndex)
{
    var form = document.getElementById("mgcdeliverydate");
    var month = (document.getElementsByName('deliveryDate('+itemIndex+').deliveryMonth'))[0].value;
    var year = (document.getElementsByName('deliveryDate('+itemIndex+').deliveryYear'))[0].value;
    var locationType = form.elements["location"].value;
    var itemCount = 1;
    var zip = form.elements["zip"].value;
    var country = "";
    var productSKU = form.elements["sku"].value;
    var productPrice = form.elements["price"].value;
    var pf ="calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+itemCount+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&deliDate=true"+"&itemIndex="+itemIndex;
    window.open(pf, null, "height=412,width=312,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function popupCalendar()
{
    var month = document.getElementById("deliveryMonth").value;
    var year = document.getElementById("deliveryYear").value;
    var locationType = document.getElementById("locationCode").value;
    var itemCount = 1;
    var quantity = document.getElementById("quantity");
    var contextPageType = "undefined";
    var cpt = document.getElementById("contextPageType");
		if (cpt != null)
		{
			contextPageType = cpt.value;
		}

    if(quantity != null)
    {
    	itemCount = quantity.value;
    }
    var zip = document.getElementById("zipCode").value;
    var international = document.getElementById("international").value;
    
    	if(international == 'true')
    	{
    		zip = '00000';
	} 
    var country = "";
//    var skuselect = document.getElementById("sku");
//    var productSKU = skuselect.options[skuselect.selectedIndex].value;
//    var productPrice = skuselect.options[skuselect.selectedIndex].getAttribute("skuprice");
	var checkedSku;
	var skuArray = document.getElementsByName("sku");

	for(var i=0;i<skuArray.length;i++)
	{
		if(skuArray[i].checked == true)
		{
			checkedSku = skuArray[i];
			break;
		}
	}
	var productSKU = checkedSku.value;
	var productPrice = checkedSku.getAttribute("skuprice");
    var pf ="calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+itemCount+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&contextPageType="+contextPageType;
    window.open(pf, null, "height=412,width=312,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function popupGiftNotice()
{
	window.open("giftnotice.do", null, "height=600,width=800,top=0,left=0,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes");
}

function popupYourChoice()
{
	window.open("yourchoice.jsp", "yourchoice", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=696,height=465,top=10,left=10");
}

//Added for GPT Addon project for Backward compatibiltiy
function popupCalendarNew(isGeoSell,prodType,bazaarVoiceDomainFlag)
{
    var locationType = document.getElementById("locationCode").value;
    var itemCount = 1;
    var quantity = document.getElementById("quantity");
    var contextPageType = "undefined";
    var cpt = document.getElementById("contextPageType");
		if (cpt != null)
		{
			contextPageType = cpt.value;
		}
	
	if (bazaarVoiceDomainFlag == null) {
		bazaarVoiceDomainFlag = false;
	}
	
	var month = null;
	var today = new Date();
	
	if(document.productForm.deliveryMonth != null && document.productForm.deliveryMonth.value != ''){
		month = document.productForm.deliveryMonth.value;
	}else{
		month = today.getMonth() + 1;
	}
	
	var year = null;	
	if(document.productForm.deliveryYear != null && document.productForm.deliveryYear.value != ''){
		year = document.productForm.deliveryYear.value;
	}else{
		year = today.getFullYear();
	}
    
    var locationType = document.getElementById("locationCode").value;
    
    if(quantity != null)
    {
    	itemCount = quantity.value;
    }
    var zip = document.getElementById("zipCode").value;
    var country = "";
    var international = document.getElementById("international").value;

	if(international == 'true')
	{
		zip = '00000';
	}   	
	var checkedSku;
	var skuArray = document.getElementsByName("sku");

	for(var i=0;i<skuArray.length;i++)
	{
		if(skuArray[i].checked == true)
		{
			checkedSku = skuArray[i];
			break;
		}
	}
	var productSKU = checkedSku.value;
	var shiptoday  = '';
	var shiptomorrow = '';
	
	if(document.getElementById("shiptoday")){
		shiptoday = document.getElementById("shiptoday").innerHTML;
 		shiptomorrow = document.getElementById("shiptomorrow").innerHTML;	
 	}
	var productPrice = checkedSku.getAttribute("skuprice");
	var s = new String(productPrice);
	if(s){
	  productPrice = s.replace(",","");
	}
	if(shiptoday != null && shiptoday != "" ){
		pf = pf+"&shiptoday="+shiptoday;
	}
	if(shiptomorrow != null && shiptomorrow != "" ){
		pf = pf+"&shiptomorrow="+shiptomorrow; 
	}
    var pf ="calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+itemCount+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&contextPageType="+contextPageType+"&isGeoSell="+isGeoSell+"&prodType="+prodType+ "&page=product&bazaarVoiceDomainFlag=" + bazaarVoiceDomainFlag;   
    window.open(pf, null, "height=490,width=575,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function popupCalendarBasketNew(productPrice, productSKU, locationType, quantityIndex, dateIndex, isGpt)
{
    var month = document.getElementById("cartItem(" + dateIndex + ").deliveryMonth").value;
    var year = document.getElementById("cartItem(" + dateIndex + ").deliveryYear").value;
    var zip = document.getElementById("cartItem(" + dateIndex + ").zip").value;
    var itemCount = document.getElementById("cartItem(" + quantityIndex + ").quantity").value;
    var isGeoSell = false;
    if(! isGpt)
     isGeoSell = true;
    var country = "";
    var international  = document.getElementById("cartItem(" + dateIndex + ").international").value;
    if(international == 'true')
    {
    	zip = '00000';
    }
    var pf = "calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+itemCount+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&dateIndex="+dateIndex+"&isGeoSell="+isGeoSell+"&page=shoppingbasket";
    window.open(pf, null, "height=430,width=575,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function popupCalendarBasketNew(productPrice, productSKU, locationType, quantityIndex, dateIndex, isGpt,prodType)
{
    var form = document.getElementById("shoppingBasketForm");
    
    var month = form.elements["cartItem(" + dateIndex + ").deliveryMonth"].value;
    var year = form.elements["cartItem(" + dateIndex + ").deliveryYear"].value;
    var zip = form.elements["cartItem(" + dateIndex + ").zip"].value;
    var itemCount = form.elements["cartItem(" + quantityIndex + ").quantity"].value;
    //Added By Amar to validate product Type for shoppingBasket page calendar
    if(prodType==null || prodType==''){
       alert('Invalid Product Type');
       return false;
    }
    var isGeoSell = false;
    
    if(! isGpt)
     isGeoSell = true;
     var country = "";
   
   
    var international = form.elements["cartItem(" + dateIndex + ").international"].value;
    if(international == 'true')
    {
    	zip = '00000';
    }
    var pf = "calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+itemCount+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&dateIndex="+dateIndex+"&isGeoSell="+isGeoSell+"&prodType="+prodType+"&page=shoppingbasket";
    window.open(pf, null, "height=430,width=575,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}
function popupShippingCalendarNew(productPrice, productSKU, zip, quantity, country, groupIndex, itemId)
{
    var month = document.getElementsByName("giftMessages(" + itemId + ").deliveryMonth")[0].value;
    var year = document.getElementsByName("giftMessages(" + itemId + ").deliveryYear")[0].value;
    var locationType = document.getElementById("shippingMethods(" + groupIndex + ").locationType").value;
    var pf = "calendar.do?month="+month+"&year="+year+"&locationType="+locationType+"&itemCount="+quantity+"&productPrice="+productPrice+"&zip="+zip+"&country="+country+"&productSKU="+productSKU+"&itemId="+itemId;
    window.open(pf, null, "height=430,width=575,top=100,left=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}
