//Calender object
var mCal;

//Function for populating listmenu's
function getListValues(language,oList,lstDiv,action,defShippingMethod){

	contentDiv = lstDiv;
	actionTaken = action;
	languageUsed = language;

	var oShipIsBill = document.getElementById('ship_is_bill');
	var blShipIsBill = oShipIsBill.checked;
	var blBillingCountry = true;


	//if(oList.id == "shipping_country"){
	if(oList.id == "billing_country"){


		if(oList.options[oList.selectedIndex].value==""){
			blBillingCountry = false;
		}else{
			//Get selected shippingoption
		/*	if(document.forms['customer_form'].elements['shipping_method']){
				var oShipping = document.forms['customer_form'].elements['shipping_method'];
				var listItemValue = oShipping.options[oShipping.selectedIndex].value;
			}else{
				var listItemValue = defShippingMethod;
			}*/
		listItemValue = oList.options[oList.selectedIndex].value;

		}




	}else{
		//Get other selected listitem
		var listItemValue = oList.options[oList.selectedIndex].value;

		copyShippingFormField(oList);
	}

	var oCountry = document.forms['customer_form'].elements['shipping_country'];
	var curShippingCountry = oCountry.options[oCountry.selectedIndex].value;
	if (curShippingCountry == '') {
		//testen of the billing wel bekend is
		oCountry = document.forms['customer_form'].elements['billing_country'];
		curShippingCountry = oCountry.options[oCountry.selectedIndex].value;
	}

	if(blShipIsBill){
		curBillingCountry = curShippingCountry;
	}else{
		var oCountry = document.forms['customer_form'].elements['billing_country'];
		var curBillingCountry = oCountry.options[oCountry.selectedIndex].value;

		if((oList.id=="shipping_method" || oList.id=="billing_country") && curBillingCountry==""){
			blBillingCountry = false;
		}
	}


	//If country is changed, reset payment options
	if(oList.id == "billing_country"){
		var oPayment = document.forms['customer_form'].elements['payment_method'];
		var boxLength;

		if(oPayment){

			boxLength = oPayment.length;

			if(boxLength > 1){
				for (i = boxLength; i > 0; i--) {
					oPayment.options[i] = null;
				}
			}
		}
	}


	/*if(oList.id == "billing_country" || !blBillingCountry || (oList.id=="shipping_country" && curBillingCountry=="")){
		var oPayment = document.forms['customer_form'].elements['payment_method'];
		var boxLength;

		if(oPayment){

			boxLength = oPayment.length;
			boxLength2 = oPayment.length;

			if(boxLength > 1){
				for (i = boxLength; i > 0; i--) {
					oPayment.options[i] = null;
				}
			}
		}
	}*/



	/*if(blBillingCountry){*/

		xmlHttp=GetXmlHttpObject();

		var url="/modules/sc/modules/customer.php";
		url=url+"?sid="+Math.random();
		url=url+"&action="+action;
		url=url+"&language="+language;
		url=url+"&billing_country="+curBillingCountry;
		url=url+"&shipping_country="+curShippingCountry;
		url=url+"&list_item_value="+listItemValue;

		//alert(url)
		SendRequest(url,"GET");

	/*}*/

}

//Update payment option
function UpdatePaymentOption(cartDiv,language,action,orderstatus,skipOrderOverView,OrderId){


	if(skipOrderOverView){
		//var oPayment = document.forms['customer_form'].elements['payment_method']
		orderId = OrderId;
		skipStep = skipOrderOverView;

	}else{
		paymentMethod = "";
		skipStep = false;
	}

	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	var oPayment = document.forms['payment_options_form'].elements['payment_method'];
	//paymentMethod = oPayment.options[oPayment.selectedIndex].value;
	paymentMethod = get_radio_value(oPayment);

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/customer.php";
	url=url+"?sid="+Math.random();
	url=url+"&action="+action;
	url=url+"&language="+language;
	url=url+"&payment_method="+paymentMethod;

	SendRequest(url,"GET");
}

//Get value from radiobutton field
function get_radio_value(oRadio)
{

	var rad_val;

	for (var i=0; i < oRadio.length; i++)
	{
		if (oRadio[i].checked)
		{
			rad_val = oRadio[i].value;
		}
	}

	return rad_val;
}


