var numbers = new Array();
var int;

var oldvals = new Array();

function setFirst(field) {
	field.select();
	field.style.backgroundColor = "#ffffff";
	field.style.border = "1px solid #666666";
}

function setMenue(field) {
	field.style.backgroundColor = "#ffffff";
	field.style.border = "1px solid #666666";
}

function newCaptcha() {
	var zeit = new Date();
	document.getElementById("captcha-img").src = "fileadmin/inc/class.captcha.php?"
			+ zeit.getMilliseconds();
}

function setOldVal(field) {
	if (field.value == "") {
		field.value = oldvals[field.name];
	}

	// field.select();
}

function setFirstNo(field) {
	if (field.value == oldvals[field.name]) {
		field.value = "";
	}

	field.select();
}

function addToCart(partid,type) {
	$('shoppingcart-body').innerHTML = '<img src="fileadmin/images/ajax-loader.gif"  style="margin-left: 55px; margin-top: 60px;" />';
	var pars = "eID=cart&do=add&L="+type+"&partid=" + partid;
	var myAjax = new Ajax.Request("index.php", {
		method :'get',
		parameters :pars,
		onComplete :updateCart
	});
}

function updateCart(requestObject) {
	var xmldoc = requestObject.responseXML;
	xmldoc.getElementsByTagName("action")[0].normalize();
	xmldoc.getElementsByTagName("partid")[0].normalize();
	xmldoc.getElementsByTagName("cartcontent")[0].normalize();
	
	var cartcontent = xmldoc.getElementsByTagName("cartcontent")[0].firstChild.data;
	cartcontent.evalScripts();
	
	$('shoppingcart-body').innerHTML = cartcontent;

}

function changeQty(field,type) {

	var partid = field.name.split("-");
    partid = partid[1];
    var qty = field.value;
    
    $('shoppingcart-body').innerHTML = '<img src="fileadmin/images/ajax-loader.gif"  style="margin-left: 55px; margin-top: 60px;" />';
    if (qty==0) {
    	var pars = "eID=cart&do=remove&L="+type+"&partid=" + partid;
    	var myAjax = new Ajax.Request("index.php", {
    		method :'get',
    		parameters :pars,
    		onComplete :updateCart
    	});
	}else {
		var pars = "eID=cart&do=changeqty&L="+type+"&partid=" + partid+"&qty="+qty;
		var myAjax = new Ajax.Request("index.php", {
			method :'get',
			parameters :pars,
			onComplete :updateCart
		});
	}
	
	
}

function deleteItem(partid,type) {
	$('shoppingcart-body').innerHTML = '<img src="fileadmin/images/ajax-loader.gif"  style="margin-left: 55px; margin-top: 60px;" />';
	var pars = "eID=cart&do=remove&L="+type+"&partid=" + partid;
	var myAjax = new Ajax.Request("index.php", {
		method :'get',
		parameters :pars,
		onComplete :updateCart
	});
}


function deleteItem(partid,type) {
	if (confirm(delMsg)) {
		$('shoppingcart-body').innerHTML = '<img src="fileadmin/images/ajax-loader.gif"  style="margin-left: 55px; margin-top: 60px;" />';
		var pars = "eID=cart&do=remove&L="+type+"&partid=" + partid;
		var myAjax = new Ajax.Request("index.php", {
			method :'get',
			parameters :pars,
			onComplete :updateCart
		});
	}
}

function updateCartItem(requestObject) {
	var xmldoc = requestObject.responseXML;
	xmldoc.getElementsByTagName("action")[0].normalize();
	xmldoc.getElementsByTagName("partid")[0].normalize();
	xmldoc.getElementsByTagName("cartcontent")[0].normalize();
	xmldoc.getElementsByTagName("sum")[0].normalize();
	
	var partid = xmldoc.getElementsByTagName("partid")[0].firstChild.data;
	var sum = xmldoc.getElementsByTagName("sum")[0].firstChild.data;
	var cocontent = xmldoc.getElementsByTagName("cartcontent")[0].firstChild.data;
	if (sum!=0) {
		$('cosum').innerHTML = sum;
		$('copart-'+partid).parentNode.removeChild($('copart-'+partid));
	}else {
		location.href = location.href;
		$('content-main').innerHTML = cocontent;
	}
}


function select_fold(obj){
	remember_select = obj;
	var obj_parent = document.getElementById(obj+'_parent');
	var obj = document.getElementById(obj+'_foldout');
	if(obj.style.display == 'none'){
		obj.style.display = '';
		obj_parent.style.zIndex = 999999;
		$('clear_select').setStyle ({ display: 'block' });
	}else{
		obj.style.display = 'none';
		obj_parent.style.zIndex = 1;
		$('clear_select').setStyle ({ display: 'none' });
	}
}

function clear_select(){
	select_fold(remember_select);
}
function setValQty(obj,val,text) {
	var linktext = document.getElementById(obj+'_link');
	linktext.innerHTML = text;
	
	var field = $(obj);
	field.value = val;
	select_fold(obj);
	
	changeQty(field);
}

