function calcShipping()
{

	var ship = document.getElementById("shipping");
	var currValue = ship.value;
	var amount = 0;
	var total = document.getElementById("total");
	//checking last ship
	var lastShip = document.getElementById("lastShip");
	switch (currValue)
	{
	case "ragil":
	  amount = 10;
	  break;
	case "rashum":
	  amount = 15;
	  break;
	case "shalih":
	  amount = 35
	  break;
	default:
	  amount = 0;
	}
	if(lastShip == 0)
	{
		document.getElementById("total").innerHTML = parseInt(total.innerHTML) + parseInt(amount);
	}
	else
	{
		document.getElementById("total").innerHTML = parseInt(total.innerHTML) - parseInt(lastShip.value);
		document.getElementById("total").innerHTML = parseInt(total.innerHTML) + parseInt(amount);
		lastShip.value = amount;
		document.getElementById("amount").value = parseInt(total.innerHTML);
	}
	
}

function calcOnload()
{
	var ship = document.getElementById("shipping");
	
	if(ship != null)
	{
		var currValue = ship.value;
		var lastShip = document.getElementById("lastShip");
		if(ship.selectedIndex > 0)
		{
			switch (currValue)
			{
			case "ragil":
			  amount = 10;
			  break;
			case "rashum":
			  amount = 15;
			  break;
			case "shalih":
			  amount = 35
			  break;
			default:
			  amount = 0;
			}
			if(lastShip == 0)
			{
				document.getElementById("total").innerHTML = parseInt(total.innerHTML) + parseInt(amount);
			}
			else
			{
				document.getElementById("total").innerHTML = parseInt(total.innerHTML) - parseInt(lastShip.value);
				document.getElementById("total").innerHTML = parseInt(total.innerHTML) + parseInt(amount);
				lastShip.value = amount;
			}
		}
	}
}

function validCartSubmit()
{
	for(i=0; i<document.orderForm.elements.length; i++)
	{
		if(document.orderForm.elements[i].name != "")
		{
			var field = document.orderForm.elements[i].name.substring(0,3);
			if(field == "qty")
			{
				if(document.orderForm.elements[i].value == "0")
				{
					alert("כמות 0 לא חוקית - 1 או יותר");
					return false;
				}
				
			}
		}
	}
	
	var shipping = document.getElementById("shipping");
	
	var globalAmount = document.getElementById("globalAmount");
	//alert(globalAmount)
	if(globalAmount.value == 5)
	{
		document.getElementById("total").innerHTML = 5;
		document.getElementById("amount").value = 5;
	}
	
	if(shipping.selectedIndex == 0)
	{
		alert("בחר שיטת משלוח");
		shipping.focus();
		return false;
	}
	
	payment = document.getElementById("payment");
	if(payment.selectedIndex == 0)
	{
		alert("בחר אופן תשלום");
		payment.focus();
		return false;
	}
	
	if(payment.selectedIndex == 2)
	{
		var amount = document.getElementById("total");
		popwin("order.php?amount="+amount.innerHTML+"&MerchantData="+BuildMerchantStr());
		return false
	}
	BuildMerchantStr();
	win1 = window.open ("f2.html", "win1","location=1,status=1,scrollbars=1,resizable=1,width=870,height=600");
	
	document.orderForm.submit();
}

function updateCart()
{
	var qStr = "";
	for(i=0; i<document.orderForm.elements.length; i++)
	{
		if(document.orderForm.elements[i].name != "")
		{
			var field = document.orderForm.elements[i].name.substring(0,3);
			
			if(field == "qty" || field=="ddl" || field=="cat")
			{
				if(document.orderForm.elements[i].value == "0")
				{
					alert("כמות 0 לא חוקית - 1 או יותר");
					return false;
				}
				qStr = qStr + document.orderForm.elements[i].name+"="+document.orderForm.elements[i].value+"&";
			}
		}
	}
	shipping = document.getElementById("shipping");
	payment = document.getElementById("payment");
	
	
	location.href="cart.php?action=update&shIdx="+shipping.selectedIndex+"&pmIdx="+payment.selectedIndex+"&" + qStr;
}

function popwin(page)
{
	testwindow= window.open (page, "mywindow","location=1,status=1,scrollbars=1,resizable=1,width=820,height=640");
}
function popwinPrm(page,w,h)
{
	testwindow= window.open (page, "mywindow","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+"");
}
function confirmDelete() {
  return confirm("?הפריט יימחק - האם אתה בטוח");
}

function BuildMerchantStr()
{
	shipping = document.getElementById("shipping");
	payment = document.getElementById("payment");
	var merStr = document.getElementById("MerchantData").value;
	merStr = merStr.replace("ship:1","");
	merStr = merStr.replace("ship:2","");
	merStr = merStr.replace("ship:3","");
	merStr = merStr.replace("ship:4","");
	merStr = merStr.replace(":","");
	document.getElementById("MerchantData").value = merStr + ":ship:"+shipping.selectedIndex;
	//alert(document.getElementById("MerchantData").value)
	return document.getElementById("MerchantData").value;
}

/**

 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

 */

function echeck(str) {

 

                        var at="@"

                        var dot="."
						var errMsg = "כתובת דואר אלקטרוני לא תקינה";

                        var lat=str.indexOf(at)

                        var lstr=str.length

                        var ldot=str.indexOf(dot)

                        if (str.indexOf(at)==-1){

                           alert(errMsg)

                           return false

                        }

 

                        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

                           alert(errMsg)

                           return false

                        }

 

                        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

                            alert(errMsg)

                            return false

                        }

 

                         if (str.indexOf(at,(lat+1))!=-1){

                            alert(errMsg)

                            return false

                         }

 

                         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

                            alert(errMsg)

                            return false

                         }

 

                         if (str.indexOf(dot,(lat+2))==-1){

                            alert(errMsg)

                            return false

                         }

                        

                         if (str.indexOf(" ")!=-1){

                            alert(errMsg)

                            return false

                         }

 

                         return true                                                        

            }

function validForm()
{

var name = document.getElementById("name").value;
var email = document.getElementById("email");
var phone = document.getElementById("phone").value;
if(name == "")

{

            alert("אנא מלא שם");
			document.getElementById("name").focus();
            return false
			
}

if(email.value == "")

{

            alert("אנא מלא כתובת דואר");
			document.getElementById("email").focus();
            return false

}

            

if ((email.value==null)||(email.value=="")){

                        alert("אנא מלא כתובת דואר")

                        email.focus()

                        return false

}

if (echeck(email.value)==false){

                        email.focus()

                        return false

}


}