//Update customerinfo
function UpdateCustomerInfo(cartDiv,language,action,orderstatus,skipOrderOverView,OrderId){

	actionTaken = action;


	/*if(skipOrderOverView){

	var oPayment = document.forms['customer_form'].elements['payment_method']
	paymentMethod = oPayment.options[oPayment.selectedIndex].value

	orderId = OrderId
	skipStep = skipOrderOverView

	}else{
	paymentMethod = ""
	skipStep = false
	}*/

	contentDiv = cartDiv;
	languageUsed = language;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/customer.php";
	var postData;

	var elementTypes;

	postData="action="+action;
	postData=postData+"&language="+language;
	postData=postData+"&orderstatus="+orderstatus;

	var customerForm = document.forms['customer_form'];
	var element_name,element_value;
	var element_label;


	for(i=0; i<customerForm.elements.length; i++){


		if(customerForm.elements[i].type !== "button" &&
		customerForm.elements[i].type !== "reset" &&
		customerForm.elements[i].type !== undefined &&
		customerForm.elements[i].disabled == false){

			element_name = customerForm.elements[i].name;

			if(customerForm.elements[i].type == "text" || customerForm.elements[i].type == "textarea"){

				element_value = customerForm.elements[i].value;

			}else if(customerForm.elements[i].type == "checkbox"){
				element_value = customerForm.elements[i].checked;

				if(element_name=="ship_is_bill"){
					if(!element_value){
						element_value = 0;
					}else{
						element_value = 1;
					}
				}else{
					if(!element_value){
						element_value = "";
					}
				}

			}
			else if(customerForm.elements[i].type == "radio"){
				if (customerForm.elements[i].checked) {
					element_value = customerForm.elements[i].value;
				} else {
					element_value = '';
				}

			}
			else if(customerForm.elements[i].type == "select-one"){

				element_value = customerForm.elements[i].options[customerForm.elements[i].selectedIndex].value;

			}


			// If ship_is_bill then copy billing to shipping
			copyShippingFormField(customerForm.elements[i]);
			//Reset field background color
			customerForm.elements[i].style.background = "";
			element_value = encodeMyHtml(element_value);

			if ((customerForm.elements[i].type == "radio" && element_value != '') || customerForm.elements[i].type != 'radio') {
				postData=postData+"&"+element_name+"="+element_value;
			}

		}

	}

	//alert(url+postData);

	SendRequest(url,"POST",postData);
}

//Show payment options
function ShowPaymentOptions(cartDiv,language,action){

	//Set bookmark to maintain state on refresh
	setPageBookMark('t=pop');

	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/customer.php";
	url=url+"?sid="+Math.random();
	url=url+"&action="+action;
	url=url+"&language="+language;

	SendRequest(url,"GET");
}

//Show customerform
function ShowCustomerForm(cartDiv,language,action,orderstatus){

	//Set bookmark to maintain state on refresh
	setPageBookMark('t=cuf');

	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/customer.php";
	url=url+"?sid="+Math.random();
	url=url+"&action="+action;
	url=url+"&language="+language;
	url=url+"&orderstatus="+orderstatus;

	//alert(url);


	SendRequest(url,"GET");

	//ping google showcustomerform klantenformulier
	try {
		pageTracker._trackPageview("/bestelproces/klantgegevens.html");
	} catch(err) {

	}
}

//Confirm order
function ConfirmOrder(cartDiv,language,action,OrderId,payment_method){

	//Set bookmark to maintain state on refresh
	setPageBookMark('t=pay%oid='+OrderId+'%pam='+payment_method);

	contentDiv = cartDiv;
	actionTaken = action;
	paymentMethod = payment_method;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/order.php";
	url=url+"?sid="+Math.random();
	url=url+"&action="+action;
	url=url+"&language="+language;
	url=url+"&orderid="+OrderId;
	url=url+"&payment_method="+payment_method;

	//alert(url);


	SendRequest(url,"GET");

	//ping google afterconfirming
	try {
		pageTracker._trackPageview("/bestelproces/definitief_bestellen.html");
	} catch(err) {

	}
}

//Pay order
function PayOrder(cartDiv,language,action,OrderId,payment_method){
	contentDiv = cartDiv;
	actionTaken = action;
	paymentMethod = payment_method;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/order.php";
	url=url+"?sid="+Math.random();
	url=url+"&action="+action;
	url=url+"&language="+language;
	url=url+"&orderid="+OrderId;
	url=url+"&payment_method="+payment_method;

	//alert(url);

	SendRequest(url,"GET");
}


