var ProductOptions=new Array();
var current_prod;
var error = false;

var Bestelarray=new Array();

var optional=new Array();

// JavaScript Document
function toggleotherinfo(){
$("#otherinformation").toggle();

	if($("#minusorplus").html() == "+"){
	$("#minusorplus").html("-")
	}
	else if($("#minusorplus").html() == "-"){
	$("#minusorplus").html("+")
	}	
	else{
	$("#minusorplus").html("-")
	}
}


function newproductqueue(){
	if(ProductOptions.length > 0){
		ProductOptions.length = 0
	}
}


function changeproductqueue(accid,prodid){

	current_prod = prodid;
	checkbox = document.getElementById("acc_"+accid).checked;
	
	if(checkbox){		
		//alert("add:" + accid);
		ProductOptions[ProductOptions.length] = accid;
		$("#gekozenitems").load("source/selecteditems.php",{"products[]":ProductOptions,lang:current_lang,prodid:prodid});
		$("#pricediv").load("source/productprice.php",{"products[]":ProductOptions,lang:current_lang,prodid:prodid,action:"acc"});
	}
	else{
		//alert("remove:" + accid);
		for (var i=0; i <ProductOptions.length; i++){
				if(accid == ProductOptions[i]){
				ProductOptions.splice(i,1);
				}
		}
		$("#gekozenitems").load("source/selecteditems.php",{"products[]":ProductOptions,lang:current_lang,prodid:prodid});
		$("#pricediv").load("source/productprice.php",{"products[]":ProductOptions,lang:current_lang,prodid:prodid,action:"acc"});
	}
}


function playvideo(path){
	$('#video').show();
	$('#video').load("source/video.php",{'path':path});
}


function loadproductsindiv(prodid){
		if(current_prod == prodid){
		$("#gekozenitems").load("source/selecteditems.php",{"products[]":ProductOptions,lang:current_lang,prodid:prodid});
		$("#pricediv").load("source/productprice.php",{"products[]":ProductOptions,lang:current_lang,prodid:prodid,action:"acc"});
		
		//do checkboxes
			for (var i=0; i <ProductOptions.length; i++){
			idstring = "acc_" + ProductOptions[i];
			document.getElementById(idstring).checked = true;
			}
		}
		else{
			ProductOptions.splice(0,ProductOptions.length);
		}
}

function isset(varname){
  return(typeof(window[varname])!='undefined');
}

function bestel(prodid){
	aantal = document.getElementById("amount").value;
	kleuroptions = document.getElementById("product_kleur");
	kleur = kleuroptions.options[kleuroptions.options.selectedIndex].value;

  	if (isInteger(aantal) == true){


			//add to bestel queue
			Bestelarray[Bestelarray.length]=prodid;
				
			//add opties
			//for (i=0; i<ProductOptions.length;i++){
			//	addtooptionqueue(ProductOptions[i]);
			//}
			

			$.post("source/productcheck.php",{"prodid":prodid}, function(data){
				if(data != "true"){
					$("#maincontent").load("source/order.php",{'lang': current_lang,'prodid':prodid,'optional[]':ProductOptions,'aantal':aantal,'prodid':prodid,'action':"add",'kleur':kleur});
					currentpage="order.php";
					pagetype="server"		
				}
				else{
				alert("You cannot add this product because you allready have this product in your order. If you want to modify your order please do so in the order overview.");
				}
			});
			
	}
	else{
		alert("The amount of lifts is not a valid number")
	}
}

function isInteger(s) {
return (s.toString().search(/^-?[0-9]+$/) == 0);
}


function bestel_todb(){
bedrijfnaam = document.getElementById("order_bname").value;
voornaam = document.getElementById("order_vname").value;
achternaam = document.getElementById("order_surname").value;

telefoon = document.getElementById("order_tel").value;
mobiel = document.getElementById("order_mobiel").value;
email = document.getElementById("order_email").value;

city = document.getElementById("order_city").value;
postal = document.getElementById("order_postal").value;

countrylist = document.getElementById("order_country");

country = countrylist.options[countrylist.options.selectedIndex].text;

street = document.getElementById("order_street").value;
nr = document.getElementById("order_nr").value;
comment = document.getElementById("order_comment").value;

$.post("source/order_todb.php",{'lang': current_lang,'bedrijfnaam':bedrijfnaam,'voornaam':voornaam,'achternaam':achternaam,'telefoon':telefoon,'mobiel':mobiel,'email':email,'city':city,'postal':postal,'country':country,'street':street,'nr':nr,'comment':comment});
scroll(0,0);
$("#maincontent").load("source/confirm.php",{'lang': current_lang});
}

function nextimage(index,prodid){
newindex = index + 1;
$("#imageviewerwindow").load("source/imageviewer.php",{'prodid': prodid,'index':newindex,'db':'true','lang':current_lang});
}

function lastimage(index,prodid){
newindex = index - 1;
$("#imageviewerwindow").load("source/imageviewer.php",{'prodid': prodid,'index':newindex,'db':'true','lang':current_lang});
}


function showall(prodid){
$("#imageviewer").load("source/productimages_totalview.php",{'prodid':prodid});
}

function view_spec_img(imagepath,prodid){
	$("#imageviewerwindow").load("source/imageviewer.php",{'db':'true','lang':current_lang,'imagepath':imagepath,'prodid':prodid});
}

function download(path){
window.open(path,"Download_from_JIG_Europe")
}

function addtooptionqueue(option){
		//optional[productid][option]
	optional[optional.length]=option;
}

function actualiseeroption(optionid){
	amount = document.getElementById('optamountfield_'+optionid).value;
	
	$.post("source/updatecart.php",{"optionid":optionid,"amount":amount,"action":"option"}, function(data){
		$("#prijsoverzicht").load("source/orderprijsoverzicht.php",{'db':'true','lang':current_lang});
	});
}

function actualiseerproduct(prodid){
	amount = document.getElementById('prodamountfield_'+prodid).value;
	
	$.post("source/updatecart.php",{"prodid":prodid,"amount":amount,"action":"product"}, function(data){
		$("#prijsoverzicht").load("source/orderprijsoverzicht.php",{'db':'true','lang':current_lang});
	});
}

function removeoption(optionid){
	
	$.post("source/removenode.php",{"optionid":optionid,'action':"option"}, function(data){
		$('#orderlinkid').load('source/orderamount.php',{'lang': current_lang,'db':'true'})
		$("#prijsoverzicht").load("source/orderprijsoverzicht.php",{'db':'true','lang':current_lang});
	});	
}

function removeproduct(prodid){
	
	$.post("source/removenode.php",{"prodid":prodid,'action':"product"}, function(data){
		$('#orderlinkid').load('source/orderamount.php',{'lang': current_lang,'db':'true'})
		$("#prijsoverzicht").load("source/orderprijsoverzicht.php",{'db':'true','lang':current_lang});
	});	
}
