﻿function showhidetable(dObject) {
    var str = (dObject.id).replace("_", "tbl")
    switch (dObject.value) {
        case 'بلي': 
            {
                showElementByID(str);
                break;
            }
        case 'خير': 
            {
                hideElementByID(str);
                break;
            }
        default:
            break;
    }
}

function HaghighiHoghughi(dObject) {
    switch (dObject.value) {
        case 'آقاي':
            {
                showElementByID('tblHaghighi');
                setClassForTable('tblHaghighi', 'Req');
                setClassForTable('tblhoghughi', '');
                hideElementByID('tblhoghughi');
                break;
            }
        case 'خانم':
            {
                showElementByID('tblHaghighi');
                setClassForTable('tblHaghighi', 'Req');
                setClassForTable('tblhoghughi', '');
                hideElementByID('tblhoghughi');

                break;
            }
        case 'شركت':
            {
                showElementByID('tblhoghughi');
                setClassForTable('tblhoghughi', 'Req');
                setClassForTable('tblHaghighi', '');
                hideElementByID('tblHaghighi');
                break;
            }
        default:
            break;
    }
}


function HasClass(el,cl){
    if((el.className===null)||(typeof el=='undefined')) return false;
    var classes=el.className.split(' ');
    for(j in classes){
        if(classes[j]==cl) return true;
    }
    return false;
}
var obj2= document.getElementsByName("_sarparastYaOzv");
//validateForm
function checkempty()
{
  var returnval=true     //by default, allow form submission
    for (i=0; i<document.form1.elements.length; i++)
    {
        if( (document.form1.elements[i].type=="text" 
            || document.form1.elements[i].type=="textarea")&& HasClass(document.form1.elements[i],'Req') && document.form1.elements[i].style.visibility!="hidden")
        {
           if (document.form1.elements[i].value=="")
           { //if empty field
             alert("لطفا اطلاعات را به صورت كامل پر كنيد.") //alert error message
             document.form1.elements[i].focus();
             document.form1.elements[i].style.backgroundColor='yellow'; 
             returnval=false; //disallow form submission
             return returnval;
             break; //end loop. No need to continue.
           }
         }
         if(document.form1.elements[i].type=="select-one" && 
            HasClass(document.form1.elements[i],'Req')
            && (document.form1.elements[i].value == "" || document.form1.elements[i].value == "انتخاب كنيد" ))
         {
             alert("يك گزينه را انتخاب كنيد.") //alert error message
             //document.form1.getElementByName("_ostanF").focus();
             document.form1.elements[i].style.backgroundColor='yellow'; 
             returnval=false; //disallow form submission
             return returnval;
             break; //end loop. No need to continue.
         }
   }         
   return returnval;
}
function checkNumber(contents) {
    if (((contents.value / contents.value) != 1) && (contents.value != 0)) 
    {
        alert('لطفا فقط عدد تايپ كنيد.');
        contents.focus();
        return;
    }
}

function hideElementByID(id)
{
    document.getElementById(id).className="hidden"
}
function showElementByID(id)
{
    document.getElementById(id).className="shown"
}
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=400,height=500,left = 540,top = 362');");
}

function setClassForTable(tablename, properclass) {
    for (i = 0; i < document.getElementById(tablename).getElementsByTagName('INPUT').length; i++) {
        document.getElementById(tablename).getElementsByTagName('INPUT')[i].className = properclass;
    }
    for (i = 0; i < document.getElementById(tablename).getElementsByTagName('OPTION').length; i++) {
        document.getElementById(tablename).getElementsByTagName('OPTION')[i].className = properclass;
    } 
      
}