function AddOrder(structuurId, cartDiv,language,action){
	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;
	var quantity;
	var product_type;
	var cur_product_type = "";
	var structuurId;
	var product_article;
	var aProductAccIds;
	var aProductAccDescs;

	var aAccIds = [];
	var aAccDesc = [];

	xmlHttp=GetXmlHttpObject();

	var oQuantity;
	oQuantity = document.getElementById('quantity_'+structuurId);
	//Get article quantity
	if(oQuantity){
		quantity = oQuantity.value;
	}else if(document.getElementById('quantity')){
		oQuantity = document.getElementById('quantity');
		quantity = oQuantity.value;
	}
	else{
		quantity  = 1;
	}

	var oProductType;
	oProductType = document.getElementById('product_type');
	//Get product type if available
	if(oProductType){
		cur_product_type = oProductType.options[oProductType.selectedIndex].value;
	}

	//Check for product accessoires
	var oProductAccIds;
	if (document.forms['product_acc_form'].elements != undefined && document.forms['product_acc_form'].elements['product_acc_ids'] != undefined) {
		oProductAccIds = document.forms['product_acc_form'].elements['product_acc_ids'];
		if(oProductAccIds){
			var aProductAccIds = oProductAccIds;
			var iProductAccId;
			var rbProductAcc;
			var i;
			var j = 0;
			var iLength;

			if(aProductAccIds.length){
				iLength = aProductAccIds.length;
				//var oProductAcc;
				for(i=0; i<iLength; i++){
					iProductAccId = aProductAccIds[i].value;
					rbProductAcc = document.getElementById('product_acc_yes_'+iProductAccId);
					//Only add if checked
					//if(rbProductAcc[1].checked){
					if(rbProductAcc.checked){
						aAccIds[j] = iProductAccId;
						//alert(iProductAddId);
						var oProductAccDesc;
						oProductAccDesc = document.getElementById('product_acc_desc_'+iProductAccId);
						if(oProductAccDesc){
							aAccDesc[j] = oProductAccDesc.value;
						}else{
							aAccDesc[j] = "";
						}
						j++;
					}
				}
			}else{
				iProductAccId = aProductAccIds.value;
				rbProductAcc = document.getElementById('product_acc_yes_'+iProductAccId);
				if(rbProductAcc.checked){
					aAccIds[0] = iProductAccId;
					var oProductAccDesc;
					oProductAccDesc = document.getElementById('product_acc_desc_'+iProductAccId);
					if(oProductAccDesc){
						aAccDesc[0] = oProductAccDesc.value;
					}else{
						aAccDesc[0] = "";
					}
				}
			}
			/*var x;
			for(x=0; x<aAccIds.length; x++){
			alert(aAccIds[x]);
			alert(aAccDesc[x]);
			}*/

		}
	}

	var url="/modules/sc/modules/order.php";
	var postedData;
	/*url=url+"?structuurId="+structuurId
	url=url+"&language="+language
	url=url+"&action="+action
	url=url+"&quantity="+quantity
	url=url+"&sid="+Math.random()
	if(cur_product_type!==""){
	url=url+"&cur_product_type="+cur_product_type
	}
	if(aProductAccIds.length > 0){
	url=url+"&product_acc_ids="+aAccIds
	url=url+"&product_acc_descs="+aAccDesc
	}*/

	postedData="structuurId="+structuurId;
	postedData=postedData+"&language="+language;
	postedData=postedData+"&action="+action;
	postedData=postedData+"&quantity="+quantity;
	postedData=postedData+"&sid="+Math.random();
	if(cur_product_type!==""){
		postedData=postedData+"&cur_product_type="+cur_product_type;
	}
	if(aAccIds.length > 0){
		aAccIds = js_array_to_php_array (aAccIds);
		aAccDesc = js_array_to_php_array (aAccDesc);

		//postedData=postedData+"&product_acc_ids="+aAccIds
		postedData=postedData+"&product_acc_ids="+escape(aAccIds);
		postedData=postedData+"&product_acc_descs="+escape(aAccDesc);
	}

	postedData=postedData+"&cookieEnabled="+ navigator.cookieEnabled; // Added ML

	SendRequest(url,"POST",postedData);


}

