

function validateStudentForm()
{
    var ffourindex = document.studentform.formfourindex;
    var fname = document.studentform.firstname;
    var lname = document.studentform.lastname;
    var rel_Id=document.studentform.religion_Id
    var rel_Id=document.studentform.religion_Id
    var email1=document.studentform.email1
    var email2=document.studentform.email2
    var studentmobileno=document.studentform.studentmobileno;
    var middlename=document.studentform.middlename;
    var studentaddress=document.studentform.studentaddress;
    var design=document.studentform.designation;
    var emeregencename=document.studentform.emeregencename;
    var emergencead=document.studentform.emergenceaddress;
 

   

    
    if (ffourindex.value == "")
    {
        window.alert("Please fill in the Form Four Index Number.");
        ffourindex.focus();
        return false;
    }




    if (fname.value == "")
    {
        window.alert("Please fill the  First Name");
        fname.focus();
        return false;
    }


    if (fname.value.length>15)
    {
        window.alert("Too long  First Name");
        fname.value='';
        fname.focus();
        return false;
    }


    if (middlename.value.length>15)
    {
        window.alert("Too long  Middle Name");
        middlename.value='';
        middlename.focus();
        return false;
    
    }
  
    if (lname.value == "")
    {
        window.alert("Please fill in the Last Name.");
        lname.focus();
        return false;
    }
    if (lname.value.length>15)
    {
        window.alert("Too long  Last Name");
        lname.value='';
        lname.focus();
        return false;
    }


          
    if (email1.value == "")
    {
        window.alert("Please fill in the Email Address.");
        email1.focus();
        return false;
    }

    if (email1.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email1.value='';
        email1.focus();
        return false;
    }

    if (email1.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email1.focus();
        return false;
    }

  
    if (email2.value == "")
    {
        window.alert("Please Re type your Email Address");
        email2.focus();
        return false;
    }
    if (email2.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email2.value='';
        email2.focus();
        return false;
    }

    if (email2.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email1.focus();
        return false;
    }
    
    if (email2.value != email1.value)
    {
        window.alert("Email Adresses Missmatch");
        email1.focus();
        return false;
    }

    if(studentmobileno.value.length>14)
    {
        window.alert("Too long and invalid mobile number");
        studentmobileno.value='';
        studentmobileno.focus();
        return false;
    }


    if (studentaddress.value.length>20)
    {
        window.alert("Too long Address");
        studentaddress.value='';
        studentaddress.focus();
        return false;
    }


    if (design.value.length>20)
    {
        window.alert("Too long Designation");
        design.value='';
        design.focus();
        return false;
    }

    if (emeregencename.value.length>20)
    {
        window.alert("Too long Name");
        design.value='';
        design.focus();
        return false;
    }

    if (emergencead.value.length>20)
    {
        window.alert("Too long addresss");
        emergencead.value='';
        emergencead.focus();
        return false;
    }



    var gender=document.studentform.gender;
    var religion_Id=document.studentform.religion_Id;
    var denomination_Id=document.studentform.denomination_Id;
    var marital_Id=document.studentform.marital_Id;
    var town_Id=document.studentform.town_Id;
    var nationality_Id=document.studentform.nationality_Id;
    var program_Id=document.studentform.program_Id;
    var disability=document.studentform.disability;
    var sponsor_type_id=document.studentform.sponsor_type_id;

    if (gender.value==0)
    {
        window.alert("Please Select your Gender");
   
        gender.focus();
        return false;
    }

    if (religion_Id.value==0)
    {
        window.alert("Specify Your Religion");
        religion_Id.focus();
        return false;
    }

    if (denomination_Id.value==0)
    {
        window.alert("Specify Your Denomination");
        denomination_Id.focus();
        return false;
    }


    if (marital_Id.value==0)
    {
        window.alert("Specify Your Marital Status");
        marital_Id.focus();
        return false;
    }

    if (town_Id.value==0)
        {
            window.alert("Specify your town");
            town_Id.focus();
            return false;

        }

        if (nationality_Id.value==0)
            {
                window.alert("Specify your Nationality");
                nationality_Id.focus();
                return false;
            }

            if (disability.value==0)
                {
                    window.alert("Specify If you are disabled or not");
                    disability.focus();
                    return false;
                }

            if (program_Id.value==0)
                {
                    window.alert("Specify Your Degeree program");
                    program_Id.focus();
                    return false;
                }


                if (sponsor_type_id.value==0)
                    {
                        window.alert("Specify Your Sponsorship Status");
                        sponsor_type_id.focus();
                        return false;
                    }

}










