/*
#########################################################
#
# default javascript functions for the webshop
#
# Copyright:		2000-2011 S-Inside
# Project:			Any website
# Platform:			Javascript
#
#########################################################
*/


// 15-05-11 - to sort simple productlist
function switchProductSort ($p_sSort) {
	var $sLocation = window.location.href;
	var $sNewSort = "sort="+$p_sSort;
	var $sOldSort = "sort="+getValueOfParameterURL("sort");
	$sLocation = $sLocation.replace($sOldSort, $sNewSort);
	//alert($sLocation);
	self.location.href = $sLocation;
}

// 24-05-11 - submit form by pushing order img or button
function orderProduct ($p_nProductID) {
	$bOrder = true;
	
	if (document.getElementById('planprice_'+$p_nProductID+'_1')) {
		// plannerprice is given, check if plannerprice is checked
		var $sPriceNoPlanning = document.getElementById('planprice_'+$p_nProductID+'_1');
		var $sPricePlanning = document.getElementById('planprice_'+$p_nProductID+'_0');
		if (($sPricePlanning) && ($sPriceNoPlanning) && ($sPriceNoPlanning.checked == false) && ($sPricePlanning.checked == false)) {
			// no price is checked, give message
			alert("Kies aub een van beide opties, met of zonder montage!");
			$bOrder = false;
		}
	}
	if ($bOrder) {
		document.forms["form_"+$p_nProductID].submit()
		
	}
}

// to check if one price with planning is checked
function priceChecked ($p_nProductID, $p_nPlanning) {
	var $sPriceNoPlanning = document.getElementById('planprice_'+$p_nProductID+'_1');
	var $sPricePlanning = document.getElementById('planprice_'+$p_nProductID+'_0');
	if (($sPricePlanning) && ($sPriceNoPlanning)) {
		if ($p_nPlanning == 1) {
			$sPricePlanning.checked = false;
		} else {
			$sPriceNoPlanning.checked = false;
		}
	}
}

// show or hide prices in webshop
function switchPrices () {
	var $aDivs = document.getElementsByTagName("div");
	var $nHidden = document.forms["hidePrices"].hiddenPrices.value;
	$nHidden++;
	if ($nHidden > 1) {
		$nHidden = 0;
	}
	document.forms["hidePrices"].hiddenPrices.value = $nHidden;
	
	for (var $nCount = 0; $nCount < $aDivs.length; $nCount++) {
		var $sDiv = $aDivs[$nCount];
		
		if ($sDiv.className == 'price_visible') {
			$sDiv.className = 'price_hidden';
		} else if ($sDiv.className == 'price_hidden') {
			$sDiv.className = 'price_visible';
		}
	}
	
	// set PHP session
	$sURL = 'ajax.php?sAction=switchPrices&id='+$nHidden;
	// alert($sURL);
	http.open('post', $sURL);
    http.onreadystatechange = handleResponse;
    http.send(null);
}


/*

function deleteProduct($p_nProductID) {
	$bConfirmed = confirm("Product echt verwijderen? Dit kan niet ongedaan gemaakt worden!");
	
	if ($bConfirmed) {
		location.href = "admin.php?type=dropproduct&productid="+$p_nProductID;
	}
	
}
function loadProduct() {
	//document.allproducts.submit();
	//document.forms['allproducts'].submit();
}


function setCustomFieldBasket ($p_nID, $p_sValue) {
	alert($p_nID+" "+$p_sValue);
}

function setTimer () {
	// function to automatically log of after $Timer/1000 seconds
	var $Timer = 300000; 
	var $Clock;
	
	//clearTimeout($Clock);
	//$Clock = setTimeout('window.location="http://10.0.0.2/erp/index.php?type=uitloggen"',$Timer); 
}

function addAmount($sForm,$sElement,$nNumber) {
	// to add or substract $nNumber to the given box
    $x = parseInt($sForm.elements[$sElement].value,10);
    
    if (isNaN($x)){
	    $x=0;
    }
    
    $x += $nNumber;
    if ($x < 0){
	    $x=0;
    }
    
    $sForm.elements[$sElement].value = $x;
}

function openLink(src){
	window.location=src;
}

*/
