var actual = 1;
var buttoni = 'prev';
var max_img;
var checks = 0;

function show(id)
{
	try			
	{
		document.getElementById("a"+actual).style.display = "none";
		document.getElementById(id).style.display = "block";			
		
		 if(buttoni == 'prev' && (actual-1) <= 1)
		{document.getElementById("prev").style.color = "#9a9a8a";}
		else
		{document.getElementById("prev").style.color = "#000000";}
		 
		 if(buttoni == 'next' && (actual+1) == max_img)
		{document.getElementById("next").style.color = "#9a9a8a";}
		else
		{document.getElementById("next").style.color = "#000000";}				
	}
	catch(err)
  {
  	//alert(err);
  }
}

function checkInput(inpt){
	var inputs = document.getElementsByTagName("input");
	if(document.getElementById("inpt_"+inpt).checked == true)
	{
		checks++;
	}
	else
	{
		checks--;
	}
	if(checks == allowedChecks)
	{
 		
 		for(i=0; i< inputs.length; i++)
 		{
 			if(inputs[i].type == "checkbox" && inputs[i].checked == false)
 			{
 				inputs[i].disabled = true;
 			}
 		}
	}
	else
	{
		for(i=0; i< inputs.length; i++)
 		{
 			if(inputs[i].type == "checkbox" && inputs[i].disabled == true)
 			{
 				inputs[i].disabled = false;
 			}
 		}
	}
}
function checkMessage(el,msg,chrslft)
{
	var chars = el.value;
	document.getElementById("order_message").innerHTML = msg+"("+(160-chars.length)+" "+chrslft+")";
}	
function justNumber(evt,el)
{
  if(evt.keyCode) // IE
  {
  	charCode = evt.keyCode;
  }
	else if(evt.which) // Netscape/Firefox/Opera
  {
  	charCode = evt.which;
  }
   //var charCode = (evt.which) ? evt.which : event.keyCode;
   charCode = parseInt(charCode);
   //if(charCode >= 48 && charCode <= 57 || charCode == 9)
   if (charCode == 8 || charCode == 9 || (charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105) || charCode == null)
   	return true
   else
   	return false;
}
function getDeleteConfirmation_js(deleted_item,shid)
{
	var answer = confirm(deleted_item);
	if (answer){
		//document.getElementById("del_prod").value = shid;
		document.getDeleteConfirmationForm.submit();
	}else{
		return false;
	}
}
function open_window()
{
window.open ("<? echo $subdir.$incdir.'upload.php'; ?>","mywindow","menubar=1,resizable=1,width=400,height=220");	
}
function open_conditions(idja)
{
	//window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200');
	//window.open('http://www.tefala.com/inc/terms_and_conditions.php?cid=1','Terms_And_Conditions','width=600,height=800,toolbar=1,location=no,directories=no,status=no,menubar=no,scrollbars=1,copyhistory=no,resizable=1');
	if(idja == 1)
	{
		window.open('http://www.tefala.com/inc/pages/terms_and_conditions.php?cid=1','Terms_And_Conditions','width=600,height=800');
	}
	else
	{
		if(idja == 2)
		window.open('http://www.tefala.com/inc/pages/terms_and_conditions.php?cid=2','Terms_And_Conditions','width=600,height=800');
	}
}
 