function validateSponsor()
{
    var sponsor_type_id=document.studentform.sponsor_type_id;
    if ((sponsor_type_id.value==1||sponsor_type_id.value==2))
    {
        document.studentform.sponsorname.disabled=true;
        document.studentform.sponsoraddress.disabled=true;
        document.studentform.sponoremail.disabled=true;
        document.studentform.sponsorfax.disabled=true;
        document.studentform.sponsortel.disabled=true;
        document.studentform.sponsorweb.disabled=true;
        document.studentform.sponsormobile.disabled=true;
    }
    else
    {
        document.studentform.sponsorname.disabled=false;
        document.studentform.sponsoraddress.disabled=false;
        document.studentform.sponoremail.disabled=false;
        document.studentform.sponsorfax.disabled=false;
        document.studentform.sponsortel.disabled=false;
        document.studentform.sponsorweb.disabled=false;
        document.studentform.sponsormobile.disabled=false;
    }

}


function validateEmployment()
{
    var employmentstatus=document.studentform.employmentstatus;

    if (employmentstatus.value!='YES')
    {
        document.studentform.designation.disabled=true;
    }
    else
    {
        document.studentform.designation.disabled=false;
    }
}

























function validateInventoryForm()
{
    var order = document.stinventory.order;
    var codeno = document.stinventory.codeno;
    var quantity = document.stinventory.quantity;
    var reorder = document.stinventory.reorder;
    var purchase = document.stinventory.purchase;
    var sell = document.stinventory.selling;
    // var numericExpression = /^[0-9]+$/;
    // var alphaExpression = /^[a-zA-Z]+$/;
    //var alphanumeric    = /^[0-9a-zA-Z]+$/;
    
    if (order.value == "")
    {
        window.alert("Please fill in the order.");
        order.focus();
        return false;
    }
    if (codeno.value == "")
    {
        window.alert("Please fill the  codeno");
        codeno.focus();
        return false;
    } 
    if (quantity.value == "")
    {
        window.alert("Please fill in the quantity.");
        quantity.focus();
        return false;
    }
    if (reorder.value == "")
    {
        window.alert("Please fill in the reorder field.");
        reorder.focus();
        return false;
    }
    if (purchase.value == "")
    {
        window.alert("Please fill in the purchase field.");
        purchase.focus();
        return false;
    }
    if (sell.value == "")
    {
        window.alert("Please fill in the sell field.");
        sell.focus();
        return false;
    }
}



















function validateSupplierxForm(){
    var supplier = document.supplier.supplier;
    var stid  = document.supplier.station_Id;
    var sid = document.supplier.staff_Id;
    if (stid.value == "")
    {
        window.alert("the station id is empty.");
        stid.focus();
        return false;
    }
    if (sid.value == "")
    {
        window.alert("the staff id is empty.");
        sid.focus();
        return false;
    }
    if (supplier.value == "")
    {
        window.alert("Please fill in supplier field.");
        supplier.focus();
        return false;
    }
   
}

function validateSalesOrderForm()
{

    var stid  = document.salesorder.station_Id;
    var sid = document.salesorder.staff_Id;
    var cid  = document.salesorder.customer_Id;
    var order = document.salesorder.order;
    var quantity = document.salesorder.quantity;
    var sell = document.salesorder.selling;
     
    var numericExpression = /^[0-9]+$/;


    if (stid.value == "")
    {
        window.alert("the station id is empty.");
        stid.focus();
        return false;
    }
    if (sid.value == "")
    {
        window.alert("the staff id is empty.");
        sid.focus();
        return false;
    }
    if (sid.value == "")
    {
        window.alert("the staff id is empty.");
        sid.focus();
        return false;
    }
    if (cid.value == "")
    {
        window.alert("the staff id is empty.");
        cid.focus();
        return false;
    }
     
    if (order.value == "")
    {
        window.alert("the order field is empty.");
        order.focus();
        return false;
    }
       
    if (quantity.value == "")
    {
        window.alert("fill in the quantity field .");
        quantity.focus();
        return false;
    }
     
    if (sell.value == "")
    {
        window.alert("fill in the quantity field .");
        sell.focus();
        return false;
    }



    var checkStr = document.studentform.fname;
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length)
        {
            allValid = false;
            break;
        }
        if (ch != ",")
            allNum += ch;
    }
    if (!allValid)
    {
        alert("Please enter only non numeric characters  for the First Name");
        document.clientform.focus();
        return (false);
    }



}

