var wait="";
var para="";
var delall ="";
frmcheckout = false;
function makeRequest(url,p,postform) {
para = p;
if(postform){postpara = createQuery(postform);}else{postpara="";}
if(para!="1stshowcart"){
wait = true;
alert("چند لحظه صبر کنيد . . .");
}else{
para= "showcart";
}
var http_request = false;
url = "http://www.alljobs.ir/store/includes/" + url ;
//url = "http://localhost/asnaf/store/includes/" + url ;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType("text/xml");
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert("Giving up :( Cannot create an XMLHTTP instance");
return false;
}
http_request.onreadystatechange = function() { alertContents(http_request,para); };
http_request.open("POST", url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
http_request.setRequestHeader("Content-length", postpara.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(postpara);
}
function alertContents(http_request,para) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
if(wait){
removeCustomAlert();
wait = false;
}
if (para=="showcart"){
document.all.butshowcart.style.display="none";
div = document.getElementById("div"+para);
div.innerHTML = http_request.responseText;
if(document.all.divnewbody.style.display=="block"){
makeRequest("store_ajax.php?mo=checkout","checkout");
}
}else if(para=="addcart") {
alert(http_request.responseText);
}else if(para=="delcart") {
alert(http_request.responseText);
}else if(para=="checkout" || para=="sendtofriend") {
document.all.divbody.style.display="none";
document.all.divnewbody.style.display="block";
div = document.getElementById("divnewbody");
div.innerHTML = http_request.responseText;
}else if(para=="submitcheckout") {
if(http_request.responseText=="orderyes"){
delall = 'yes';
mg='از خرید شما متشکریم';
mg=mg+'
منتظر تماس ما باشید';
mg=mg+'
تلفن تماس';
mg=mg+'
021-88750200';
alert(mg);
document.all.divnewbody.style.display="none";
document.all.divbody.style.display="block";
}else if(http_request.responseText=="orderno"){
alert("مشکلی وجود دارد لطفا بعدا اقدام کنید");
document.all.divnewbody.style.display="none";
document.all.divbody.style.display="block";
}
}else if(para=="submitsendtofriend") {
if(http_request.responseText=="sendyes"){
alert("ايميل شما با موفقيت ارسال شد.");
document.all.divnewbody.style.display="none";
document.all.divbody.style.display="block";
}else if(http_request.responseText=="sendno"){
alert("ايميل شما ارسال نشد.
لطفا بعدا اقدام کنيد.
با تشکر");
document.all.divnewbody.style.display="none";
document.all.divbody.style.display="block";
}
}
} else {
alert("There was a problem with the request1.");
}
}
}
// constants to define the title of the alert and button text.
var ALERT_TITLE = "توجه";
var ALERT_BUTTON_TEXT = "ادامه";
var ALERT_BUTTON_CANCEL = "انصراف";
// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
window.alert = function(txt,conf) {
createCustomAlert(txt,conf);
}
}
function createCustomAlert(txt,conf) {
// shortcut reference to the document object
d = document;
// if the modalContainer object already exists in the DOM, bail out.
if(d.getElementById("modalContainer")) return;
// create the modalContainer div as a child of the BODY element
mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
mObj.id = "modalContainer";
// make sure its as tall as it needs to be to overlay all the content on the page
mObj.style.height = document.documentElement.scrollHeight + "px";
//mObj.style.textAlign = "center";
// create the DIV that will be the alert
alertObj = mObj.appendChild(d.createElement("div"));
alertObj.id = "alertBox";
alertObj.style.textAlign = "center";
// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
// center the alert box
alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
alertObj.style.top = document.body.scrollTop + "px";
// create an H1 element as the title bar
h1 = alertObj.appendChild(d.createElement("h1"));
h1.appendChild(d.createTextNode(ALERT_TITLE));
// create a paragraph element to contain the txt argument
var splittxt = new Array();
splittxt = txt.split("
");
for(i=0; i < splittxt.length; i++){
sbr = alertObj.appendChild(d.createElement("br"));
msg = alertObj.appendChild(d.createElement("span"));
msg.appendChild(d.createTextNode(splittxt[i]));
}
// create an anchor element to use as the confirmation button.
if(!wait){
btn = alertObj.appendChild(d.createElement("a"));
btn.id = "closeBtn";
btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
btn.href = "#";
// set up the onclick event to remove the alert when the anchor is clicked
btn.onclick = function() { removeCustomAlert();return false; }
if(conf){
btn2 = alertObj.appendChild(d.createElement("a"));
btn2.id = "cancelBtn";
btn2.appendChild(d.createTextNode(ALERT_BUTTON_CANCEL));
btn2.href = "#";
// set up the onclick event to remove the alert when the anchor is clicked
btn2.onclick = function() { removeCustomAlert(); return false; }
}
}
}
// removes the custom alert from the DOM
function removeCustomAlert() {
document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
if(delall=="yes"){
makeRequest("store_ajax.php?mo=showcart","showcart");
delall = "";
}
if(!wait && (para=="addcart" || para=="delcart")){
makeRequest("store_ajax.php?mo=showcart","showcart");
}
}
// showimage
function showimage(path) {
// shortcut reference to the document object
d = document;
// if the modalContainer object already exists in the DOM, bail out.
if(d.getElementById("modalContainer")) return;
// create the modalContainer div as a child of the BODY element
mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
mObj.id = "modalContainer";
// make sure its as tall as it needs to be to overlay all the content on the page
mObj.style.height = (document.documentElement.scrollHeight +330) + "px";
// create the DIV that will be the show
showObj = mObj.appendChild(d.createElement("div"));
showObj.id = "showBox";
showObj.align = "center";
// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
if(d.all && !window.opera) showObj.style.top = document.documentElement.scrollTop + "px";
// center the show box
showObj.style.left = (d.documentElement.scrollWidth - showObj.offsetWidth)/2 + "px";
showObj.style.top = document.body.scrollTop + "px";
// create a image element to contain the txt argument
simg = showObj.appendChild(d.createElement("img"));
simg.src = path;
//simg.border = "1";
sbr = showObj.appendChild(d.createElement("br"));
// create an anchor element to use as the confirmation button.
btn = showObj.appendChild(d.createElement("a"));
btn.id = "closeBtn";
btn.appendChild(d.createTextNode("Close"));
btn.href = "#";
// set up the onclick event to remove the alert when the anchor is clicked
btn.onclick = function() { removeCustomAlert();return false; }
}
function createQuery(form)
{
var elements = form.elements;
var pairs = new Array();
for (var i = 0; i < elements.length; i++) {
if ((name = elements[i].name) && (value = elements[i].value))
pairs.push(name + "=" + encodeURIComponent(value));
}
return pairs.join("&");
}
function checkoutform(){
if(document.all.name.value==''){
alert('نام و نام خانوادگی را وارد کنید');
document.all.name.focus();
}else if(document.all.tel.value==''){
alert('تلفن و یا موبایل را وارد کنید');
document.all.tel.focus();
}else if(document.all.city.value==''){
alert('نام شهر را وارد کنید');
document.all.city.focus();
}else if(document.all.address.value==''){
alert('آدرس کامل پستی را وارد کنید');
document.all.address.focus();
}else{
return true;
}
return false;
}
function sendtofriendform(){
if(document.all.name.value==''){
alert('نام و نام خانوادگی خود را وارد کنيد');
document.all.name.focus();
}else if(document.all.email.value==''){
alert('آدرس ايميل خود را وارد کنيد');
document.all.email.focus();
}else if(document.all.namefriend.value==''){
alert('نام و نام خانوادگی دوست خود را وارد کنيد');
document.all.namefriend.focus();
}else if(document.all.emailfriend.value==''){
alert('آدرس ايميل دوست خود را وارد کنيد');
document.all.emailfriend.focus();
}else{
return true;
}
return false;
}
function updatepayment(count,kind){
document.all.shippingtotal.value = count;
document.all.totaltotal.value = eval(document.all.shippingtotal.value) + eval(document.all.ordertotal.value);
document.all.shipping.value=kind;
if(kind=='motor'){
document.all.ppayment[0].disabled=false;
document.all.ppayment[0].checked=true;
document.all.ppayment[1].disabled=true;
document.all.insideguide.style.display='block';
document.all.bankguide.style.display='none';
document.all.payment.value='insite';
}
if(kind=='post'){
document.all.ppayment[1].disabled=false;
document.all.ppayment[1].checked=true;
document.all.ppayment[0].disabled=true;
document.all.insideguide.style.display='none';
document.all.bankguide.style.display='block';
document.all.payment.value='bank';
}
if(kind=='ems'){
document.all.ppayment[1].disabled=false;
document.all.ppayment[1].checked=true;
document.all.ppayment[0].disabled=true;
document.all.insideguide.style.display='none';
document.all.bankguide.style.display='block';
document.all.payment.value='bank';
}
}