function js_array_to_php_array (a)
// This converts a javascript array to a string in PHP serialized format.
// This is useful for passing arrays to PHP. On the PHP side you can
// unserialize this string from a cookie or request variable. For example,
// assuming you used javascript to set a cookie called "php_array"
// to the value of a javascript array then you can restore the cookie
// from PHP like this:
//    <?php
//    session_start();
//    $my_array = unserialize(urldecode(stripslashes($_COOKIE['php_array'])));
//    print_r ($my_array);
//    ?>
// This automatically converts both keys and values to strings.
// The return string is not URL escaped, so you must call the
// Javascript "escape()" function before you pass this string to PHP.
{
	var a_php = "";
	var total = 0;
	for (var key=0; key<a.length; key++)
	{
		++ total;
		a_php = a_php + "s:" +
		String(key).length + ":\"" + String(key) + "\";s:" +
		String(a[key]).length + ":\"" + String(a[key]) + "\";";
	}
	/*for (var key in a)
	{
	++ total;
	a_php = a_php + "s:" +
	String(key).length + ":\"" + String(key) + "\";s:" +
	String(a[key]).length + ":\"" + String(a[key]) + "\";";
	}*/
	a_php = "a:" + total + ":{" + a_php + "}";
	return a_php;
}



//Edit existing order
function EditOrder(orderid,articleId,cartDiv,language,action){

	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	var url="/modules/sc/modules/order.php";
	url=url+"?articleid="+articleId;
	url=url+"&orderid="+orderid;
	url=url+"&language="+language;
	url=url+"&action="+action;
	url=url+"&sid="+Math.random();

	//Quantity change
	if(action=="edit"){

		var quantityField = document.getElementById('quantity'+articleId);
		url=url+"&new_quantity="+quantityField.value;


	}
	xmlHttp=GetXmlHttpObject();
	SendRequest(url,"GET");



}
//Delete product accessoires
function deleteProductAccessoire(productAccId,cartDiv,language,action){

	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	var url="/modules/sc/modules/order.php";
	url=url+"?product_acc_id="+productAccId;
	url=url+"&language="+language;
	url=url+"&action="+action;
	url=url+"&sid="+Math.random();

	xmlHttp=GetXmlHttpObject();

	SendRequest(url,"GET");

}

//View message after adding product
function viewMessageAfterAdd(cartDiv,language,action){


	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/order.php";
	url=url+"?language="+language;
	url=url+"&action="+action;
	url=url+"&sid="+Math.random();

	SendRequest(url,"GET");

}

//View shoppingcart
function viewCart(cartDiv,language,action){


	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/order.php";
	url=url+"?language="+language;
	url=url+"&action="+action;
	url=url+"&sid="+Math.random();

	SendRequest(url,"GET");

}

//Check for existing orders
function CheckOrder(cartDiv,language,action){


	contentDiv = cartDiv;
	actionTaken = action;
	languageUsed = language;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/order.php";
	url=url+"?language="+language;
	url=url+"&action="+action;
	url=url+"&sid="+Math.random();

	//document.write(url)

	SendRequest(url,"GET");

}

//Show orderoverview
function ShowOrderOverview(cartDiv,language,action){

	//Set bookmark to maintain state on refresh

	if(action=="showorderoverview"){
		setPageBookMark('t=oov');
		var step = "/bestelproces/ordergegevens.html";
	}else{
		setPageBookMark('t=sco');
		var step = "/bestelproces/winkelwagen_overzicht.html";
	}

	contentDiv = cartDiv;
	actionTaken = action;

	xmlHttp=GetXmlHttpObject();

	var url="/modules/sc/modules/order.php";
	url=url+"?sid="+Math.random();
	url=url+"&action="+action;
	url=url+"&language="+language;

	SendRequest(url,"GET");

	$.modal.close();

	//ping google showorderoverview winkelwagenoverzicht
	try {
		pageTracker._trackPageview(step);
	} catch(err) {

	}

}

function setPageBookMark(bookmark){
	var tmpLocation = window.location.href;
	var lastIndex = tmpLocation.lastIndexOf('#');

	if(lastIndex>-1){
		tmpLocation = tmpLocation.substring(0,lastIndex);
	}

	window.location.href = tmpLocation+'#['+bookmark+']';
}

function getPageBookMark(){
	var tmpLocation = window.location.href;
	var lastIndex = tmpLocation.lastIndexOf('#');

	if(lastIndex>-1){
		var lastIndex1 = tmpLocation.lastIndexOf('[');
		var lastIndex2 = tmpLocation.lastIndexOf(']');
		var strBookMark = tmpLocation.substring(lastIndex1+1,lastIndex2);

		return strBookMark;
	}

	return "";
}

//Function for showing the shoppingcart
function showSC(oElement,cartDiv,language){

	var position = findPosition(oElement);
	var cartContent = document.getElementById(cartDiv);

	cartContent.style.top = position[1];
	cartContent.style.left = position[0]-145;

	cartContent.style.visibility = 'visible';


}