function switchProducer(id) {
	$('innerheaderimg').src = producers[id]["headermiddle"].src;
	$('innerheaderimg').width =  producers[id]["headermiddle"].width;
	$('innerheaderimg').height =  producers[id]["headermiddle"].height;
	$('innerheaderimg').alt = producers[id]["title"];
	$('innerheaderimg').title = producers[id]["title"];
	
	$('featureimg').src = producers[id]["featureimg"].src;
	$('featureimg').alt = producers[id]["title"];
	$('featureimg').title = producers[id]["title"];
	
	$('producertext').innerHTML = producers[id]["text"];
	
	$('morebutton').href = producers[id]["link"];
	
	if (producers[id-1]!=undefined) {
		$('left-arrow').style.display = "block";
		$('leftheaderimg').src = producers[id-1]["headerleft"].src;
		$('leftheaderimg').width =  producers[id-1]["headerleft"].width;
		$('leftheaderimg').height =  producers[id-1]["headerleft"].height;
		$('leftheaderimg').alt = producers[id-1]["title"];
		$('leftheaderimg').title = producers[id-1]["title"];
		$('left-arrow').href = 'javascript:switchProducer('+(id-1)+');';
	}else {
		$('left-arrow').style.display = "none";
	}
	if (producers[id+1]!=undefined) {
		$('right-arrow').style.display = "none";
		var afterT = "block";
		$('rightheaderimg').src = producers[id+1]["headerleft"].src;
		$('rightheaderimg').width =  producers[id+1]["headerleft"].width;
		$('rightheaderimg').height =  producers[id+1]["headerleft"].height;
		$('rightheaderimg').alt = producers[id+1]["title"];
		$('rightheaderimg').title = producers[id+1]["title"];
		$('right-arrow').href = 'javascript:switchProducer('+(id+1)+');';
	}else {
		$('right-arrow').style.display = "none";
		var afterT = "none";
	}
	
	new Effect.SlideFromLeft("startfeature");
	
	setTimeout('$("right-arrow").style.display = "'+afterT+'";',1100);

}

function select_fold_big(obj){
	remember_select = obj;
	var obj_parent = document.getElementById(obj+'_parent');
	var obj = document.getElementById(obj+'_foldout');
	if(obj.style.display == 'none'){
		obj.style.display = '';
		obj_parent.style.zIndex = 999999;
		$('clear_select_big').setStyle ({ display: 'block' });
	}else{
		obj.style.display = 'none';
		obj_parent.style.zIndex = 1;
		$('clear_select_big').setStyle ({ display: 'none' });
	}
}

function clear_select_big(){
	select_fold_big(remember_select);
}

function setValBig(obj,val,text) {
	var linktext = document.getElementById(obj+'_link');
	linktext.innerHTML = text;
	
	var field = $(obj);
	field.value = val;
	
	var fullStr = 'http://'+domain+'/'+val;
	
	if (fullStr != window.location.href) {
		window.location.href = fullStr;
	}
	select_fold_big(obj);
}




function changeQtyBig(field,type) {

	var partid = field.name.split("-");
    partid = partid[1];
    var value = field.value;
    
	var pars = "eID=cart&do=changeqtycart&L="+type+"&partid=" + partid+"&qty="+value;
	var myAjax = new Ajax.Request("index.php", {
		method :'get',
		parameters :pars,
		onComplete :updatePrices
	});
}

function deleteItemB(partid) {
	if (confirm(delMsg)) {
		$('copart-'+partid).hide(); 
		var pars = "eID=cart&do=remove&L="+type+"&partid=" + partid+"&big=1";
		var myAjax = new Ajax.Request("index.php", {
			method :'get',
			parameters :pars,
			onComplete :updateCartItem
		});
	}
}

function updatePrices(requestObject) {
	var xmldoc = requestObject.responseXML;
	xmldoc.getElementsByTagName("action")[0].normalize();
	xmldoc.getElementsByTagName("partid")[0].normalize();
	xmldoc.getElementsByTagName("cartcontent")[0].normalize();
	xmldoc.getElementsByTagName("sum")[0].normalize();
	
	var partid = xmldoc.getElementsByTagName("partid")[0].firstChild.data;
	var sum = xmldoc.getElementsByTagName("sum")[0].firstChild.data;
	var price = xmldoc.getElementsByTagName("cartcontent")[0].firstChild.data;

	$('price-'+partid).innerHTML = price;
	$('cosum').innerHTML = sum;
}




var remeber_select = '';

function cr_select_fold(obj){
	remeber_select = obj;
	var obj_parent = document.getElementById(obj+'_parent');
	var obj = document.getElementById(obj+'_foldout');
	if(obj.style.display == 'none'){
		obj.style.display = '';
		obj_parent.style.zIndex = 99;
		document.getElementById('clear_select').style.display = '';
	}else{
		obj.style.display = 'none';
		obj_parent.style.zIndex = 1;
		document.getElementById('clear_select').style.display = 'none';
	}
}

function cr_select_setval(obj,val,txt){
	var linktext = document.getElementById(obj+'_link');
	linktext.innerHTML = txt;
	
	var feld = MM_findObj(obj);
	feld.value = val;
	cr_select_fold(obj);
}

function clear_select(){
	cr_select_fold(remeber_select);
}
