// The following function introduced on 10/31/2001 by Mohan Kaniyur
function ShowCalendar(oDoc,itemcnt,cDate,perishable,company_code,pcode,sku,pdt_type,method_code,dd_day,dd_month,dd_year,state,zip,lfc_flag,geo_sell_flag,continuity,element_idx,original_date,mst_sku,mst_month,index,size,comingFrom,cont_method_code,subscription_flag)
{
	var popup_width;
	var popup_height;
	var dt;
	var frmname;
	var delpcode;
	var subscription_flag;
	if (subscription_flag != 'S') 
	{
		subscription_flag = 'M';
	}
	if (navigator.appName == "Netscape") {
	 	if (navigator.appVersion.charAt(0) < 4) {
	 		popup_width=300;
	 		popup_height=400;
	 	}
	 	else
	 	{
	 		popup_width=305;
	 		popup_height=400;
	 	}
	}
	if (navigator.appName == "Microsoft Internet Explorer")	{
	 		popup_width=300;
	 		popup_height=400;
	 	}
	
	if (navigator.appName == "Netscape") {
		var x1 = this.screenX + (this.outerWidth  - popup_width - 30)/2;
		var y1 = this.screenY + (this.outerHeight - popup_height)/2;			 
	}
	else {
		var x1 =  (screen.width  - popup_width - 30)/2;
		var y1 =  (screen.height - popup_height)/2;
	}

	if(oDoc == "product.asp")
	{
		frmname = "check";
		if (typeof eval(document.check.sku.length) == "undefined") {
			sku = document.check.sku.value;
		} else {
			sku=GetSelectedSku();
		}
		
		if (eval("document." + frmname+".state[document." + frmname+".state.selectedIndex].text")  == "")
		{
			alert("Please select the Recipient's state.");
			eval("document."+frmname+".state.focus()");
			return;
	    }
		if (eval("document."+frmname+".zip.value") == "")
		{
			alert("Please enter a valid zip code.");
			eval("document."+frmname+".zip.focus()");
			return;
	    }
	    state = eval("document." + frmname+".state[document." + frmname+".state.selectedIndex].text");
		zip = eval("document."+frmname+".zip.value");
		dd_month = eval("document." + frmname+".dd_month[document." + frmname+".dd_month.selectedIndex].value");
		dd_day = eval("document." + frmname+".dd_day[document." + frmname+".dd_day.selectedIndex].value");
		dd_year =eval("document." + frmname+".dd_year[document." + frmname+".dd_year.selectedIndex].value")
	}
	else if(oDoc == "basket.asp")
	{		
		frmname = "FormUpdate";
		state = "state" + itemcnt;
		state = eval("document.FormUpdate."+state+"[document.FormUpdate." + state + ".selectedIndex].value;");
	
		zip = "zip" + itemcnt;
  		zip = eval("document.FormUpdate."+zip+".value");
  	 	
  		month = "month" + itemcnt;
  		dd_month = eval("document.FormUpdate."+month+"[document.FormUpdate." + month + ".selectedIndex].value;");
  	  	
		day = "day" + itemcnt;
		dd_day = eval("document.FormUpdate." + day + "[document.FormUpdate." + day + ".selectedIndex].value;");
    
		year = "year" + itemcnt;
		dd_year = eval("document.FormUpdate." + year + "[document.FormUpdate." + year + ".selectedIndex].value;");
		
		if (eval("document."+frmname+".zip"+itemcnt+".value") == "")
		{
			alert("Please enter a valid zip code.");
			eval("document."+frmname+".zip"+itemcnt+".focus()");
			return;
	    }
	}

	else if(oDoc == "continuity.asp")
	{		
		
  	 	state = state;
  	 	zip = zip;
  	 	month = dd_month
  	 	day = dd_day
  	 	year = dd_year
  	 	original_date = original_date;
  	 	element_date = cDate;
  	 	continuity_flag = continuity;
  	 	sku = sku;
  	 	mst_sku = mst_sku;
  	 	delpcode = document.continuityfrm.delpcode.value;
  	 	element_idx = element_idx;
  	 	strdetdateval = document.continuityfrm.strdetdateval.value; 	 	
		index =  index;
		size = size;  		
		cF = comingFrom;
		continuity_method_code = cont_method_code;
	}
	else if(oDoc == "edit_shipping.asp")
	{
		frmname = "addbookform";
		month = "dd_month";
  		dd_month = eval("document.addbookform."+month+"[document.addbookform." + month + ".selectedIndex].value;");
  	  	
		day = "dd_day";
		dd_day = eval("document.addbookform." + day + "[document.addbookform." + day + ".selectedIndex].value;");
    
		year = "dd_year";
		dd_year = eval("document.addbookform." + year + "[document.addbookform." + year + ".selectedIndex].value;");
		if (eval("document."+frmname+".ship_to_zip.value") == "")
		{
			alert("Please enter a valid zip code.");
			eval("document."+frmname+".ship_to_zip.focus()");
			return;
	    }
	    zip = eval("document."+frmname+".ship_to_zip.value");
	}
	else if(oDoc == "specialpromotion.asp")
	{
		frmname = "specialpromotion";
		state = "state" + itemcnt;
		state = eval("document.specialpromotion."+state+"[document.specialpromotion." + state + ".selectedIndex].value;");
	
		zip = "zip" + itemcnt;
  		zip = eval("document.specialpromotion."+zip+".value");

		month = "dd_month" + itemcnt;
  		dd_month = eval("document.specialpromotion."+month+"[document.specialpromotion." + month + ".selectedIndex].value;");
  	  	
		day = "dd_day" + itemcnt;
		dd_day = eval("document.specialpromotion." + day + "[document.specialpromotion." + day + ".selectedIndex].value;");
    
		year = "dd_year" + itemcnt;
		dd_year = eval("document.specialpromotion." + year + "[document.specialpromotion." + year + ".selectedIndex].value;");
		
		if (eval("document."+frmname+".zip"+itemcnt+".value") == "")
		{
			alert("Please enter a valid zip code.");
			eval("document."+frmname+".zip"+itemcnt+".focus()");
			return;
		}
	}
	else if(oDoc == "multiple_delivery.asp")
	{
		frmname = "nextform";
		state = "state" + itemcnt;
		state = eval("document.nextform."+state+"[document.nextform." + state + ".selectedIndex].value;");
	
		zip = "zip" + itemcnt;
  		zip = eval("document.nextform."+zip+".value");
  	 	
  		month = "dd_month" + itemcnt;
  		dd_month = eval("document.nextform."+month+"[document.nextform." + month + ".selectedIndex].value;");
  	  	
		day = "dd_day" + itemcnt;
		dd_day = eval("document.nextform." + day + "[document.nextform." + day + ".selectedIndex].value;");
    
		year = "dd_year" + itemcnt;
		dd_year = eval("document.nextform." + year + "[document.nextform." + year + ".selectedIndex].value;");

		if (eval("document."+frmname+".zip"+itemcnt+".value") == "")
		{
			alert("Please enter a valid zip code.");
			eval("document."+frmname+".zip"+itemcnt+".focus()");
			return;
	    }
	}
	
    dt = new Date()
    if (dd_month==0) {
        dd_month = dt.getMonth();
        dd_month = dd_month + 1;
    }
    if (dd_year==0) {
        dd_year = dt.getYear();
    }
    if (dd_day==0) {
        dd_day = dt.getDate();
    }    

    //added for continuity
    if (continuity) {
		if (continuity == ''){
			continuity_flag = 'Y'
		}
	 }
   else {
	   continuity_flag = 'N'
   }
   if (delpcode) {
	if (delpcode == ''){
		delpcode = ''
	}
 }
	   
	  //end add for continuity
	if(oDoc == "continuity.asp")
	{
		var  wp = window.open('/deliverywizard_calendar.asp?curr=y&item_no='+ itemcnt+'&dd_day='+dd_day+'&dd_month='+dd_month + '&dd_year=' + dd_year +'&zip='+zip+'&state='+state+'&backf='+oDoc+'&cDate='+cDate+'&perishable='+perishable+'&cc='+company_code+'&pcode='+pcode+'&sku='+sku+'&pdt_type='+pdt_type+'&lfc_flag='+lfc_flag+'&geo_sell_flag='+geo_sell_flag+'&continuity='+continuity_flag+'&delpcode='+delpcode+'&element_idx='+element_idx+'&original_date='+original_date+'&mst_sku='+mst_sku+'&strdetdateval='+strdetdateval+'&mst_month='+mst_month+'&index='+index+'&size='+size+'&comingFrom='+cF+'&continuity_method_code='+continuity_method_code+'&subscription_flag='+subscription_flag,'variant_pop','screenX='+ x1 + ',screenY='+ y1 +',width='+popup_width+',height='+popup_height+',location=no,status=no,scrollbars=no,resizable=no,directories=no,menubar=no,toolbar=no')
	}
	else 
	{
		var  wp = window.open('/deliverywizard_calendar.asp?curr=y&item_no='+ itemcnt+'&dd_day='+dd_day+'&dd_month='+dd_month + '&dd_year=' + dd_year +'&zip='+zip+'&state='+state+'&backf='+oDoc+'&cDate='+cDate+'&perishable='+perishable+'&cc='+company_code+'&pcode='+pcode+'&sku='+sku+'&pdt_type='+pdt_type+'&lfc_flag='+lfc_flag+'&geo_sell_flag='+geo_sell_flag,'variant_pop','screenX='+ x1 + ',screenY='+ y1 +',width='+popup_width+',height='+popup_height+',location=no,status=no,scrollbars=no,resizable=no,directories=no,menubar=no,toolbar=no')
	}
}

function GetSelectedSku()
{
	var i;
	for( i=0; i<document.check.sku.length; ++i) {
		if(document.check.sku[i].checked)
			return document.check.sku[i].value;
	}
	// default (non selected)
	return -1;
}