//Function for hiding the shoppingcart
function hideSC(cartDiv){
	cartDiv.style.visibility = 'hidden';
}


//Function for showing/hiding the shoppingcart button
function showScButton(buttonId,visibility){
	var scButton = document.getElementById(buttonId);

	scButton.style.visibility = visibility;
}

//function for hiding or showing content
function hideShowDiv(elementName,visibility){
	//var element = document.getElementById(elementName);
	//element.style.visibility = visibility;
	if (visibility = 'hidden') {
		$.modal.close();
	}

}

//function for hiding or showing content
function hideShowDivOverlay(elementName){
	var element = document.getElementById(elementName);

			$.modal($(element),{
				persist: true,
    			minHeight:17,
				containerCss:{backgroundColor:"#fff",height:120,padding:0,width:322},

				onOpen: function(dialog)
				{
					dialog.overlay.fadeIn('fast', function () {
						dialog.container.slideDown('normal', function () {
							dialog.data.fadeIn('normal');

							element.style.visibility = 'visible';


						});
					});
				},
				onClose: function(dialog)
				{
					dialog.overlay.fadeOut('fast', function () {
						dialog.container.fadeOut('fast', function () {
							dialog.data.fadeOut('fast', function () {

								$.modal.close(); // must call this!
								$("#actionAfterAdd").remove(); // and this too!

								});
							});
						});

				}

			});
}






//Function for determining position of the shoppingcart
function findElementPosition( oElement ) {
	if( typeof( oElement.offsetParent ) != 'undefined' ) {
		for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
		return [ posX, posY ];
	} else {
		return [ oElement.x, oElement.y ];
	}
}

function mouseLeaves (element, evt) {
	if (typeof evt.toElement != 'undefined' && evt.toElement && typeof
	element.contains != 'undefined') {
		return !element.contains(evt.toElement);
	}
	else if (typeof evt.relatedTarget != 'undefined' && evt.relatedTarget) {
		return !contains(element, evt.relatedTarget);
	}
}

function contains (container, containee) {
	while (containee) {
		if (container == containee) {
			return true;
		}
		containee = containee.parentNode;
	}
	return false;
}

function IsInteger(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;

}

function IsEmpty(aTextField) {
	if ((aTextField.value.length==0) ||
	(aTextField.value==null)) {
		return true;
	}
	else { return false; }
}

