var xmlHttp
var recordID

function add_myrecord(firstname,lastname,action)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	
	var firstname = encodeURIComponent(firstname);
	var lastname = encodeURIComponent(lastname);
	
	var url="ajax_data_actions.asp"
	url=url+"?firstname="+firstname
	url=url+"&lastname="+lastname
	url=url+"&action="+action
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=Debug
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


function LoadAreas(cntid, provinceid, countryid, areaid)
{	

	$("#areaDiv").html("<div id=loaddiv ><img src=../images/ajax-loader.gif></div>");
	
	var cntid = encodeURIComponent(cntid);
	var provinceid = encodeURIComponent(provinceid);
	var countryid = encodeURIComponent(countryid);
	var areaid = encodeURIComponent(areaid);
	
	var url="packets_ajax.asp?cntID="+cntid
	url=url+"&provinceid="+provinceid
	url=url+"&countryid="+countryid
	url=url+"&areaid="+areaid
	url=url+"&sid="+Math.random()
	
	$("#areaDiv").load( url );
}

function changeArea(selObj,cnt){
	var countryID;
	var provinceID;
	var areaID;
	var id= selObj.value;

	
	countryID = document.form1.country_id.value
	provinceID = document.form1.province_id.value
	areaID = document.form1.area_id.value
	//optionid = document.form1.optionid.value

	if (selObj.name == "country_id"){
		provinceID = 0
		areaID = 0
	}
	
	if (selObj.name == "province_id"){
		areaID = 0
	}        
	document.getElementById('areaID').value = areaID;
	LoadAreas(cnt,provinceID,countryID,areaID);
	
	//elegxos gia to an prepei na alaksoun ta metaforika.
	if (document.getElementById("prd_ShippingTime") == undefined)
		{
		ShippingTime = "";
		}
	else
		{
		ShippingTime = document.getElementById("prd_ShippingTime").value;
		}
	
	if (ShippingTime != '' && areaID !=0)
		{
			//alert("Αλλάξατε την περιοχή αποστολής. Τα έξοδα αποστολής θα υπολογιστούν ξανά.");
			//window.setTimeout('LoadSpecial('+fnetID+')',1000);
			selectedDate = document.getElementById("prd_shippingDate").value;
			timezone = ShippingTime
			theareaID = areaID
			cntID = cnt
			window.setTimeout('LoadShipCost('+selectedDate+', '+timezone+', '+theareaID+', '+cntID+')',1000);
		}
	
	
}


function LoadDate(selectedDate,cntID,action)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	
	var cntID = encodeURIComponent(cntID);
	var provinceid = encodeURIComponent(provinceid);
	var countryid = encodeURIComponent(countryid);
	var areaid = encodeURIComponent(areaid);
	var action = encodeURIComponent(action);

	var url="dates_ajax.asp?selectedDate="+selectedDate
	url=url+"&cntID="+cntID
	url=url+"&action="+action
	url=url+"&sid="+Math.random()
	
	xmlHttp.onreadystatechange = DisplaydatetimeDiv;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function LoadShipCost(selectedDate, timezone, theareaID, cntID)
{
	$("#ShipCostDiv").html("<div id=loaddiv ><img src=../images/ajax-loader.gif></div>");
	
	var selectedDate = encodeURIComponent(selectedDate);
	var timezone = encodeURIComponent(timezone);
	var theareaID = encodeURIComponent(theareaID);	
	var cntID = encodeURIComponent(cntID);
	
	var url="ship_ajax.asp?selectedDate="+selectedDate
	url=url+"&timezone="+timezone
	url=url+"&theareaID="+theareaID
	url=url+"&cntID="+cntID
	url=url+"&sid="+Math.random()
	
	$("#ShipCostDiv").load( url , function(){
		if (document.getElementById("winid") == undefined)
		{
			fnetID = document.getElementById('cnt_fnetID').value;
			selected_cntid = document.getElementById('selected_cntid').value;
			window.setTimeout('LoadSpecial('+fnetID+', '+selected_cntid+')',1000);
		} else {
			if (document.getElementById("winid").value != document.getElementById("cnt_fnetID").value || document.getElementById("cnt_fnetID").value == '')
			{
				fnetID = document.getElementById('cnt_fnetID').value;
				selected_cntid = document.getElementById('selected_cntid').value;
				window.setTimeout('LoadSpecial('+fnetID+', '+selected_cntid+')',1000);
			}						
		}
	});
	
}