function validateExpenseForm()
{
    var stid  = document.expense.station_Id;
    var sid = document.expense.staff_Id;
    var vorcherno = document.expense.vorcherno;
    var amount= document.expense.amount;
    var numericExpression = /^[0-9]+$/;
     
    if (stid.value == "")
    {
        window.alert("the station id is empty.");
        stid.focus();
        return false;
    }
     
    if (sid.value == "")
    {
        window.alert("the staff id is empty.");
        sid.focus();
        return false;
    }
    if (vorcherno.value == "")
    {
        window.alert("fill in the vorcherno.");
        vorcherno.focus();
        return false;
    }
    if (amount.value == "")
    {
        window.alert("fill in the amount.");
        amount.focus();
        return false;
    }

}

  
function validateReceiverForm()
{
    var stid  = document.receiver.station_id;
    var receiver = document.receiver.receiver;
    if (stid.value == "")
    {
        window.alert("fill in the amount.");
        amount.focus();
        return false;
    }
    if (receiver.value == "")
    {
        window.alert("fill in the reciever.");
        receiver.focus();
        return false;
    }
}


function validateSupplierForm()
{
    var stid  = document.supplier.station_Id;
    var staff  = document.supplier.staff_Id;
    var supplier = document.supplier.supplier_Id;
    var order = document.supplier.order;
    var amount = document.supplier.amount;

    if (stid.value == "")
    {
        window.alert("station id is empty.");
        stid.focus();
        return false;
    }
    if (staff.value == "")
    {
        window.alert("staff id is empty.");
        staff.focus();
        return false;
    }
    if (supplier.value == "")
    {
        window.alert("supplier id empty.");
        supplier.focus();
        return false;
    }
    if (order.value == "")
    {
        window.alert("fill in the order field.");
        order.focus();
        return false;
    }
    if (amount.value == "")
    {
        window.alert("fill in the amount field.");
        amount.focus();
        return false;
    }
}
  
function validateAccountForm()
{
    var stid  = document.account.station_Id;
    var staff  = document.account.staff_Id;
    

    if (stid.value == "")
    {
        window.alert("station id is empty.");
        stid.focus();
        return false;
    }
}
  
function validateSalaryForm()
{
    var user  = document.psalary.user;
    var salary  = document.psalary.salary;


    if (user.value == "")
    {
        window.alert("the staff name is empty.");
        user.focus();
        return false;
    }
    if(salary.value=="")
    {
        window.alert("please fill in th staff salary.");
        salary.focus();
        return false;

    }
}
function validateDeductionForm()
{
    var user  = document.pdeduct.user;
    var deduct  = document.pdeduct.deduct;

    if (user.value == "")
    {
        window.alert("the staff name is empty.");
        user.focus();
        return false;
    }
    if(deduct.value=="")
    {
        window.alert("please fill in the deduction amount.");
        deduct.focus();
        return false;

    }
}
function validateAllowanceForm()
{
      
    var user  = document.pallowance.user;
    var allowance  = document.pallowance.allowance;

    if (user.value == "")
    {
        window.alert("the staff name is empty.");
        user.focus();
        return false;
    }
    if (allowance.value=="")
    {
        window.alert("please fill in the allowance amount.");
        allowance.focus();
        return false;

    }
    

}
function validateAssetForm()
{
    var hist  = document.asset.historical;

    if (hist.value == "")
    {
        window.alert("fill in the historical field.");
        hist.focus();
        return false;
    }
}
function validateReceiveForm()
{
    var order  = document.recievepayment.order;
    var amount  = document.recievepayment.amount;

    if (order.value == "")
    {
        window.alert("fill in the order field.");
        order.focus();
        return false;
    }
    if (amount.value == "")
    {
        window.alert("fill in the amount field");
        amount.focus();
        return false;
    }

}
 
function confirmDelete(delUrl)
{
    if( confirm("Are you sure you want to delete?"))
    {
        document.location=delUrl;
    }
}
function confirmTaxable(delUrl)
{
    if(confirm("Are You  sure you want to set this item as taxable?"))
    {
        document.location = delUrl;
    }
}
function validateCashForm()
{
    var nominal= document.cashform.nominal;
    var accountno =document.cashform.accountno;



    if (nominal.value == "")
    {
        window.alert("fill in the nominal name please");
        nominal.focus();
        return false;
    }

    if (accountno.value == "")
    {
        window.alert("fill in the accountno");
        accountno.focus();
        return false;
    }
}

