var baseurl = "http://www.alljobs.ir/store/includes/";
//var baseurl = "http://localhost/asnaf/store/includes/";
var wait="";
var para="";
var delall ="";
frmcheckout = false;
$(document).ready(function () {
loadcomplete = true;
makeRequest('store_ajax.php?mo=showcart','1stshowcart');
});
function makeRequest(url,para,postform) {
if(postform){postpara = createQuery(postform);}else{postpara="";}
if(para!="1stshowcart"){
$('#dialogWait').dialog({modal: true,closeOnEscape: false, width: 300, height: 100});
}else{
para= "showcart";
}
//if(postpara){makeAlert(postpara);$('#dialogWait').dialog("close");return false;}
$.ajax({
type: "POST",
url: baseurl + url,
data: postpara,
success: function(response){
$('#dialogWait').dialog("close");
alertContents(response,para)
},
error: function(){
$('#dialogWait').dialog("close");
$('#dialogError').dialog({modal: true, width: 300, height: 170, buttons: { "OK": function() { $(this).dialog("close"); } }});
}
});
}
function alertContents(response,para) {
if (para=="showcart"){
$('#butshowcart').hide();
$('#divshowcart').html(response);
if($('#divnewbody').css("display")=="block"){
makeRequest("store_ajax.php?mo=checkout","checkout");
}
}else if(para=="addcart") {
if(response=="Add"){
$('#dialogAdd').dialog({modal: true, width: 300, height: 170, buttons: { "OK": function() { $(this).dialog("close"); } }});
}else if(response=="Exist"){
$('#dialogExist').dialog({modal: true, width: 300, height: 170, buttons: { "OK": function() { $(this).dialog("close"); } }});
}
makeRequest("store_ajax.php?mo=showcart","showcart");
}else if(para=="delcart") {
$('#dialogDeleted').dialog({modal: true, width: 300, height: 170, buttons: { "OK": function() { $(this).dialog("close"); } }});
makeRequest("store_ajax.php?mo=showcart","showcart");
}else if(para=="checkout") {
$('#divnewbody').html(response);
$('#divbody').hide();
$('#divnewbody').show();
}else if(para=="submitcheckout") {
if(response=="orderyes"){
$('#dialogOrdered').dialog({modal: true, width: 300, height: 270, buttons: { "OK": function() { $(this).dialog("close"); } }});
makeRequest("store_ajax.php?mo=showcart","showcart");
$('#divnewbody').hide();
$('#divbody').show();
}else if(http_request.responseText=="orderno"){
$('#dialognoOrdered').dialog({modal: true, width: 300, height: 170, buttons: { "OK": function() { $(this).dialog("close"); } }});
$('#divnewbody').hide();
$('#divbody').show();
}
}
}
function makeAlert(msg){
$('#dialogMsg').html(msg);
$('#dialogMsg').dialog({modal: true, width: 300, height: 170, buttons: { "OK": function() { $(this).dialog("close"); } }});
}
function createQuery(myForm){
var pairs = new Array();
$('#frmcheckout :input').each(function() {
if(this.value) pairs.push(this.name + "=" + encodeURIComponent(this.value));
});
///pairs.push("shipping=" + encodeURIComponent($("#shipping").val()));
//pairs.push("payment=" + encodeURIComponent($("#payment").val()));
return pairs.join("&");
}
function checkoutform(){
if($('[name="name"]').val()==''){
makeAlert('نام و نام خانوادگی را وارد کنید');
//document.all.name.focus();
}else if($('[name="tel"]').val()==''){
makeAlert('تلفن و یا موبایل را وارد کنید');
}else if($('[name="city"]').val()==''){
makeAlert('نام شهر را وارد کنید');
}else if($('[name="address"]').val()==''){
makeAlert('آدرس کامل پستی را وارد کنید');
}else{
return true;
}
return false;
}
function updatepayment(count,kind){
$('[name="shippingtotal"]').val(count);
$('[name="totaltotal"]').val(count);
$('[name="totaltotal"]').val(eval($('[name="shippingtotal"]').val()) + eval($('[name="ordertotal"]').val()));
$('[name="shipping"]').val(kind)
if(kind=='motor'){
document.all.ppayment[0].disabled=false;
document.all.ppayment[0].checked=true;
document.all.ppayment[1].disabled=true;
$('#insideguide').show();
$('#bankguide').hide();
$('#payment').val('insite');
}
if(kind=='post'){
document.all.ppayment[1].disabled=false;
document.all.ppayment[1].checked=true;
document.all.ppayment[0].disabled=true;
$('#insideguide').hide();
$('#bankguide').show();
$('#payment').val('bank');
}
if(kind=='ems'){
document.all.ppayment[1].disabled=false;
document.all.ppayment[1].checked=true;
document.all.ppayment[0].disabled=true;
$('#insideguide').hide();
$('#bankguide').show();
$('#payment').val('bank');
}
}