﻿var globalIntervalRef;
var openedMenuItem=-1;
var hour;
var minute;
var second;
var getOnlyOneTime=false;

function showFarsiNumers(str)
{
    var temp="";
    for(var i=0;i<str.length;i++){
      temp += String.fromCharCode(str.charCodeAt(i)+1728);
    }
    return temp;
}

function updateClock()
{
  var clock=document.getElementById("clockID");
  
  if(clock!=null && !getOnlyOneTime){
    hour=clock.getAttribute("getHour");
    minute=clock.getAttribute("getMinute");
    second=clock.getAttribute("getSecond");
    getOnlyOneTime=true;
  }
  
  second++;
  if(second>59){
    second=0;
    minute++;
  }
  if(minute>59){
    minute=0;
    hour++;
  }
  if(hour>23){
    hour=0;
  }
  
  // Pad the minutes and seconds with leading zeros, if required
  var hourS = (hour < 10 ? "0" : "" ) + hour;
  var minuteS = ( minute < 10 ? "0" : "" ) + minute;
  var secondS = ( second < 10 ? "0" : "" ) + second;

  var currentTimeString = showFarsiNumers(hourS) + ":" + showFarsiNumers(minuteS) + ":" + showFarsiNumers(secondS);
  
  clock.innerHTML = currentTimeString;
}

function updateClockEn()
{
  var clock=document.getElementById("clockID");
  
  if(clock!=null && !getOnlyOneTime){
    hour=clock.getAttribute("getHour");
    minute=clock.getAttribute("getMinute");
    second=clock.getAttribute("getSecond");
    getOnlyOneTime=true;
  }
  
  second++;
  if(second>59){
    second=0;
    minute++;
  }
  if(minute>59){
    minute=0;
    hour++;
  }
  if(hour>23){
    hour=0;
  }
  
  // Pad the minutes and seconds with leading zeros, if required
  var hourS = (hour < 10 ? "0" : "" ) + hour;
  var minuteS = ( minute < 10 ? "0" : "" ) + minute;
  var secondS = ( second < 10 ? "0" : "" ) + second;

  var currentTimeString = hourS + ":" + minuteS + ":" + secondS;
  
  clock.innerHTML = currentTimeString;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function hideAllMenuItems(){
    var i=0;
    var j=0;
    var element=document.getElementById("menuItem_"+i+"_"+j);
    while(element!=null){
        while(element!=null){
            element.style.display="none";
            j++;
            element=document.getElementById("menuItem_"+i+"_"+j);
        }
        j=0;
        i++;
        element=document.getElementById("menuItem_"+i+"_"+j);
    }
}

function efectiveShowMenuItem(itemA,itemB){
    var element=document.getElementById("menuItem_"+itemA+"_"+itemB);
    clearInterval(globalIntervalRef);
    if(element!=null){
        element.style.display="";
        globalIntervalRef=setInterval("efectiveShowMenuItem("+itemA+","+(itemB+1)+");",50);
    }
    else
        clearInterval(globalIntervalRef);
}

function showMenuItem(item){
    hideAllMenuItems();
    //var i=0;
    //var element=document.getElementById("menuItem_"+item+"_"+i);
    if(openedMenuItem==-1 || openedMenuItem!=item){
        openedMenuItem=item;
        efectiveShowMenuItem(item,0);
    }
    else
        openedMenuItem=-1;
    /*while(element!=null){
        for(var j=0;j<1000000;j++)
            i=i;
        element.style.display="";        
        i++;
        element=document.getElementById("menuItem_"+item+"_"+i);
    }*/
}

function editOnMouseEnter(element)
{
    if(element.value==element.attributes["defaultvalue"].value)
    {
        element.value="";
    }
}

function editOnMouseLeave(element)
{
    if(element.value=="")
    {
        element.value=element.attributes["defaultvalue"].value;
    }
}

function gotoAction(act)
{
    var form=document.forms[0];
    form.action=act;
    form.__VIEWSTATE.name = 'NOVIEWSTATE';
    form.submit();
}

function login()
{
    var userName=document.getElementById("editLoginUserName").value;
    var password=document.getElementById("editLoginPassword").value;
    gotoAction("login.aspx?userName="+userName+"&password="+password);
}

function logout()
{
    gotoAction("login.aspx?logout=true");
}

function searchFunc(val)
{
    if(val.length>0)
    {
        gotoAction("search.aspx?searchWord="+val);
    }
}

function checkBeforeSend()
{
    var e1=document.getElementById("editLoginUserName");
    var e2=document.getElementById("editLoginPassword");
    if(e1!=null && e1.value==e1.attributes["defaultvalue"].value)
    {
        e1.value="";
    }
    if(e2!=null && e2.value==e2.attributes["defaultvalue"].value)
    {
        e2.value="";
    }
}

function kolbehSearch(val)
{
    if(val.length>0)
    {
        gotoAction("kolbeh.aspx?searchWord="+val);
    }
}

function hideAllElements(masterID){
  var i=0;
  var element=document.getElementById(masterID+"_"+i);
  while(element!=null){
    element.style.display='none';
    i++;
    element=document.getElementById(masterID+"_"+i);
  }
}

function showHideElement(masterID,id){
  var element=document.getElementById(masterID+"_"+id);
  var b=element.style.display=='';
  hideAllElements(masterID);
  if(!b)
    element.style.display='';
}

function submitToSaman(){
    gotoAction("https://acquirer.sb24.com/CardServices/controller");
}

function hideAllTabs(){
    var i=0;
    var element=document.getElementById('tab'+i);
    while (element!=null){
        element.style.display='none';
        i++;
        element=document.getElementById('tab'+i);
    }
}

function showTab(id,color){
    hideAllTabs();
    var element=document.getElementById(id);
    element.style.display='';
    var element=document.getElementById('tabBody');
    element.style.backgroundColor=color;
}

var lastDegreeSelectedIndex=0;
var payIsOnline=0;
function checkPayClick2(){
  document.getElementById('payment1Section1').style.display='none'; 
  document.getElementById('payment2Section1').style.display='none'; 
  document.getElementById('payment3Section1').style.display='none'; 
  document.getElementById('payment4Section1').style.display='none'; 
  if(lastDegreeSelectedIndex==1 || lastDegreeSelectedIndex==2){
    if(payIsOnline==1){ 
      document.getElementById('payment4Section1').style.display=''; 
    } 
    else{ 
      document.getElementById('payment2Section1').style.display=''; 
    } 
  } 
  else if(lastDegreeSelectedIndex==3){
    if(payIsOnline==1){ 
      document.getElementById('payment3Section1').style.display=''; 
    } 
    else{ 
      document.getElementById('payment1Section1').style.display=''; 
    } 
  } 
}
 
function checkPayClick(dropDown){ 
  lastDegreeSelectedIndex=dropDown.selectedIndex; 
  checkPayClick2(); 
}
 
function checkPayClick3(i){ 
  payIsOnline=i; 
  checkPayClick2(); 
} 
 
function checkPay2Click(i){
  document.getElementById('payment1Section1').style.display='none'; 
  document.getElementById('payment2Section1').style.display='none'; 
  document.getElementById('payment'+i+'Section1').style.display=''; 
}

function registerationSubmit(btn){
    btn.disabled="disabled";
}

function ShowStateDetailOf(n){
    window.location='Kolbeh.aspx?state='+n;
}