function  validateNewUser()
{
    var staff_name =document.newuser.staff_name;
    var email =    document.newuser.email;
    var username = document.newuser.username ;
    var password = document.newuser.password;

    if (staff_name.value == "")
    {
        window.alert("fill in the staff name");
        staff_name.focus();
        return false;
    }
    if (username.value == "")
    {
        window.alert("fill in the username");
        username.focus();
        return false;
    }
    if (password.value == "")
    {
        window.alert("fill in the password");
        password.focus();
        return false;
    }

    if (email.value == "")
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    if (email.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    if (email.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

}

function validateStationForm()
{
    var station =document.stationform.station;
    var customer_name =document.stationform.customer_name;
    var username =  document.stationform.username;
    var password =document.stationform.password;
    var email =document.stationform.email;
    if(station.value== "")
    {
        window.alert("fill in the station name.");
        station.focus();
        return false;
    }
    if(customer_name== "")
    {
        window.alert("fill in the customer name.");
        customer_name.focus();
        return false;
    }
    if(username== "")
    {
        window.alert("fill in the username.");
        username.focus();
        return false;
    }
    if(password.value== "")
    {
        window.alert("fill in the password.");
        password.focus();
        return false;
    }
    if (email.value == "")
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    if (email.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    if (email.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

}

function validateClientForm()
{
    var fileno= document.clientform.fileno;
    var cname =document.clientform.cname;
    var cphone=document.clientform.cphone;
    var email = document.clientform.cemail;


    if(fileno.value== "")
    {
        window.alert("please fill in the file No.");
        fileno.focus();
        return false;
    }
    if (cname.value== "")
    {
        window.alert("Please fill in the customer name.");
        return false;
    }
    if(cphone.value=="")
    {
        window.alert("please fill in the phone no.");
        return false;
    }

    if (email.value == "")
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    if (email.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    if (email.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    var checkOK = "0123456789";
    var checkStr = document.clientform.cphone;
    var allValid = true;
    var decPoints = 0;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length)
        {
            allValid = false;
            break;
        }
        if (ch != ",")
            allNum += ch;
    }
    if (!allValid)
    {
        alert("Please enter only digit characters in the \"NumberText\" field.");
        document.clientform.focus();
        return (false);
    }
}


    
var xmlHttp = createXmlHttpRequestObject();
// creates an XMLHttpRequest instance
function createXmlHttpRequestObject()
{
    // will store the reference to the XMLHttpRequest object
    var xmlHttp;
    // this should work for all browsers except IE6 and older
    try
    {
        // try to create XMLHttpRequest object
        xmlHttp = new XMLHttpRequest();
    }
    catch(e)
    {
        // assume IE6 or older
        var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
            'MSXML2.XMLHTTP.5.0',
            'MSXML2.XMLHTTP.4.0',
            'MSXML2.XMLHTTP.3.0',
            'MSXML2.XMLHTTP',
            'Microsoft.XMLHTTP');
        // try every prog id until one works
        for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
        {
            try
            {
                // try to create XMLHttpRequest object
                xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
            }
            catch (e) {}
        }
    }
    // return the created object or display an error message
    if (!xmlHttp)
        alert("Error creating the XMLHttpRequest object.");
    else
        return xmlHttp;
}
// read a file from the server
function getLocation(locationId)
{
    var strURL ="http://localhost/smartBussiness/js/findLocation.php?location="+locationId;

    var req = createXmlHttpRequestObject();

    if (req) {

        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {
                    document.getElementById('locdiv').innerHTML=req.responseText;
                } else {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }
        }
        req.open("GET", strURL, true);
        req.send(null);
    }
}
// function called when the state of the HTTP request changes
function handleRequestStateChange()
{
    // when readyState is 4, we are ready to read the server response
    if (xmlHttp.readyState == 4)
    {
        // continue only if HTTP status is "OK"
        if (xmlHttp.status == 200 || xmlHttp.status == 400)
        {
            try
            {
                document.getElementById('locdiv').innerHTML=req.responseText;
            // do something with the response from the server
            }
            catch(e)
            {
                // display error message
                alert("Error reading the response: " + e.toString());
            }
        }
        else
        {
            // display status message
            alert("There was a problem retrieving the data:\n" +
                xmlHttp.statusText);
        }
    }
}

   





var menuids=["treemenu1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal(){
    for (var i=0; i<menuids.length; i++){
        var
        ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
        for (var t=0; t<ultags.length; t++){
            if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
                ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px"
                //dynamically position first level submenus to be height of main menu item

                ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"

            }
            else{ //else if this is a sub level menu (ul)

                ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px"
                //position menu to the right of menu item that activated it

                ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"

            }
            ultags[t].parentNode.onmouseover=function(){
                this.getElementsByTagName("ul")[0].style.visibility="visible"
            }
            ultags[t].parentNode.onmouseout=function(){
                this.getElementsByTagName("ul")[0].style.visibility="hidden"
            }
        }
    }
}

if (window.addEventListener)
    window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
    window.attachEvent("onload", buildsubmenus_horizontal)