function noString(evt,input)
{
	 if(evt.keyCode) // IE
	  {
	  	charCode = evt.keyCode;
	  }
	else if(evt.which) // Netscape/Firefox/Opera
	  {
	  	charCode = evt.which;
	  }
   //var charCode = (evt.which) ? evt.which : event.keyCode;
   charCode = parseInt(charCode);
   
   //if (charCode > 31 && (charCode < 48 || charCode > 57) || (charCode < 96 || charCode > 105) || charCode == null)
   if (charCode == 8 || charCode == 9 || (charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105) || charCode == null)
   {return true;}
	 else
   { return false; }
}  
function update_value(input)
{
	var num;
	var res;
	//document.cart.submit()
	if(parseInt(document.getElementById("amount"+input).value) <= 0)
	document.getElementById("amount"+input).value = 1;
	
	num = parseFloat(document.getElementById("price"+input).value)*(parseInt(document.getElementById("amount"+input).value));
	res = num.toFixed(2);
	
	document.getElementById("total"+input).value = res;
}
function update_value_blur(input)
{
	var num;
	var res;
	if(parseInt(document.getElementById("amount"+input).value) <= 0 || document.getElementById("amount"+input).value == '')
	document.getElementById("amount"+input).value = 1;
	
	num = parseFloat(document.getElementById("price"+input).value)*(parseInt(document.getElementById("amount"+input).value));
	res = num.toFixed(2);
	document.getElementById("total"+input).value = res;
}
function show(id,stylished)
{
	try
	{
		document.getElementById(id).style.display = stylished;
	}
	catch(err)
  {
	}
} 
function showhide(id,style)
{
	try
	{
		var curstyle = document.getElementById(id).style.display;
		if(curstyle == 'none'){
		document.getElementById(id).style.display = style;
		}
		else{
			document.getElementById(id).style.display = 'none';
		}
	}
	catch(err)
  {
	}
}
function upload_img()
{
	document.uploadPhoto.submit();
}
function alert_no_products(el,amount,loop)
{
	if(el.value > amount)
	{
		alert("This amount is not available right now. The recomended amount is set to the number of this product. Thanks!");
		el.value = amount;
		update_value_blur(loop);
		return false;
	}
	else
	{
		return true;
	}		
}
function checkOut_js(msg)
{
	try{
		//funksioni per select boxat e detyrueshem
		if(required_select_selected(shopping_cart_required_selects,shopping_cart_required_selects_notification))
		{
			document.checkout.submit();
		}
	}catch(err){
		//alert(err);
	}
}
function make_payment(msg)
{
	selForm = document.getElementById("select_bank");
	opts = selForm.getElementsByTagName("option");
	selIndex = selForm.selectedIndex;
	if(opts[selIndex].value != 0)
	{
		return true;
	}else{
		alert(msg);
		selForm.focus();
		return false;
	}	
}
function required_select_selected(stack,error_stack)
{
	var ret = true;
	try{
		for(var i = 0; i < stack.length ; i++)
		{
			var selectCheck = stack[i];
			var sel = document.getElementById(selectCheck);
			var val = sel.options[sel.selectedIndex].value
			if( val == undefined || val == 0 || val == '')
			{
				ret = false;
				alert(error_stack[i]);
				sel.focus();
				return ret;
			}
		}
		return ret;
	}catch(err){
		alert(err);
	}
}
function set_shipping(sel)
{
	try{
		var val = sel.options[sel.selectedIndex].value;
		document.shipping_form.shipping_form_id.value = val;
		document.shipping_form.submit();
	}
	catch(err){
		
	}
}
function set_delivery_form(sel)
{
	try{
		var val = sel.options[sel.selectedIndex].value;
		document.payment_type_form.payment_type_form_id.value = val;
		document.payment_type_form.submit();
	}
	catch(err){
		
	}
}
function open_informator(idja)
{
	if(idja == 1){
		window.open('http://www.tefala.com/inc/pages/informator.php?cid=1','Informator','width=600,height=770');
	}
	else{
		if(idja == 2)
		window.open('http://www.tefala.com/inc/pages/informator.php?cid=2','Informator','width=600,height=770');
	}
}
function open_video_manual(idja)
{
	if(idja == 1){
		window.open('http://www.tefala.com/inc/pages/video.php?cid=1','Video_tutoriali','width=990,height=649');
	}
	else{
		if(idja == 2)
		window.open('https://www.tefala.com/inc/pages/video.php?cid=2','Video_tutorial','width=990,height=649');
	}
}