function SetLoginSource(Source){document.getElementById('LoginSource').value=Source;}
function UpdateUIHeaderRows(Source){var AccountLablesRow=document.getElementById("AccountLablesRow");var AccountInputsRow=document.getElementById("AccountInputsRow");var TelInputsRow=document.getElementById("TelInputsRow");var TelLabelsRow=document.getElementById("TelLabelsRow");if(Source=="Account"){AccountLablesRow.style.display='';AccountInputsRow.style.display='';TelLabelsRow.style.display='none';TelInputsRow.style.display='none';}
else{AccountLablesRow.style.display='none';AccountInputsRow.style.display='none';TelLabelsRow.style.display='';TelInputsRow.style.display='';}}
function SubmitFormOnEnter(formName){if(event.keyCode==13){document.forms[formName].submit();}}
function IsUserLoggedWithAccount(){if(document.getElementById('LoginSource')==null){return false;}
else{if(document.getElementById('LoginSource').value=="Account")return true;else return false;}}
function TotalAmountChecked(){var ns6=(document.getElementById&&(!document.all))?true:false;var ns4=(document.layers)?true:false;var ie4=(document.all)?true:false;flag=1;if(ns6){var total=0.0;index=0;var objInvoices=document.BillPayment.CheckBox_Invoices;if(!objInvoices)objInvoices=document.BillPayment.InvAmount;if(!(objInvoices)){total=-1;return total;}
if(isNaN(objInvoices.length)){GetInvoice(objInvoices.value,objInvoices.title).checked=objInvoices.checked;if(objInvoices.checked==true){total+=GetInvoice(objInvoices.value,objInvoices.title).Amount;flag=0;}}
else{check_num=objInvoices.length;while(index<check_num){GetInvoice(objInvoices[index].value,objInvoices[index].title).checked=objInvoices[index].checked;flag=0;if(objInvoices[index].checked==true){total+=Invoices[index].Amount;}
index++;}}
if(flag==1){total=0;}
document.BillPayment.SelectedInvoices.value=Serialize(Invoices);return total;}
else if(ns4){var total=0.0;index=0;var objInvoices=document.BillPayment.CheckBox_Invoices;if(!objInvoices)objInvoices=document.BillPayment.InvAmount;if(!(objInvoices)){total=-1;return total;}
if(isNaN(objInvoices.length)){if(objInvoices.checked==true){total+=parseFloat(objInvoices.value);flag=0;}}
else{check_num=objInvoices.length;while(index<check_num){flag=0;if(objInvoices[index].checked==true)total+=parseFloat(objInvoices[index].value);index++;}}
if(flag==1){total=0;}
return total;}
else if(ie4){var total=0.0;index=0;var objInvoices=document.BillPayment.CheckBox_Invoices;if(!objInvoices)objInvoices=document.BillPayment.InvAmount;if(!(objInvoices)){total=-1;return total;}
if(isNaN(objInvoices.length)){GetInvoice(objInvoices.value,objInvoices.title).checked=objInvoices.checked;if(objInvoices.checked==true){total+=GetInvoice(objInvoices.value,objInvoices.title).Amount;flag=0;}}
else{check_num=objInvoices.length;while(index<check_num){GetInvoice(objInvoices[index].value,objInvoices[index].title).checked=objInvoices[index].checked;flag=0;if(objInvoices[index].checked==true){total+=Invoices[index].Amount;}
index++;}}
if(flag==1){total=0;}
document.BillPayment.SelectedInvoices.value=Serialize(Invoices);return total;}}
function CalculateAmount(){var ns6=(document.getElementById&&(!document.all))?true:false;var ns4=(document.layers)?true:false;var ie4=(document.all)?true:false;if(ns6){var osTotalInvoices=Object(document.getElementById("TotalInvoices"));var osEPayFees=Object(document.getElementById("EPayFees"));var strTemp="";if(osTotalInvoices!=null){var total=TotalAmountChecked();InternetFee=total;total=Math.round(total*100)/100;InternetFee=Math.round(InternetFee*100)/100;strInternetFee=String(InternetFee);strTotal=String(total);if(total>0){nIndex=strTotal.indexOf(".");if(nIndex>0){if(osTotalInvoices!=null){strTotal=strTotal.slice(0,nIndex+3);strTemp=strTotal;strTemp='<layer id="lTotalInvoices" left="804" top="834" width="189">'+strTemp+'</layer>';osTotalInvoices.innerHTML=strTemp;document.forms['BillPayment']['TotalAmount'].value=parseFloat(strTotal);}
if(osEPayFees!=null){strTemp=strInternetFee.slice(0,nIndex+3);strTemp='<layer id="lEPayFees" left="804" top="814" width="189">'+strTemp+'</layer>';osEPayFees.innerHTML=strTemp;}}
else{if(osTotalInvoices!=null){strTemp=strTotal;strTemp='<layer id="lTotalInvoices" left="804" top="834" width="189">'+strTemp+'</layer>';osTotalInvoices.innerHTML=strTemp;document.forms['BillPayment']['TotalAmount'].value=parseFloat(strTotal);}
if(osEPayFees!=null){strTemp=strInternetFee;strTemp='<layer id="lEPayFees" left="804" top="814" width="189">'+strTemp+'</layer>';osEPayFees.innerHTML=strTemp;}}}
else{if(osTotalInvoices!=null){strTemp="--";strTemp='<layer id="lTotalInvoices" left="804" top="834" width="189">'+strTemp+'</layer>';osTotalInvoices.innerHTML=strTemp;document.forms['BillPayment']['TotalAmount'].value=parseFloat("0");}
if(osEPayFees!=null){strTemp="0";strTemp='<layer id="lEPayFees" left="804" top="814" width="189">'+strTemp+'</layer>';osEPayFees.innerHTML=strTemp;}}}}
else if(ns4){var olTotalInvoices=Object(document.lTotalInvoices);var olEPayFees=Object(document.lEPayFees);var oDummyImg1=Object(document.DummyImg1);var oDummyImg2=Object(document.DummyImg2);if(olTotalInvoices!=null){var total=TotalAmountChecked();InternetFee=total;total=Math.round(total*100)/100;InternetFee=Math.round(InternetFee*100)/100;strInternetFee=""+InternetFee;strTotal=""+total;if(total>0){nIndex=strTotal.indexOf(".");if(nIndex>0){if(olTotalInvoices!=null){olTotalInvoices.document.open();olTotalInvoices.left=oDummyImg2.x-24;olTotalInvoices.top=oDummyImg2.y-8;olTotalInvoices.document.write(strTotal.slice(0,nIndex+3));olTotalInvoices.document.close();document.forms['BillPayment']['TotalAmount'].value=strTotal.slice(0,nIndex+3);}
if(olEPayFees!=null){olEPayFees.document.open();olEPayFees.left=oDummyImg1.x-24;olEPayFees.top=oDummyImg1.y;olEPayFees.document.write(strInternetFee.slice(0,nIndex+3));olEPayFees.document.close();}}
else{if(olTotalInvoices!=null){olTotalInvoices.document.open();olTotalInvoices.left=oDummyImg2.x-24;olTotalInvoices.top=oDummyImg2.y-8;olTotalInvoices.document.write(strTotal);olTotalInvoices.document.close();document.forms['BillPayment']['TotalAmount'].value=strTotal;}
if(olEPayFees!=null){olEPayFees.document.open();olEPayFees.left=oDummyImg1.x-24;olEPayFees.top=oDummyImg1.y;olEPayFees.document.write(strInternetFee);olEPayFees.document.close();}}}
else{if(olTotalInvoices!=null){olTotalInvoices.document.open();olTotalInvoices.left=oDummyImg2.x;olTotalInvoices.top=oDummyImg2.y-8;olTotalInvoices.document.write("--");olTotalInvoices.document.close();document.forms['BillPayment']['TotalAmount'].value="0";}
if(olEPayFees!=null){olEPayFees.document.open();olEPayFees.left=oDummyImg1.x;olEPayFees.top=oDummyImg1.y;olEPayFees.document.write("0");olEPayFees.document.close();}}}}
else if(ie4){if(document.all("TotalInvoices")!=null){var total=TotalAmountChecked();InternetFee=total;total=Math.round(total*100)/100;InternetFee=Math.round(InternetFee*100)/100;strInternetFee=""+InternetFee;strTotal=""+total;if(total>0){nIndex=strTotal.indexOf(".");if(nIndex>0){if(document.all("TotalInvoices")!=null){document.all("TotalInvoices").innerText=strTotal.slice(0,nIndex+3);document.all("TotalAmount").value=strTotal.slice(0,nIndex+3);}
if(document.all("EPayFees")!=null){document.all("EPayFees").innerText=strInternetFee.slice(0,nIndex+3);}}
else{if(document.all("TotalInvoices")!=null){document.all("TotalInvoices").innerText=strTotal
document.all("TotalAmount").value=strTotal}
if(document.all("EPayFees")!=null){document.all("EPayFees").innerText=strInternetFee;}}}
else{if(document.all("TotalInvoices")!=null)document.all("TotalInvoices").innerText="--";document.all("TotalAmount").value="0"
if(document.all("EPayFees")!=null){document.all("EPayFees").innerText=0;}}}}}
function payClicked(){var ns6=(document.getElementById&&(!document.all))?true:false;var ns4=(document.layers)?true:false;var ie4=(document.all)?true:false;if(ns6)var oTotalInvoices=Object(document.getElementById("TotalInvoices"));else if(ns4)var oTotalInvoices=Object(document.lTotalInvoices);else if(ie4)var oTotalInvoices=Object(document.all("TotalInvoices"));var bMinimumCheckBox=false;if(document.BillPayment.CheckBox_Invoices==null){alert("لا توجد فاتورة حاليا للسداد");return;}
if(isNaN(document.BillPayment.CheckBox_Invoices.length)){var oCheckBox=document.BillPayment.CheckBox_Invoices;GetInvoice(oCheckBox.value,oCheckBox.title).checked=oCheckBox.checked;if(oCheckBox.checked==true)bMinimumCheckBox=true;}
else{for(j=0;j<=document.BillPayment.CheckBox_Invoices.length-1;j++){var oCheckBox=document.BillPayment.CheckBox_Invoices[j];GetInvoice(oCheckBox.value,oCheckBox.title).checked=oCheckBox.checked;if(oCheckBox.checked==true)bMinimumCheckBox=true;}}
if(bMinimumCheckBox==true){try{document.BillPayment.SelectedInvoices.value=Serialize(Invoices.filter(CheckedInvoices));}
catch(e){document.BillPayment.SelectedInvoices.value=Serialize(Invoices);}
document.forms.BillPayment.action="Payment.aspx";document.forms.BillPayment.submit();return;}
else{if(Invoices.length<1){alert("لا توجد فاتورة حاليا للسداد");}
else alert("يجب اختيار فاتورة لدفعها");return;}}
function showBillClicked(){alert("Refresh the data below...");}
function detailsClicked(){location.href="customer_sign_in_details.aspx";}
function submitClickedNew(source){if(source=="TelNo"){if(!checkForm())return;}
if(source=="ACCREF"){if(!checkFormACCREF())return;}
if(document.BILL_REQ.NewTelNo){document.BILL_REQ.NewTelNo.value="NewTelNo";}
document.BILL_REQ.action="customer_bill_status.aspx?New=1&From="+source;document.BILL_REQ.method="post";document.BILL_REQ.submit();}
function submitClicked(){if(checkForm()){if(document.BILL_REQ.NewTelNo){document.BILL_REQ.NewTelNo.value="NewTelNo";}
document.BILL_REQ.action="customer_bill_status.aspx?New=1";document.BILL_REQ.method="post";document.BILL_REQ.submit();}}
function PINsubmitClicked(nDest){var ValidPIN=/^\d{4}$/;varStr="من فضلك\n";if(document.BILL_REQ.PIN_Code.value==""||(!(ValidPIN.test(document.BILL_REQ.PIN_Code.value)))){varStr=varStr+"\nأدخل كود سري صحيح، مكون من 4 أرقام";alert(varStr);}
else{if(nDest==0)document.BILL_REQ.action="Customer_Bill_Pin.aspx?Dest=0&Save=true";else if(nDest==1)document.BILL_REQ.action="history.aspx";else if(nDest==2)document.BILL_REQ.action="int_history.aspx";else if(nDest==3)document.BILL_REQ.action="epay_trans.aspx";else if(nDest==4)document.BILL_REQ.action="Payment.aspx";else if(nDest==5)document.BILL_REQ.action="Customer_Average_Invoices.aspx?Dest=5&Save=true";else if(nDest==6)document.BILL_REQ.action="Customer_Bill_Pin.aspx?Dest=0&Save=true&isAccount=1";document.BILL_REQ.method="post";document.BILL_REQ.submit();}}
function checkForm(){varStr="من فضلك\n";if(document.BILL_REQ.AreaCode.value==""){varStr=varStr+"\nأدخل كود المنطقة"}
if(document.BILL_REQ.TelNo.value==""){varStr=varStr+"\nأدخل رقم التليفون"}
if(document.BILL_REQ.AreaCode.value.toString().length>3){varStr=varStr+"\nكود المنطقة يجب أن يكون أقصر من 3 أرقام"}
if(document.BILL_REQ.TelNo.value.toString().length>document.BILL_REQ.TelNo.maxlength){varStr=varStr+"\nرقم التليفون يجب أن يكون أقصر من "+document.BIL_REQ.TelNo.maxlength+" أرقام"}
if(document.BILL_REQ.TelNo.value.toString().indexOf(" ")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf(".")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf("-")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.TelNo.value.toString())){varStr=varStr+"\nأدخل رقم تليفون صحيح"}
if(document.BILL_REQ.AreaCode.value.toString().indexOf(" ")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf(".")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf("-")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.AreaCode.value.toString())){varStr=varStr+"\nأدخل كود مدينة صحيح"}
if(varStr!="من فضلك\n"){alert(varStr);return false;}
else{return true;}}
function checkFormACCREF(){varStr="من فضلك\n";if(document.BILL_REQ.ACCREF.value.toString()==""){varStr=varStr+"\nأدخل رقم الحساب "}
if(document.BILL_REQ.ACCREF.value.toString().indexOf(" ")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf(".")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf("-")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.ACCREF.value.toString())){varStr=varStr+"\nأدخل رقم حساب صحيح"}
if(varStr!="من فضلك\n"){alert(varStr);return false;}
else{return true;}}
function closeClicked(){window.parent.location.href="Customer_Bill_Inquiry.aspx";}
function closeClicked2(){window.close();}
function confirmClicked(){document.BM.action="epay_trans.aspx"
document.BM.method="post";document.BM.submit();}
function confirmCloseClicked(){history.back();}
function outClicked(varAC,varTN,varSession){document.epay_trans.action="customer_bill_status.aspx";document.epay_trans.AreaCode.value=varAC;document.epay_trans.TelNo.value=varTN;document.epay_trans.Session.value=varSession;document.epay_trans.method="post";document.epay_trans.submit();}
function ChangeImage(strImageName,strNewSrc){document.images[strImageName].src=strNewSrc;}
function Open(url,h,w){window.open(url,null,"height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,resizable=yes");}
function Open2(url,w,h){window.open(url,null,"height="+h+",width="+w+",status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes,top=20,left=20");}
function Open3(url,h,w){window.open(url,null,"height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,top=20,left=20");}
function changePIN(){varStr="من فضلك\n";var ValidPIN=/^\d{4}$/;varStr="من فضلك\n";if(!(ValidPIN.test(document.Change.OldPINCode.value))){varStr=varStr+"\nأدخل كود سري قديم صحيح، مكون من 4 أرقام"}
if(!(ValidPIN.test(document.Change.NewPINCode.value))){varStr=varStr+"\nأدخل كود سري جديد صحيح، مكون من 4 أرقام"}
if(!(ValidPIN.test(document.Change.ConfirmPINCode.value))){varStr=varStr+"\nأدخل تأكيد كود سري صحيح، مكون من 4 أرقام"}
if(document.Change.NewPINCode.value!=document.Change.ConfirmPINCode.value){varStr=varStr+"\nأدخل كود سري و تأكيد كود سري متماثلين"}
if(varStr!="من فضلك\n"){alert(varStr);document.Change.action='ChangeYourPinCode.aspx';document.Change.submit();}
else{document.Change.action='ChangeYourPinCode.aspx?Save=true';document.Change.submit();}}
function changePINEmail(){var ValidPIN=/^\d{6}$/;var ValidEmail=/^[A-Za-z0-9_-]+[.]?[A-Za-z0-9_-]+[@][A-Za-z0-9_-]+[.][A-Za-z0-9_-]+[.]?[A-Za-z0-9_-]+$/;varStr="من فضلك\n";if(!(ValidPIN.test(document.Change.PINCode.value))){varStr=varStr+"\nأدخل كود سري صحيح، مكون من 6 أرقام"}
if((!(ValidEmail.test(document.Change.Email.value)))||document.Change.Email.length>100){varStr=varStr+"\nأدخل عنوان بريد إلكتروني صحيح"}
if(varStr!="من فضلك\n"){alert(varStr);}
else{document.Change.action='ChangePinEmail_save.aspx';document.Change.submit();}}
function sendPINEmail(){document.Forgot.action='ForgotYourPinCode_save.aspx';document.Forgot.submit();}
function BackToCustomerBillStatus(){document.BM.action="customer_bill_status.aspx"
document.BM.submit();}
function ChangePinCode(){document.BILL_REQ.action='ChangePinCode.aspx';document.BILL_REQ.method="post";document.BILL_REQ.submit();}
function GetQueryStringParams(){var args=new Object();var query=location.search.substring(1);var pairs=query.split("&");for(var i=0;i<pairs.length;i++){var pos=pairs[i].indexOf('=');if(pos==-1)continue;var argname=pairs[i].substring(0,pos);var value=pairs[i].substring(pos+1);args[argname]=unescape(value);}
return args;}
function SubmitToPage(varForm,varPage){if(document.myform){if(document.myform.NewTelNo){document.myform.NewTelNo.value="NewTelNo";}}
var args=new Object();args=GetQueryStringParams();document.getElementById(varForm).action=varPage+"?New=1&From="+args["From"];document.getElementById(varForm).method="post";document.getElementById(varForm).submit();}
function SetInvoicesNum(SelectedNum,InvoicesNum){if(InvoicesNum!=0){if(eval(SelectedNum)==eval(InvoicesNum)){document.myform.InvoicesNum.selected=true;}}}
function SelectInvoiceNum(InvoicesNum){if(InvoicesNum!=0){document.myform.InvoicesNum.value=InvoicesNum;}}
function ValidateAverageInvoices(){var source=checkFormAverageInvoices();if(source=="NotValid")return;else{if(document.myform.NewTelNo){document.myform.NewTelNo.value="NewTelNo";}
document.myform.action="Customer_Average_Invoices.aspx?New=1&From="+source;document.myform.method="post";document.myform.submit();}}
function AddToShopCartClicked(){var ns6=(document.getElementById&&(!document.all))?true:false;var ns4=(document.layers)?true:false;var ie4=(document.all)?true:false;if(ns6)var oTotalInvoices=Object(document.getElementById("TotalInvoices"));else if(ns4)var oTotalInvoices=Object(document.lTotalInvoices);else if(ie4)var oTotalInvoices=Object(document.all("TotalInvoices"));var bMinimumCheckBox=false;if(document.BillPayment.CheckBox_Invoices==null){alert("لا توجد فاتورة حاليا للسداد");return;}
if(isNaN(document.BillPayment.CheckBox_Invoices.length)){var oCheckBox=document.BillPayment.CheckBox_Invoices;GetInvoice(oCheckBox.value,oCheckBox.title).checked=oCheckBox.checked;if(oCheckBox.checked==true)bMinimumCheckBox=true;}
else{for(j=0;j<=document.BillPayment.CheckBox_Invoices.length-1;j++){var oCheckBox=document.BillPayment.CheckBox_Invoices[j];GetInvoice(oCheckBox.value,oCheckBox.title).checked=oCheckBox.checked;if(oCheckBox.checked==true)bMinimumCheckBox=true;}}
if(bMinimumCheckBox==true){try{document.BillPayment.SelectedInvoices.value=Serialize(Invoices.filter(CheckedInvoices));}
catch(e){document.BillPayment.SelectedInvoices.value=Serialize(Invoices);}
document.forms.BillPayment.action="ShoppingCart.aspx";document.forms.BillPayment.submit();return;}
else{if(Invoices.length<1)alert("لا توجد فاتورة حاليا للسداد");else alert("يجب اختيار فاتورة لدفعها");return}
if(oTotalInvoices!=null){total=TotalAmountChecked();var objInvoices=document.BillPayment.CheckBox_Invoices;if(!objInvoices)objInvoices=document.BillPayment.InvAmount;if(total>0){document.BillPayment.CheckedInv.value='';if(isNaN(objInvoices.length)){if(objInvoices.checked){document.BillPayment.CheckedInv.value='0';}}
else{whichElem='first';for(i=0;i<=objInvoices.length-1;i++){if(objInvoices[i].checked){if(whichElem=='first'){document.BillPayment.CheckedInv.value=i;whichElem='not-first';}
else{document.BillPayment.CheckedInv.value=document.BillPayment.CheckedInv.value+','+i;}}}}
document.forms.BillPayment.action="ShoppingCart.aspx";document.forms.BillPayment.submit();}
else{if(total==0)alert("يجب اختيار فاتورة لدفعها");if(total==-1)alert("لا توجد فاتورة حاليا للسداد");}}
else{document.forms.BillPayment.action="ShoppingCart.aspx";document.forms.BillPayment.submit();}}
function ShopCartPayClicked(){var ns6=(document.getElementById&&(!document.all))?true:false;var ns4=(document.layers)?true:false;var ie4=(document.all)?true:false;if(ns6)var oTotalInvoices=Object(document.getElementById("TotalInvoices"));else if(ns4)var oTotalInvoices=Object(document.lTotalInvoices);else if(ie4)var oTotalInvoices=Object(document.all("TotalInvoices"));if(oTotalInvoices!=null){total=TotalAmountChecked();var objInvoices=document.BillPayment.CheckBox_Invoices;if(!objInvoices)objInvoices=document.BillPayment.InvAmount;if(total>0){document.BillPayment.CheckedInv.value='';if(isNaN(objInvoices.length)){if(objInvoices.checked){document.BillPayment.CheckedInv.value='0';}}
else{whichElem='first';for(i=0;i<=objInvoices.length-1;i++){if(objInvoices[i].checked){if(whichElem=='first'){document.BillPayment.CheckedInv.value=i;whichElem='not-first';}
else{document.BillPayment.CheckedInv.value=document.BillPayment.CheckedInv.value+','+i;}}}}
document.forms.BillPayment.action="ShoppingCartPayment.aspx";document.forms.BillPayment.submit();}
else{if(total==0)alert("يجب اختيار فاتورة لدفعها");if(total==-1)alert("لا توجد فاتورة حاليا للسداد");}}
else{document.forms.BillPayment.action="ShoppingCartPayment.aspx";document.forms.BillPayment.submit();}}
function ShopCartPayClicked2(){total=TotalAmountChecked();if(total<=0){document.forms.BillPayment.method="post";document.forms.BillPayment.action="ShoppingCartPayment.aspx?GetAll=1";document.forms.BillPayment.submit();}
else{AddToShopCartClicked()}}
function ShopCartConfirmClicked(){document.BM.action="EPay_Trans.aspx"
document.BM.submit();}
function ShopCartBackClicked(){var ns6=(document.getElementById&&(!document.all))?true:false;var ns4=(document.layers)?true:false;var ie4=(document.all)?true:false;if(ns6)var oTotalInvoices=Object(document.getElementById("TotalInvoices"));else if(ns4)var oTotalInvoices=Object(document.lTotalInvoices);else if(ie4)var oTotalInvoices=Object(document.all("TotalInvoices"));if(oTotalInvoices!=null){var objInvoices=document.BillPayment.CheckBox_Invoices;if(!objInvoices)objInvoices=document.BillPayment.InvAmount;if(objInvoices.length==31){alert('لقد وصلت الى اقصى عدد من الفواتير التى يمكن دفعها فى وقت واحد');return;}
document.BillPayment.CheckedInv.value='';if(isNaN(objInvoices.length)){if(objInvoices.checked){document.BillPayment.CheckedInv.value='0';}}
else{whichElem='first';for(i=0;i<=objInvoices.length-1;i++){if(objInvoices[i].checked){if(whichElem=='first'){document.BillPayment.CheckedInv.value=i;whichElem='not-first';}
else{document.BillPayment.CheckedInv.value=document.BillPayment.CheckedInv.value+','+i;}}}}
document.forms.BillPayment.action="ShoppingCart_Submit.aspx";document.forms.BillPayment.submit();}
else{document.forms.BillPayment.action="ShoppingCart_Submit.aspx";document.forms.BillPayment.submit();}}
function BuildPage(){var oXML=new ActiveXObject("Microsoft.XMLDOM")
oXML.async="false"
oXML.loadXML(xmlData.xml);var oXSL=new ActiveXObject("Microsoft.XMLDOM")
oXSL.async="false"
oXSL.loadXML(objXSL.xml);var Result=oXML.transformNode(oXSL.documentElement);document.getElementById("ContentDiv").innerHTML=Result;}
function Invoice(Inv_Id,Tel_No,Inv_Date,Inv_Type,SubTotal,Penalty,Amount,checked,ACCREF){this.Inv_Id=Inv_Id;this.Tel_No=Tel_No;this.Inv_Date=Inv_Date;this.Inv_Type=Inv_Type;this.SubTotal=SubTotal;this.Penalty=Penalty;this.Amount=Amount;this.ACCREF=ACCREF;this.checked=checked;}
function CheckedInvoices(element,index,array){return element.checked;}
function Serialize(oInvoices){var strSerializedDate="";for(i=0;i<oInvoices.length;i++){if(oInvoices[i].checked==true){strSerializedDate+=oInvoices[i].Tel_No+','+oInvoices[i].Inv_Date+','+oInvoices[i].Inv_Type+','+oInvoices[i].SubTotal+','+oInvoices[i].Penalty+','+oInvoices[i].Amount+','+oInvoices[i].ACCREF;if(i<oInvoices.length-1)strSerializedDate+=";";}}
return strSerializedDate;}
function GetInvoice(inv_id){for(i=0;i<Invoices.length;i++){if(Invoices[i].Inv_Date==inv_id){return Invoices[i];}}
return 0;}
function GetInvoice(inv_id,Type){for(i=0;i<Invoices.length;i++){var invTitle=Invoices[i].Inv_Date+"-"+Invoices[i].Tel_No
if(invTitle==inv_id&&Invoices[i].Inv_Type==Type){return Invoices[i];}}
return 0;}
function CalculateAmount2(){var TotalToPaid=0;if(isNaN(document.BillPayment.CheckBox_Invoices.length)){var inv=GetInvoice(document.BillPayment.CheckBox_Invoices.value,document.BillPayment.CheckBox_Invoices.title);if(document.BillPayment.CheckBox_Invoices.checked==true){TotalToPaid+=GetInvoice(document.BillPayment.CheckBox_Invoices.value,document.BillPayment.CheckBox_Invoices.title).Amount;}}
else{for(j=0;j<document.BillPayment.CheckBox_Invoices.length;j++){var inv=GetInvoice(document.BillPayment.CheckBox_Invoices[j].value,document.BillPayment.CheckBox_Invoices[j].Title);if(document.BillPayment.CheckBox_Invoices[j].checked==true){inv=GetInvoice(document.BillPayment.CheckBox_Invoices[j].value,document.BillPayment.CheckBox_Invoices[j].title);TotalToPaid+=inv.Amount;}}}
if(TotalToPaid>0)document.getElementById("TotalInvoices").innerHTML='<layer id="lTotalInvoices" width="189" top="834" left="804">'+TotalToPaid.toFixed(2)+'</layer>'
else document.getElementById("TotalInvoices").innerHTML='<layer id="lTotalInvoices" width="189" top="834" left="804">--</layer>'}
function checkFormAverageInvoices(){var AccountVisible=false;if(IsUserLoggedWithAccount())AccountVisible=true;var AccountAlert="من فضلك\n";var TelAlert="من فضلك\n";var AccountValid=true;var TelValid=true;if(AccountVisible==true){if(document.myform.ACCREF.value==""){AccountAlert=AccountAlert+"\nأدخل رقم الحساب ";AccountValid=false;}
else if(document.myform.ACCREF.value.toString().indexOf(" ")!=-1||document.myform.ACCREF.value.toString().indexOf(".")!=-1||document.myform.ACCREF.value.toString().indexOf("-")!=-1||document.myform.ACCREF.value.toString().indexOf("+")!=-1){AccountAlert=AccountAlert+"\nأدخل رقم حساب صحيح"
AccountValid=false;}}
if(AccountAlert!="من فضلك\n"||AccountVisible==false){if(document.myform.AreaCode.value==""){TelAlert=TelAlert+"\nأدخل كود المنطقة";TelValid=false;}
if(document.myform.TelNo.value==""){TelAlert=TelAlert+"\nأدخل رقم التليفون";TelValid=false;}
if(document.myform.AreaCode.value.toString().length>3){TelAlert=TelAlert+"\nكود المنطقة يجب أن يكون أقصر من 3 أرقام";TelValid=false;}
if(document.myform.TelNo.value.toString().length>8){TelAlert=TelAlert+"\nرقم التليفون يجب أن يكون أقصر من 8 أرقام";TelValid=false;}
if(document.myform.TelNo.value.toString().length>document.myform.TelNo.maxlength){TelAlert=TelAlert+"\nرقم التليفون يجب أن يكون أقصر من "+document.BIL_REQ.TelNo.maxlength+" أرقام";TelValid=false;}
if(document.myform.TelNo.value.toString().indexOf(" ")!=-1||document.myform.TelNo.value.toString().indexOf(".")!=-1||document.myform.TelNo.value.toString().indexOf("-")!=-1||document.myform.TelNo.value.toString().indexOf("+")!=-1||isNaN(document.myform.TelNo.value.toString())){TelAlert=TelAlert+"\nأدخل رقم تليفون صحيح";TelValid=false;}
if(document.myform.AreaCode.value.toString().indexOf(" ")!=-1||document.myform.AreaCode.value.toString().indexOf(".")!=-1||document.myform.AreaCode.value.toString().indexOf("-")!=-1||document.myform.AreaCode.value.toString().indexOf("+")!=-1||isNaN(document.myform.AreaCode.value.toString())){TelAlert=TelAlert+"\nأدخل كود مدينة صحيح";TelValid=false;}}
if(AccountVisible==true&&AccountValid==false&&TelValid==false){alert(AccountAlert);return"NotValid";}
if(AccountVisible==false&&TelValid==false){alert(TelAlert);return"NotValid";}
if(AccountVisible==true&&AccountValid==true)return"ACCREF";else if(TelValid==true)return"TelNo";return"NotValid";}
function SubmitToBillStatus(varForm,varPage){var source=checkFormAverageInvoices();if(source=="NotValid")return;if(document.myform){if(document.myform.NewTelNo){document.myform.NewTelNo.value="NewTelNo";}}
document.getElementById(varForm).action=varPage+"?New=1&From="+source;document.getElementById(varForm).method="post";document.getElementById(varForm).submit();}
function SubmitToAveragePage(varForm,varPage){if(document.myform){if(document.myform.NewTelNo){document.myform.NewTelNo.value="NewTelNo";}}
var source="";var AccountVisible=false;if(IsUserLoggedWithAccount())AccountVisible=true;if(AccountVisible==true&&checkFormACCREF(false)){source="ACCREF"}
else if(checkFormTelephoneNumber(false)){source="TelNo";}
if(source==""){if(AccountVisible==true)checkFormACCREF(true);else checkFormTelephoneNumber(true);return;}
document.getElementById(varForm).action=varPage+"?New=1&From="+source;document.getElementById(varForm).method="post";document.getElementById(varForm).submit();}
function submitClickedNew(){var source="";source="TelNo";var AccountVisible=false;if(IsUserLoggedWithAccount()){AccountVisible=true;source="ACCREF";if(!checkFormACCREF(true)){return;}}
else{if(!checkFormTelephoneNumber(true)){return;}}
if(document.BILL_REQ.NewTelNo){document.BILL_REQ.NewTelNo.value="NewTelNo";}
document.BILL_REQ.action="customer_bill_status.aspx?New=1&From="+source;document.BILL_REQ.method="post";document.BILL_REQ.submit();}
function checkFormTelephoneNumber(showAlert){varStr="Please,\n";if(document.BILL_REQ.AreaCode.value==""){varStr=varStr+"\nenter the area code."}
if(document.BILL_REQ.TelNo.value==""){varStr=varStr+"\nenter the telephone number."}
if(document.BILL_REQ.AreaCode.value.toString().length>3){varStr=varStr+"\nArea code length must be less than 3."}
if(document.BILL_REQ.TelNo.value.toString()>document.BILL_REQ.maxlength){varStr=varStr+"\nTelephone number should be shorter than "+document.BILL_REQ.maxlength}
if(document.BILL_REQ.TelNo.value.toString().indexOf(" ")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf(".")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf("-")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.TelNo.value.toString())){varStr=varStr+"\nenter a valid Telephone Number."}
if(document.BILL_REQ.ACCREF.value.toString().indexOf(" ")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf(".")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf("-")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.ACCREF.value.toString())){varStr=varStr+"\nenter a valid Account Number."}
if(document.BILL_REQ.AreaCode.value.toString().indexOf(" ")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf(".")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf("-")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.AreaCode.value.toString())){varStr=varStr+"\nenter a valid Area Code."}
if(varStr!="Please,\n"){if(showAlert==true)alert(varStr);return false;}
else{return true;}}
function checkFormACCREF(showAlert){varStr="من فضلك\n";if(document.BILL_REQ.ACCREF.value.toString()==""){varStr=varStr+"\nأدخل رقم الحساب "}
else if(document.BILL_REQ.ACCREF.value.toString().indexOf(" ")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf(".")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf("-")!=-1||document.BILL_REQ.ACCREF.value.toString().indexOf("+")!=-1){varStr=varStr+"\nأدخل رقم حساب صحيح"}
if(varStr!="من فضلك\n"){if(showAlert==true)alert(varStr);return false;}
else{return true;}}
function checkFormTelephoneNumber(showAlert){varStr="من فضلك\n";if(document.BILL_REQ.AreaCode.value==""){varStr=varStr+"\nأدخل كود المنطقة"}
if(document.BILL_REQ.TelNo.value==""){varStr=varStr+"\nأدخل رقم التليفون"}
if(document.BILL_REQ.AreaCode.value.toString().length>3){varStr=varStr+"\nكود المنطقة يجب أن يكون أقصر من 3 أرقام"}
if(document.BILL_REQ.TelNo.value.toString().length>document.BILL_REQ.TelNo.maxlength){varStr=varStr+"\nرقم التليفون يجب أن يكون أقصر من "+document.BIL_REQ.TelNo.maxlength+" أرقام"}
if(document.BILL_REQ.TelNo.value.toString().indexOf(" ")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf(".")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf("-")!=-1||document.BILL_REQ.TelNo.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.TelNo.value.toString())){varStr=varStr+"\nأدخل رقم تليفون صحيح"}
if(document.BILL_REQ.AreaCode.value.toString().indexOf(" ")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf(".")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf("-")!=-1||document.BILL_REQ.AreaCode.value.toString().indexOf("+")!=-1||isNaN(document.BILL_REQ.AreaCode.value.toString())){varStr=varStr+"\nأدخل كود مدينة صحيح"}
if(varStr!="من فضلك\n"){if(showAlert==true)alert(varStr);return false;}
else{return true;}}
function submitClickedPopupNew(){document.BILL_REQ.action="Popup_Window.aspx?New=1&From=TelNo";document.BILL_REQ.method="post";document.BILL_REQ.submit();}
function SubmitToAveragePagePopup(varForm,varPage){if(document.myform){if(document.myform.NewTelNo){document.myform.NewTelNo.value="NewTelNo";}}
var source="";source="TelNo";if(IsUserLoggedWithAccount()){source="ACCREF"}
document.getElementById(varForm).action=varPage+"?New=1&From="+source;document.getElementById(varForm).method="post";document.getElementById(varForm).submit();}
function Check(){cShopCartBillsCount=parseInt(document.getElementById('ShopCartBillsCount').value);cMaxNumOfBillsToBePaid=parseInt(document.getElementById('MaxNumOfBillsToBePaid').value);var PaymentMethod=document.getElementById('PaymentMethod');if(PaymentMethod!=null&&PaymentMethod!="undefined"&&PaymentMethod.getAttribute("Value")=="0"&&cShopCartBillsCount>cMaxNumOfBillsToBePaid){alert('في الوقت الحالي يمكنك سداد حتى  '+document.getElementById('MaxNumOfBillsToBePaid').value+' فواتير في المرة الواحدة وذلك عند إختيار طريقة الدفع بكروت الإئتمان');}
else ShopCartConfirmClicked();}
