	function OpenBrowserWindow(theURL, winName, features, myWidth, myHeight, isCenter) 
	{ //v3.0
	  if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	  }
	  var d=window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	}
	
	function ShowGeneralCalendar(ctrl_name)
	{
		//alert("e");
		OpenBrowserWindow("calendar.asp?ctrlName="+ctrl_name, 'calendar', 'scrollbars=no,resizeable=yes', 180, 172, "true");
		return false;
	}
	
	function showCalendar(calStr)
	{
		//alert("10");
		var selUpgradeOptions = SelectedUpgradeOptions();
		OpenBrowserWindow("productcalendar.asp?" + calStr + "&sel=" + selUpgradeOptions, 'productcalendar', 'scrollbars=no,resizeable=yes', 190, 220, "true");
		//window.open("productcalendar.asp?" + calStr, "productcalendar", "height=340,width=430, scrollbars=no,resizeable=yes");
		return false;
	}

	function showLocationMap()
	{
		//alert("1");
		OpenBrowserWindow("images/location_map.jpg", 'location_map', 'scrollbars=no,resizeable=yes', 400, 600, "true"); 
		return false;
	}

	function Agent_showLocationMap()
	{
		//alert("1");
		OpenBrowserWindow("../images/location_map.jpg", 'location_map', 'scrollbars=no,resizeable=yes', 400, 600, "true"); 
		return false;
	}
	
	function Agent_showCalendar(calStr)
	{
		//alert("10");
		//var selUpgradeOptions = SelectedUpgradeOptions();
		OpenBrowserWindow("../productcalendar.asp?" + calStr, 'productcalendar', 'scrollbars=no,resizeable=yes', 190, 220, "true");
		//window.open("productcalendar.asp?" + calStr, "productcalendar", "height=340,width=430, scrollbars=no,resizeable=yes");
		return false;
	}
	
	function UpgradeOptionDetail(id)
	{
		//alert("11");
		OpenBrowserWindow("upgradedetail.asp?page=true&id=" + id, 'upgradedetail', 'scrollbars=yes,resizeable=yes', 400, 350, "true"); 
		return false;		
	}
	
	function PrintOrder(id,gp)
	{
		OpenBrowserWindow("/printorder.asp?id=" + id+"&gp=" + gp, 'printorder', 'scrollbars=yes,resizeable=yes', 530, 400, "true"); 
		return false;		
	}
	
	function PrintSupplierOrder(id)
	{
		OpenBrowserWindow("/printorder.asp?id=" + id + "&sp=true", 'printorder', 'scrollbars=yes,resizeable=yes', 530, 400, "true"); 
		return false;		
	}
	
	function UpgradeOptionSelect(id,win)
	{
		//alert(id + " " + win);
		var ctrl = win.document.getElementById('chk_xsale_' + id);
		var optSelected = win.document.getElementById('xsale_' + id + "_ok");
		if (ctrl!=null)
		{
			optSelected.value = "1";
			ctrl.checked = true;			
		}
	}
	
	function SelectedUpgradeOptions()
	{
		var ctrl = document.getElementsByName("chk_xsale");
		var limit = ctrl.length;
		var i;
		var sel = "";
		for (i=0;i<limit;i++)
		{
			if (ctrl[i].checked==true)
			{
				sel = sel + "," + ctrl[i].value;
			}
		}
		if (sel!="")
			return sel.substring(1);
		else
			return "0";
	}
	
	function isBlank(value)
	{
		var res = true;		
		var l = value.length;		
		for(var i = 0; i < l; i++)
		{
			if (value.charAt(i) != " ")
			{
				res = false;
				break;
			}
		}
		
		return res;
	}
	
	function isNumeric(value, allowZeroStart)
	{
		
		if (allowZeroStart)
		{
			return (/^[0-9]+$/.test(value));
		}
		else
		{
			return (/^[1-9]+[0-9]*$/.test(value));
		}			
	}	
	
	function isNumericWithSpace(value)
	{
		
		return (/^[0-9 ]+$/.test(value));
	}		
	
	function isAlphabets(value, allowspace)
	{
		if (allowspace==true)
			return (/^[A-Za-z ]+$/.test(value));
		else
			return (/^[A-Za-z]+$/.test(value));
	}
	
	function isValidEmail(value)
	{
		return(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value));
	}
	
	function isDate(dateStr) {

	//alert(dateStr);
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	//alert(matchArray);
	if (matchArray == null) {
	//alert("Please enter date as either dd/mm/yy or dd-mm-yy.");
	return false;
	}

	month = matchArray[1]; // p@rse date into variables
	day = matchArray[3];
	year = matchArray[5];

	//alert(day + "/" + month + "/" + year);
	
	if (month < 1 || month > 12) { // check month range
	//alert("Month must be between 1 and 12.");
	return false;
	}

	if (day < 1 || day > 31) {
	//alert("Day must be between 1 and 31.");
	return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	//alert("Month "+month+" doesn`t have 31 days!")
	return false;
	}

	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)) {
	//alert("February " + year + " doesn`t have " + day + " days!");
	return false;
	}
	}
	return true; // date is valid
	}
	
	function CheckUpgradeOptions(id)
	{
		//alert(id);
		if (id=="0007" || id=="0003" || id=="0002" || id=="0001")
		{
			if (id=="0007" && isChecked("0007"))
			{
				removeChecked("0003");
				removeChecked("0002");
				removeChecked("0001");				
			}
			else if(id=="0003" && isChecked("0003"))
			{
				if (isChecked("0007"))
				{
					removeChecked("0003");
					alert("Can't select this package. You have already selected a package which includes this package.")
				}
				removeChecked("0002");
				removeChecked("0001");				
			}
			else if(id=="0002" || id=="0001" || isChecked("0002") || isChecked("0001"))
			{
				if (isChecked("0007"))
				{
					removeChecked("0003");
					removeChecked("0002");
					removeChecked("0001");
					alert("Can't select this package. You have already selected a package which includes this package.")
				}
				else if (isChecked("0003"))
				{
					removeChecked("0002");
					removeChecked("0001");
					alert("Can't select this package. You have already selected a package which includes this package.")
				}								
			}			
		}
		
		var optSelected = document.getElementById("xsale_" + id + "_ok");
		if (parseInt(optSelected.value,10)<=0 && isChecked(id))
		{
			alert("You can not select this option unless you select the detail for this.\nPlease click the image to see the details for this option.");
			removeChecked(id);
		}
	}
	
	function removeChecked(id)
	{
		/*var chks = document.getElementsByName("chk_xsale");		
		var l =chks.length;		
		var i;
		for (i=0;i<l;i++)
		{
			if (chks[i].value==id)
			{
				chks[i].checked = false;
				break;
			}
		}
		return;
*/
		var chkctrl = document.getElementById("chk_xsale_" + id);		
		if (chkctrl!=null)
		{
			chkctrl.checked = false;
		}
		return;
	}
	
	function isChecked(id)
	{
		/*var chks = document.getElementsByName("chk_xsale");		
		var l =chks.length;		
		var i;
		for (i=0;i<l;i++)
		{
			if (chks[i].value==id)
			{
				return chks[i].checked;
			}
		}
		return false;*/
		
		var chkctrl = document.getElementById("chk_xsale_" + id);		
		if (chkctrl!=null)
		{
			return chkctrl.checked;
		}
		return false;

	}
	
	function SendOrderEmail(id)
	{
		OpenBrowserWindow("/test_cruise/sendordermail.asp?id=" + id, "sendorder", "", 300, 100, true);
	}
	
	function ChangeCurrency()
	{
		OpenBrowserWindow("ChangeCurrency.asp", "ChangeCurrency", "scrollbars=yes", 300, 350, true);
		return false;
	}
	
	function isAmount(value)
	{
		return (/^[0-9]+\.*[0-9]{0,2}$/.test(value));
	}
	
	
	function ShowDepartureDetail(id)
	{
		/*var dLength = Departures.length;
		
		for (var i = 0; i < dLength; i++)
		{
			if (Departures[i][0] == id)
			{
				var detail = Departures[i][1];
				if (detail[0] != "")
				{
					document.getElementById("DeptLocation").innerHTML = detail[0] + "&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' onClick='javascript: return showLocationMap();'>View Map</a>";
				}			
				
				document.getElementById("DeptBoarding").innerHTML = detail[1];
				document.getElementById("DeptReturn").innerHTML = detail[2];
				document.getElementById("caDetailID").value = id;
			}
		}*/
		if (id.indexOf("default-")>=0)
		{
			//alert("1");
			document.getElementById("isDefaultDeparture").value = "1";
			id = id.replace("default-", "");
			document.getElementById("DefaultDepartureID").value = id;
			document.getElementById("caDetailID").value = "0";
		}
		else
		{
			document.getElementById("isDefaultDeparture").value = "0";
			document.getElementById("DefaultDepartureID").value = "0";
			document.getElementById("caDetailID").value = id;
		}
		//document.getElementById("detailID").value = id;
		//document.forms['departureForm'].submit();
						
	}