//function for encoding formvalues
function encodeMyHtml(strToEncode) {
	strToEncode = escape(strToEncode);
	strToEncode = strToEncode.replace(/\//g,"%2F");
	strToEncode = strToEncode.replace(/\?/g,"%3F");
	strToEncode = strToEncode.replace(/=/g,"%3D");
	strToEncode = strToEncode.replace(/&/g,"%26");
	strToEncode = strToEncode.replace(/@/g,"%40");

	return strToEncode;
}

function showHideControl(controlId,displayType,disabledState){
	oControl = document.getElementById(controlId);

	if(oControl){
		oControl.style.display = displayType;

		//Disable childcontrols?
		if(disabledState=="disabled"){
			disableEnableControlsByTagName(oControl,"input",true);
			disableEnableControlsByTagName(oControl,"textarea",true);
			disableEnableControlsByTagName(oControl,"select",true);
		}else if(disabledState=="enabled"){
			disableEnableControlsByTagName(oControl,"input",false);
			disableEnableControlsByTagName(oControl,"textarea",false);
			disableEnableControlsByTagName(oControl,"select",false);
		}
	}
}

function disableEnableControlsByTagName(oParentControl,tagName,state){
	var oChildren = oParentControl.getElementsByTagName(tagName);

	var i=0;
	var oNode;

	while((oNode=oChildren.item(i++))){
		/*  loop body working with oNode  */
		oNode.disabled = state;

	}
}

function copyShippingFormField(oFormField){
	var oShipIsBill = document.getElementById('ship_is_bill');
	if (oShipIsBill != undefined) {
		var blShipIsBill = oShipIsBill.checked;

		if(blShipIsBill){
			switch(oFormField.id){
				case "billing_address":
				var oShippingAddress = document.getElementById('shipping_address');
				oShippingAddress.value = oFormField.value;
				break;
				case "billing_postalcode":
				var oShippingPostalcode = document.getElementById('shipping_postalcode');
				oShippingPostalcode.value = oFormField.value;
				break;
				case "billing_place":
				var oShippingPlace = document.getElementById('shipping_place');
				oShippingPlace.value = oFormField.value;
				break;
				case "billing_country":
				var oShippingCountry = document.getElementById('shipping_country');
				oShippingCountry.selectedIndex = oFormField.selectedIndex;

				var sCountry = oShippingCountry.options[oShippingCountry.selectedIndex].value;
				if(sCountry=="nederland" || sCountry==""){
					showHideControl('vat_nr_row','none','disabled');
				}else{
					showHideControl('vat_nr_row','block','enabled');
				}
				break;
			}
		}
	}
}

//enable or disable billing form fields
function setBillingFormFields(oCheckStatus){

	var oShippingAddressDetails = document.getElementById('shipping_address_details');

	var oBillingAddress = document.getElementById('billing_address');
	var oBillingPostalcode = document.getElementById('billing_postalcode');
	var oBillingPlace = document.getElementById('billing_place');
	var oBillingCountry = document.getElementById('billing_country');

	var oShippingAddress = document.getElementById('shipping_address');
	var oShippingPostalcode = document.getElementById('shipping_postalcode');
	var oShippingPlace = document.getElementById('shipping_place');
	var oShippingCountry = document.getElementById('shipping_country');


	if(oCheckStatus.checked){

		oShippingAddressDetails.style.display = 'none';

		oShippingAddress.value = oBillingAddress.value;
		oShippingPostalcode.value = oBillingPostalcode.value;
		oShippingPlace.value = oBillingPlace.value;
		oShippingCountry.selectedIndex = oBillingCountry.selectedIndex;


		oShippingAddress.disabled = false;
		oShippingPostalcode.disabled = false;
		oShippingPlace.disabled = false;
		oShippingCountry.disabled = false;
	}else{

		oShippingAddressDetails.style.display = 'block';

		oShippingAddress.disabled = false;
		oShippingPostalcode.disabled = false;
		oShippingPlace.disabled = false;
		oShippingCountry.disabled = false;

	}
}

function showCal(inputField){
	//mCal = new dhtmlxCalendarObject("dhtmlxCalendar", false, {isYearEditable: true});
	//mCal.setYearsRange(2000, 2500);
	//mCal.setOnClickHandler(mSelectDate);
	//mCal.draw();

	oCal = document.getElementById(inputField);
	mCal = new dhtmlxCalendarObject(oCal);
	mCal.show();
}

function hideCal(){
	//mCal = new dhtmlxCalendarObject("dhtmlxCalendar", false, {isYearEditable: true});
	//mCal.setYearsRange(2000, 2500);
	//mCal.setOnClickHandler(mSelectDate);
	//mCal.draw();

	mCal.hide();
}

function showInfo(infoDiv,sender,action,structuurId,language){

	var url="/modules/sc/modules/order.php";
	url=url+"?language="+language;
	url=url+"&action="+action;
	url=url+"&structuurid="+structuurId;
	url=url+"&sid="+Math.random();

	showInfoBox(infoDiv, url);

}

function showInfoBox(elementName, url){
	var element = document.getElementById(elementName);

		$(element).load(url);

			$.modal($(element),{

    			minHeight:17,
				containerCss:{backgroundColor:"#fff",height:120,padding:0,width:322},

				onOpen: function(dialog)
				{
					dialog.overlay.fadeIn('fast', function () {
						dialog.container.slideDown('normal', function () {
							dialog.data.fadeIn('normal');

							element.style.visibility = 'visible';


						});
					});
				},
				onClose: function(dialog)
				{
					dialog.overlay.fadeOut('fast', function () {
						dialog.container.fadeOut('fast', function () {
							dialog.data.fadeOut('fast', function () {

								$.modal.close(); // must call this!

								});
							});
						});

				}

			});
}





function getVar( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) {
		return "";
	} else {
		return results[1];
	}
}


//Toont de loginstatus van de klant
function showLoginStatus(vlag,script,thisDiv){
	//xmlHttp_customer=GetXmlHttpObject_customer();

	languageUsed = vlag;

	contentDiv = thisDiv;
	actionTaken = 'loginStatus';

	xmlHttp=GetXmlHttpObject();


	var url="/modules/klanten/"+script;
	url=url+"?sid="+Math.random();
	url=url+"&vlag="+vlag;
	var fout = getVar('fout');
	if (fout != '') {
		url=url+"&fout="+fout;
	}

	//alert(url);
	//SendRequest_customer(url,"GET");
	SendRequest(url,"GET");

}
// JavaScript Document
