﻿// JScript File
function calculatePrice(type,ln){
    if(type == "postCard"){
        if(ln == "fa"){
            totalPrice = (document.getElementById("ctl00_Main_txtQuantity1").value/1 + document.getElementById("ctl00_Main_txtQuantity2").value/1 + document.getElementById("ctl00_Main_txtQuantity3").value/1 + document.getElementById("ctl00_Main_txtQuantity4").value/1 + document.getElementById("ctl00_Main_txtQuantity5").value/1 + document.getElementById("ctl00_Main_txtQuantity6").value/1)*500;
            if(totalPrice > 0){
                if(totalPrice >= 30000){
                    discount = Math.round((totalPrice*20)/100);
                } else {
                    discount = 0;
                }
            } else {
                totalPrice = 0;
                discount = 0;
            }
            document.getElementById("totalPricePreveiw").innerHTML = totalPrice + " تومان";
            document.getElementById("discountPreveiw").innerHTML = discount + " تومان";
            document.getElementById("finalPricePreveiw").innerHTML = (totalPrice - discount) + " تومان";
            document.getElementById("shippingPricePreveiw").innerHTML = "به عهده خریدار";
            document.getElementById("ctl00_Main_txtFinalPrice").value = (totalPrice - discount) + " تومان";
        } else if(ln == "en"){
            totalPrice = (document.getElementById("ctl00_Main_txtQuantity1").value/1 + document.getElementById("ctl00_Main_txtQuantity2").value/1 + document.getElementById("ctl00_Main_txtQuantity3").value/1 + document.getElementById("ctl00_Main_txtQuantity4").value/1 + document.getElementById("ctl00_Main_txtQuantity5").value/1 + document.getElementById("ctl00_Main_txtQuantity6").value/1)*1 + (document.getElementById("ctl00_Main_txtPackQuantity").value/1)*5.40;
            /*if(totalPrice > 0){
                if(totalPrice >= 30000){
                    discount = Math.round((totalPrice*20)/100);
                } else {
                    discount = 0;
                }
            } else {
                totalPrice = 0;
                discount = 0;
            }*/
            newNum = new Number(totalPrice);
            totalPrice = newNum.toFixed(2);
            document.getElementById("totalPricePreveiw").innerHTML = " US$" + totalPrice;
            //document.getElementById("discountPreveiw").innerHTML = discount + " تومان";
            //document.getElementById("finalPricePreveiw").innerHTML = (totalPrice - discount) + " تومان";
            document.getElementById("shippingPricePreveiw").innerHTML = "به عهده خریدار";
            document.getElementById("ctl00_Main_txtFinalPrice").value = " US$" + totalPrice;
        
        }
    } else if(type == "book"){
        if(ln == "fa"){
            totalPrice = (document.getElementById("ctl00_Main_txtQuantity").value/1)*1800;
            if(totalPrice > 0){
                if(totalPrice >= 30000){
                    discount = Math.round((totalPrice*20)/100);
                } else {
                    discount = 0;
                }
            } else {
                totalPrice = 0;
                discount = 0;
            }
            document.getElementById("totalPricePreveiw").innerHTML = totalPrice + " تومان";
            document.getElementById("discountPreveiw").innerHTML = discount + " تومان";
            document.getElementById("finalPricePreveiw").innerHTML = (totalPrice - discount) + " تومان";
            document.getElementById("shippingPricePreveiw").innerHTML = "به عهده خریدار";
            document.getElementById("ctl00_Main_txtFinalPrice").value = (totalPrice - discount) + " تومان";
        }
    }
}

function validateMinimum(ln){
    if((document.getElementById("ctl00_Main_txtQuantity1").value > 0) || (document.getElementById("ctl00_Main_txtQuantity2").value > 0) || (document.getElementById("ctl00_Main_txtQuantity3").value > 0) || (document.getElementById("ctl00_Main_txtQuantity4").value > 0) || (document.getElementById("ctl00_Main_txtQuantity5").value > 0) || (document.getElementById("ctl00_Main_txtQuantity6").value > 0)) {
        if ((document.getElementById("ctl00_Main_txtQuantity1").value/1 + document.getElementById("ctl00_Main_txtQuantity2").value/1 + document.getElementById("ctl00_Main_txtQuantity3").value/1 + document.getElementById("ctl00_Main_txtQuantity4").value/1 + document.getElementById("ctl00_Main_txtQuantity5").value/1 + document.getElementById("ctl00_Main_txtQuantity6").value/1) >= 20) {
            return true;
        } else {
            document.getElementById("error").innerHTML = "شما در این سیستم نمی توانید کمتر از 20 عدد کارت پستال خریداری نمایید.";
        }
    } else {
        if(ln == "fa"){
            document.getElementById("error").innerHTML = "تعداد درخواستی برای هیچ یک از کالاها مشخص نشده است.";
        } else if(ln == "en"){
            document.getElementById("error").innerHTML = "The quantity has not specified for any goods.";
        }
        return false;
    }
}

function clearError(){
    if((document.getElementById("ctl00_Main_txtQuantity1").value > 0) || (document.getElementById("ctl00_Main_txtQuantity2").value > 0) || (document.getElementById("ctl00_Main_txtQuantity3").value > 0) || (document.getElementById("ctl00_Main_txtQuantity4").value > 0) || (document.getElementById("ctl00_Main_txtQuantity5").value > 0) || (document.getElementById("ctl00_Main_txtQuantity6").value > 0) || (document.getElementById("ctl00_Main_txtPackQuantity").value > 0)) {
        document.getElementById("error").innerHTML = "&nbsp;";
    }
}

var Dispwin
function magnifyImage(code) {
	if(Dispwin){
		Dispwin.close();
	}
	Dispwin = window.open('','photo','height=572,width=460,status=no,toolbar=no,menubar=no,location=no,channelmode=no,directories=no,fullscreen=no,left=0,top=0,resizable=no,scrollbars=no');
	bodyContent = "<body style='margin:0px'><img style='margin:0px' src='../../../../../images/shop/postcards/" + code + ".jpg' /></body>";
	Dispwin.document.write(bodyContent);
	Dispwin.focus();
}