function sendShipData(cntID){
	timezone = getCheckedValue(document.timezonesform.timezone);
	selectedDate = document.getElementById('prd_shippingDate').getAttribute('value');
	theareaID = document.getElementById('areaID').getAttribute('value');
	LoadShipCost(selectedDate, timezone, theareaID, cntID)
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function LoadSpecial(fnetID,selected_cntid)
{
	$("#specialDiv").html("<div id=loaddiv ><img src=../images/ajax-loader.gif></div>");
	
	var fnetID = encodeURIComponent(fnetID);
	var selected_cntid = encodeURIComponent(selected_cntid);
	
	var url="special_ajax.asp?fnetID="+fnetID
	url=url+"&selected_cntid="+selected_cntid
	url=url+"&sid="+Math.random()

	$("#specialDiv").load( url );
}

function SaveCartVik(selected_cntid,product_option,areaID,prd_shippingDate,prd_ShippingTime,prd_ShippingPrice,cnt_fnetID,specialStr)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	
	var selected_cntid = encodeURIComponent(selected_cntid);
	var product_option = encodeURIComponent(product_option);
	var areaID = encodeURIComponent(areaID);
	var prd_shippingDate = encodeURIComponent(prd_shippingDate);
	var prd_ShippingTime = encodeURIComponent(prd_ShippingTime);
	var prd_ShippingPrice = encodeURIComponent(prd_ShippingPrice);
	var cnt_fnetID = encodeURIComponent(cnt_fnetID);
	var specialStr = encodeURIComponent(specialStr);
	
	var url="addcart_ajaxVik.asp?areaID="+areaID
	url=url+"&selected_cntid="+selected_cntid
	url=url+"&product_option="+product_option
	url=url+"&prd_shippingDate="+prd_shippingDate
	url=url+"&prd_ShippingTime="+prd_ShippingTime
	url=url+"&prd_ShippingPrice="+prd_ShippingPrice
	url=url+"&cnt_fnetID="+cnt_fnetID
	url=url+"&specialStr="+specialStr
	url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange = DisplaySaveDiv;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function SaveCart(selected_cntid,product_option,areaID,prd_shippingDate,prd_ShippingTime,prd_ShippingPrice,cnt_fnetID,specialStr)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	
	var selected_cntid = encodeURIComponent(selected_cntid);
	var product_option = encodeURIComponent(product_option);
	var areaID = encodeURIComponent(areaID);
	var prd_shippingDate = encodeURIComponent(prd_shippingDate);
	var prd_ShippingTime = encodeURIComponent(prd_ShippingTime);
	var prd_ShippingPrice = encodeURIComponent(prd_ShippingPrice);
	var cnt_fnetID = encodeURIComponent(cnt_fnetID);
	var specialStr = encodeURIComponent(specialStr);
	
	var url="addcart_ajax.asp?areaID="+areaID
	url=url+"&selected_cntid="+selected_cntid
	url=url+"&product_option="+product_option
	url=url+"&prd_shippingDate="+prd_shippingDate
	url=url+"&prd_ShippingTime="+prd_ShippingTime
	url=url+"&prd_ShippingPrice="+prd_ShippingPrice
	url=url+"&cnt_fnetID="+cnt_fnetID
	url=url+"&specialStr="+specialStr
	url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange = DisplaySaveDiv;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function displayAreas(cID)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }

	var url="ajax_data_actions.asp?action=displayContact"
	url=url+"&cID="+cID
	url=url+"&sid="+Math.random()
	//display contact DIV
	xmlHttp.onreadystatechange=Debug
	newform.selectedContact.value = cID;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

	function Debug()
	{

		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 {
			document.getElementById('debug').innerHTML=xmlHttp.responseText

		 }
	}

	function DisplayareaDiv()
	{
		var loaddiv = "<div id=loaddiv ><img src=../images/ajax-loader.gif></div>";
		var loaddivend = "<div id=loaddiv ></div>";
		
		if (xmlHttp.readyState == 1) {
			document.getElementById('areaDiv').innerHTML = loaddiv;
		}		
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 {
			document.getElementById('areaDiv').innerHTML = loaddivend;
			document.getElementById('areaDiv').innerHTML='';
			document.getElementById('areaDiv').innerHTML=xmlHttp.responseText
			
		 }
	}

	function DisplaydatetimeDiv()
	{
		var loaddiv = "<div id=loaddiv ><img src=../images/ajax-loader.gif></div>";
		var loaddivend = "<div id=loaddiv ></div>";
		
		if (xmlHttp.readyState == 1) {
			document.getElementById('datetimeDiv').innerHTML = loaddiv;
		}			
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 {
			document.getElementById('datetimeDiv').innerHTML = loaddivend;
			document.getElementById('datetimeDiv').innerHTML='';
			document.getElementById('datetimeDiv').innerHTML=xmlHttp.responseText
			
			selectedDate = 0;
			timezone = 9;
			theareaID = document.getElementById("areaID").value;
			cntID = document.getElementById("selected_cntid").value;
			window.setTimeout('LoadShipCost('+selectedDate+', '+timezone+', '+theareaID+', '+cntID+')',1000);
		 }
	}

	function DisplayShipCostDiv()
	{
		var loaddiv = "<div id=loaddiv ><img src=../images/ajax-loader.gif></div>";
		var loaddivend = "<div id=loaddiv ></div>";
		
		if (xmlHttp.readyState == 1) {
			document.getElementById('ShipCostDiv').innerHTML = loaddiv;
		}	
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 {
			document.getElementById('ShipCostDiv').innerHTML = loaddivend;
			document.getElementById('ShipCostDiv').innerHTML='';
			document.getElementById('ShipCostDiv').innerHTML=xmlHttp.responseText

			//elegxos gia to an prepei na fortosei to DIV me ta synodeutika.
			if (document.getElementById("winid") == undefined)
				{
				fnetID = document.getElementById('cnt_fnetID').value;
				selected_cntid = document.getElementById('selected_cntid').value;
				window.setTimeout('LoadSpecial('+fnetID+', '+selected_cntid+')',1000);
				}
			else
				{
				if (document.getElementById("winid").value != document.getElementById("cnt_fnetID").value || document.getElementById("cnt_fnetID").value == '')
					{
					fnetID = document.getElementById('cnt_fnetID').value;
					selected_cntid = document.getElementById('selected_cntid').value;
					window.setTimeout('LoadSpecial('+fnetID+', '+selected_cntid+')',1000);
					}						
				}
			
		

		 }
	}

	function DisplayspecialDiv()
	{
		var loaddiv = "<div id=loaddiv ><img src=../images/ajax-loader.gif></div>";
		var loaddivend = "<div id=loaddiv ></div>";
		
		if (xmlHttp.readyState == 1) {
			document.getElementById('specialDiv').innerHTML = loaddiv;
		}	
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 {
			document.getElementById('specialDiv').innerHTML = loaddivend;
			document.getElementById('specialDiv').innerHTML='';
			document.getElementById('specialDiv').innerHTML=xmlHttp.responseText

		 }
	}
	
	function DisplaySaveDiv()
	{
		var loaddiv = "<div id=loaddiv ><img src=../images/ajax-loader.gif></div>";
		var loaddivend = "<div id=loaddiv ></div>";
		
		if (xmlHttp.readyState == 1) {
			document.getElementById('SaveDiv').innerHTML = loaddiv;
		}	
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 {
			document.getElementById('SaveDiv').innerHTML = loaddivend;
			document.getElementById('SaveDiv').innerHTML='';
			document.getElementById('SaveDiv').innerHTML=xmlHttp.responseText

		 }
	}


function GetXmlHttpObject()
{
	var xmlHttp=null;
try
 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


