

//<form name='frm' method='post' action=''

//onSubmit='return theValidator(this,"Input1,Input3,temp,ta,rad","Name,Zip Code,Template,Comments,University/Non-University",",Y,,,",",,,,",",,,,");'>





//The parameters

// 0) The instance of the form , use 'this' rather than name

// 1) The name of the controls separated by comma, only add name of controls which you want to be validated.

// 2) The Message i.e if you write Name, then the msg would be 'Name cannot be blank.'

// 3) If you want any control to be validated for numeric value, then specify 'Y'

//    exactly in the same order if the 1st parameter has values Input1,Input2,temp,.. if you want to validate the Input2

//    control for numeric value the ,Y,,....

// 4) Email parameter - order as point 3

// 5) URL parameter - order as point 3

// TODO:

//        Email Validation - Done

//        URL Validation        - Done

 //implementation

/*

function check(theform)

{

        thecontrols="vchAttorneyName,vchFirmName,vchAddress1,vchAddress2,vchStateName,vchCity,vchZipCode,vchPhone,vchFax,vchEmailAddress,intFormatID";

        themessages="Attorney name,Firm name,Address,Address,State,City,Zipcode,Phone,Fax,Email address,Format";

        theNumeric=",,,,,,,,,,";

        theEmail=",,,,,,,,,Y,";

        theURL=","

        theConfirmPassword=",";

        thebadstuff="1,1,,,,,,,,,";

        theinteger=",,,,,,,,,,";

        thepercent=",";

        thesize=",,,,,,,,,,";

        thedecimal=",,,,,,,,,,";

        theimage=",";

        theempty="Y,Y,Y,,Y,Y,Y,Y,,Y,Y";

        themin=",";

        themax=",";

        thecheckboxlength=",,,,,,,,,,";

        thephoneno=",,,,,,,Y,Y,,";



        if(!theValidator(theForm,theControl,theMessage,theNumeric,theEMail,theURL,theConfirmPassword,thebadstuff,theinteger,thepercent,thesize,thedecimal,theimage,theempty,themin,themax,thecheckboxlength,thephoneno))

                return false;



        return true;

}

*/



//        *************************************  theValidator **********************************************************



function theValidator(theForm,theControl,theMessage,theNumeric,theEMail,theURL,theConfirmPassword,thebadstuff,theinteger,thepercent,thesize,thedecimal,theimage,theempty,themin,themax,thecheckboxlength,thephoneno)

{

        // This function is used to validate that all text

        // fields in a given form contain some value

        //Split the controls + Messages + Numerics by comma ,





        var theMessages = new Array();

        var theNumerics = new Array();

        var theEMails = new Array();

        var theURLs = new Array();

        var theConfirmPasswords = new Array();



        theControls=theControl.split(",");

        theMessages=theMessage.split(",");

        theNumerics=theNumeric.split(",");

        theEMails=theEMail.split(",");

        theURLs=theURL.split(",");

        thebadstuffs=thebadstuff.split(",");

        theintegers=theinteger.split(",");

        thepercents=thepercent.split(",");

        thesizes=thesize.split(",");

        thedecimals=thedecimal.split(",");

        theimages=theimage.split(",");

        theemptys=theempty.split(",");

        themins=themin.split(",");

        themaxs=themax.split(",");

        thecheckboxlengths=thecheckboxlength.split(",");

        theConfirmPasswords=theConfirmPassword.split(",");

        thephonenos=thephoneno.split(",");



//        alert(theControl);

        for (var i=0; i < theForm.elements.length; i++){

//                alert("Type: " + theForm.elements[i].type);



                for(var counter=0;counter < theControls.length; counter++)

                {

                        if (theForm.elements[i].name == theControls[counter])

                        {

                                if (theForm.elements[i].type == 'file')

                                {

                                        //Blank value check

                                        if (trim(theForm.elements[i].value) == '' && theemptys[counter] == "Y" )

                                        {

//                                                alert(theMessages[counter] + " cannot be blank.");

                                                alert("Please enter the "+theMessages[counter].toLowerCase()+".");

                                                theForm.elements[i].focus();

                                                return false;

                                        }

                                        else

                                        {

                                                if (theimages[counter] == "Y")

                                                {

                                                        var s=theForm.elements[i].value;

                                                        if (s!="")

                                                        {

                                                                array=s.split("\\");

                                                                len=array.length;

                                                                filename=array[len-1];

                                                                array1=filename.split(".");

                                                                if (array1.length == 1)

                                                                {

                                                                        alert("Files with extensions .gif, .jpg, .jpeg can only be uploaded.");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                                                if(array1[1].toLowerCase()!="jpg" && array1[1].toLowerCase()!="jpeg" && array1[1].toLowerCase()!="gif")

                                                                {

                                                                        alert("Files with extensions .gif, .jpg, .jpeg can only be uploaded.");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                                        }

                                                }

                                                if (theimages[counter] == "C")

                                                {

                                                        var s=theForm.elements[i].value;

                                                        if (s!="")

                                                        {

                                                                array=s.split("\\");

                                                                len=array.length;

                                                                filename=array[len-1];

                                                                array1=filename.split(".");

                                                                if (array1.length == 1)

                                                                {

                                                                        alert("Files with extensions .txt, .csv can only be uploaded.");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                                                if(array1[1].toLowerCase()!="txt" && array1[1].toLowerCase()!="csv")

                                                                {

                                                                        alert("Files with extensions .txt, .csv can only be uploaded.");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                                        }

                                                }



                                        }



                                }



                                if (theForm.elements[i].type == 'text')

                                {

                                        //Blank value check

                                        if (trim(theForm.elements[i].value) == '' && theemptys[counter] == "Y")

                                        {

//                                                alert(theMessages[counter] + " cannot be blank.");

                                                //alert("Please enter the "+theMessages[counter].toLowerCase()+".");

                                                //theForm.elements[i].focus();

                                                //return false;
                                                return true;

                                        }



                                        // integer value >=0

                                /*        if (theEMails[counter] != "Y" && theURLs[counter] != "Y" && theNumerics[counter] != "Y")

                                        {

                                                chkstring = trim(theForm.elements[i].value);

                                                badStuff = "~`!@#$%^&*()=+|<>?;:/\"\\";

                                                for (x=0; x<badStuff.length; x++)

                                                {

                                                        badCheck = badStuff.charAt(x);

                                                        if (chkstring.indexOf(badCheck,0) != -1)

                                                        {



                                                                alert(theMessages[counter]+" can not have special characters.");

                                                                theForm.elements[i].focus();

                                                                return false;

                                                        }

                                                }

                                        }*/





                                        // Numeric value check

                                        if (trim(theForm.elements[i].value) != '' && theNumerics[counter] == "Y")

                                        {

                                                if(isNaN(trim(theForm.elements[i].value)))

                                                {

//                                                        alert(theMessages[counter] + " should be numeric.");

                                                        alert("Please enter numeric values for "+theMessages[counter].toLowerCase()+".");

                                                        theForm.elements[i].focus();

                                                        return false;

                                                }

                                                if(trim(theForm.elements[i].value)<= 0 )

                                                {

//                                                        alert(theMessages[counter] + " should be greater than 0.");

                                                        alert("Please enter "+theMessages[counter].toLowerCase()+" greater than  0 (zero).");

                                                        theForm.elements[i].focus();

                                                        return false;

                                                }

                                        }



                                        if  (trim(theForm.elements[i].value) != '' && theintegers[counter] == "Y")

                                        {

                                                        if(isNaN(trim(theForm.elements[i].value)))

                                                                {

                //                                                        alert(theMessages[counter] + " should be numeric.");

                                                                        alert("Please enter numeric values for "+theMessages[counter].toLowerCase()+".");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                                        if(parseInt(trim(theForm.elements[i].value))< 0 )

                                                                {

                                                                alert("Please enter "+theMessages[counter].toLowerCase()+" greater than or equal to 0 (zero).");

                                                                theForm.elements[i].focus();

                                                                return false;

                                                                }

                                        }





                                        if ((trim(theForm.elements[i].value) != '' ) && (thebadstuffs[counter] != ""))

                                        {

                                                        if (thebadstuffs[counter]==1)

                                                                badStuff = "~`!@#$%^&*()=+|<>?;:/\"\\";

                                                        else if(thebadstuffs[counter]==2)

                                                                badStuff="~`!@$%^&*()=+|<>?;:/\"\\";

                                                        else if(thebadstuffs[counter]==3)

                                                                badStuff="~`!@$%^&* ()=+|<>?;\"";

                                                        if (thebadstuffs[counter]==4)

                                                                badStuff = "'~`!@#$%^&*()=+|<>?;:/\"\\ ";

                                                        if (thebadstuffs[counter]==5)

                                                                badStuff='" ';

                                                        else

                                                                badStuff='"';



                                                        chkstring = trim(theForm.elements[i].value);

                                                        for (x=0; x<badStuff.length; x++)

                                                        {

                                                                badCheck = badStuff.charAt(x);

                                                                if (chkstring.indexOf(badCheck,0) != -1)

                                                                {

                                                                        if(badStuff=='"')

                                                                        alert("Please replace double quotes with single quotes for "+theMessages[counter].toLowerCase()+".");

                                                                        else

                                                                        {

                                                                                abc=theMessages[counter].replace(theMessages[counter],theMessages[counter].charAt(0).toUpperCase());

                                                                                //alert(abc+theMessages[counter].substring(1,theMessages[counter].length)+ " should be greater than 0.");

                                                                                alert(abc+theMessages[counter].substring(1,theMessages[counter].length)+" can not have special characters.");

                                                                        }

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                                        }

                                        }



                                        if (trim(theForm.elements[i].value) != '' && thepercents[counter] == 'Y')

                                        {

                                                                if (parseInt(theForm.elements[i].value)<0 || parseInt(theForm.elements[i].value)>100)

                                                                {



                                                                        alert(theMessages[counter].toLocaleUpperCase()+" should have value between 0 to 100.");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                        }





                                        if (trim(theForm.elements[i].value) != '' && thesizes[counter] != "")

                                        {

                                                                if (trim(theForm.elements[i].value).length>thesizes[counter])

                                                                {



//                                                                        alert(theMessages[counter]+" cannot have more than "+thesizes[counter]+" characters.");

                                                                        alert("Maximum characters allowed are "+ thesizes[counter] +". Entered are "+ theForm.elements[i].value.length +" characters.");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                        }



                                        if (trim(theForm.elements[i].value) != '' && thedecimals[counter] != "")

                                        {

                                                                var str=theForm.elements[i].value;

                                                                         if (str.indexOf('.')!=-1)

                                                                                {

                                                                                   alert("No decimals allowed for "+theMessages[counter].toLowerCase()+".");

                                                                                    theForm.elements[i].focus();

                                                                                        return false;

                                                                                }

                                        }



                                        if (trim(theForm.elements[i].value) != '' && thephonenos[counter] != "")

                                        {

                                                var regexp=/^(\d{3} \d{3} \d{4}|\d{3}-\d{3}-\d{4}|\d{10}|\(\d{3}\)\d{3}-\d{4}|\d{6}|\d{7}|\d{8})$/;

                                                x = trim(theForm.elements[i].value);

                                                if(!(regexp.test(x)))

                                                {

                                                        var msg = "";

                                                        msg = "Please enter the correct "+theMessages[counter].toLowerCase();

                                                        msg = msg +  "\n The correct forms are : ";

                                                        msg = msg + "\n xxx xxx xxxx";

                                                        msg = msg + "\n xxx-xxx-xxxx";

                                                        msg = msg + "\n (xxx)xxx-xxxx";

                                                        msg = msg + "\n xxxxxxxxxx (10 digited Mobile no)";

                                                        msg = msg + "\n xxxxxx (6 digits no)";

                                                        msg = msg + "\n xxxxxxx (7 digits no)";

                                                        msg = msg + "\n xxxxxxxx (8 digits no)";



                                                        alert(msg);

                                                    theForm.elements[i].focus();

                                                        return false;

                                                }

                                        }



                                        // Email value check

                                        if (trim(theForm.elements[i].value) != '' && theEMails[counter] == "Y")

                                        {

                                                if(!emailcheck(theForm.elements[i],"Please enter valid email address."))  return false;

                                                //{

                                                //        alert("Invalid Email Address\n Should be user@domain.com");

                                                //        theForm.elements[i].focus();

                                                        //return false;

                                                //}

                                        }

                                        // URL value check

                                        if (trim(theForm.elements[i].value) != '' && theURLs[counter] == "Y")

                                        {

                                                if(!validateURL(trim(theForm.elements[i].value)))

                                                {

//                                                        alert(" Invalid URL \n Should be http://www.domain.com");

                                                        alert("Please enter valid url. \n http://www.domain.com");

                                                        theForm.elements[i].focus();

                                                        return false;

                                                }

                                        }



                                        if (trim(theForm.elements[i].value) !='' && themins[counter]!='' && themaxs[counter]!='')

                                        {

                                                if(parseInt(theForm.elements[i].value)<themins[counter] || parseInt(theForm.elements[i].value)>themaxs[counter])

                                                {

                                                        alert("Please enter value for "+theMessages[counter].toLowerCase()+" between "+themins[counter]+" and "+themaxs[counter]+".");

                                                        theForm.elements[i].focus();

                                                        return false;

                                                }

                                        }

                                        if (trim(theForm.elements[i].value) !='' && themins[counter]!='' && themaxs[counter]=='')

                                        {

                                                if((theForm.elements[i].value.length)<themins[counter])

                                                {

                                                        alert("Please enter valid "+theMessages[counter].toLowerCase()+".");

                                                        theForm.elements[i].focus();

                                                        return false;

                                                }

                                        }

                                        if (trim(theForm.elements[i].value) !='' && themaxs[counter]!='')

                                        {

                                                if( parseInt(theForm.elements[i].value)>themaxs[counter])

                                                {

                                                        alert("Please enter value for "+theMessages[counter].toLowerCase()+" less than "+themaxs[counter]+".");

                                                        theForm.elements[i].focus();

                                                        return false;

                                                }

                                        }



                                }

                                // Password Validation

                                if (theForm.elements[i].type == 'password' && theConfirmPasswords[counter]!="Y")

                                {

                                        //Blank value check

                                        if (trim(theForm.elements[i].value) == '')

                                        {

//                                                alert(theMessages[counter] + " cannot be blank.");

                                                alert("Please enter the "+theMessages[counter].toLowerCase()+".");

                                                theForm.elements[i].focus();

                                                return false;

                                        }





                                                if(theForm.elements[i].value.length > 14)

                                        {

                                                alert("Password cannot have more than 14 characters.");

                                                theForm.elements[i].focus();

                                                return false;

                                        }





                                                if(theForm.elements[i].value.length < 6)

                                        {

                                                alert("Password cannot be less than 6 characters.");

                                                theForm.elements[i].focus();

                                                return false;

                                        }





                                }



                                // Confirm Password Validation

                                //alert(theForm.elements[i].type);

                                //alert(theConfirmPassword[counter]);

                                if (theForm.elements[i].type=='password' && theConfirmPasswords[counter]=="Y")

                                {

                                        //alert("mandeep");

                                        //alert(theForm.elements[i].value);

                                        //alert(theForm.elements[i-1].value);



                                        //Blank value check

                                        if (trim(theForm.elements[i].value) == '')

                                        {

//                                                alert(theMessages[counter] + " cannot be blank.");

                                                alert("Please retype the "+theMessages[counter].toLowerCase()+".");

                                                theForm.elements[i].focus();

                                                return false;

                                        }





                                                if(theForm.elements[i].value.length > 14)

                                        {

                                                alert("Password cannot have more than 14 characters.");

                                                theForm.elements[i].focus();

                                                return false;

                                        }





                                                if(theForm.elements[i].value.length < 6)

                                        {

                                                alert("Password cannot be less than 6 characters.");

                                                theForm.elements[i].focus();

                                                return false;

                                        }



                                        if (theForm.elements[i].value!=theForm.elements[i-1].value)

                                        {

//                                                alert(theMessages[counter] + " is not same.");

                                                alert("Passwords do not match.");

                                                theForm.elements[i].focus();

                                                return false;

                                        }



                                }





                        //Select box validation

                                if (theForm.elements[i].type == "select-one")

                                {

                                        var selIndex,selValue;

                                        selIndex=theForm.elements[i].selectedIndex;

                                        var theObject=theForm.elements[i];

                                        selValue = theObject[selIndex].value;

                                        if( trim(selValue) == "" || trim(selValue) == "0")

                                        {

                                                alert("Please select the " + theMessages[counter].toLowerCase() + ".");

                                                theForm.elements[i].focus();

                                                return false;

                                        }

                                }

                        //Check box validation



                                if (theForm.elements[i].type == "checkbox" && theemptys[counter] == "Y" )

                                {

                                        var flagchecked="0";

//                                        theControls[counter]=theControls[counter].substr(0,theControls[counter].length-2);

//                                        checkboxname=eval("theForm."+theControls[counter]);

                                        if (parseInt(thecheckboxlengths[counter]) > 1)

                                        {

//                                                for (j=0;j<parseInt(thecheckboxlengths[counter]);j++)

                                                for (j=i;j<i+parseInt(thecheckboxlengths[counter]);j++)



                                                {

//                                                        checkbox1=eval(checkboxname[j]);

//                                                        if(checkbox1.checked==true)

                                                        checkbox1=eval(theForm.elements[j]);

                                                        if(checkbox1.checked==true)

                                                        {

                                                                flagchecked="1";

                                                                break;

                                                        }

                                                }

                                        }

                                        else

                                        {

                                                if(theForm.checkboxname.checked==true)

                                                {

                                                        flagchecked="1";

                                                }

                                        }

                                        if (flagchecked=="0")

                                        {

                                                alert("Please select the " + theMessages[counter].toLowerCase() + ".");

                                                theForm.elements[i].focus();

                                                return false;

                                        }

                                        i=i+parseInt(thecheckboxlengths[counter])-1;

                                }



                        // Text Area Validation

                                if (theForm.elements[i].type == "textarea")

                                {

                                        var txtAreaValue;

                                        txtAreaValue=theForm.elements[i].value;



                                        if( trim(txtAreaValue) == "" && theemptys[counter] == "Y")

                                        {

//                                                alert(theMessages[counter] + " cannot be blank.");

                                                alert("Please enter the "+theMessages[counter].toLowerCase()+".");

                                                theForm.elements[i].focus();

                                                return false;

                                        }

                                        if (trim(theForm.elements[i].value) != '' && thesizes[counter] != "")

                                        {

                                                                if (trim(theForm.elements[i].value).length>thesizes[counter])

                                                                {

                                                                                //Maximum characters allowed are n. Entered are m characters.

                                                                        //alert(theMessages[counter]+" cannot have more than "+thesizes[counter]+" characters.");



                                                                        alert("Maximum characters allowed are "+ thesizes[counter] +". Entered are "+ theForm.elements[i].value.length +" characters.");

                                                                        theForm.elements[i].focus();

                                                                        return false;

                                                                }

                                        }

                                }







                        // Radio Button Validation

                        // This radio button validation is buggy so I am commneting it out

                        /*        if(theForm.elements[i].type == "radio")

                                {

//alert(theForm.elements[i].value);

                                        if(getRadioButtonValue(theForm.elements[i],theForm.elements[i].name) == "-1")

                                        {

                                                alert("You must select " + theMessages[counter] + ".");

                                                return false;

                                        }

                                }*/

                        }



                }

        }



        return true;

}







//        ************************************        End theValidator *****************************************************





function getRadioButtonValue(theForm,theControl)

{

        var i;

        alert("Hello " + theForm + " control.length: " + theControl.length);

        for( i=0; i< theControl.length; ++i)

        {

alert(theForm[i].checked);

                if( theControl[i].checked)

                {



                        return theControl[i].value;

                }

        }



        // default (non selected)

        return -1;

}



function ltrim ( s )

{

        return s.replace( /^\s*/, "" )

}



function rtrim ( s )

{

        return s.replace( /\s*$/, "" );

}



function trim(str)

{

//        return rtrim(ltrim(str));

        return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );

}





function emailcheck(object,str)

{

var email=object.value;

var matcharray=email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)

        if(matcharray==null){

        alert(str)

                 object.focus();

                object.select();

        return false;

        }

        else return true

}



function validateEmail(email){



        // This function is used to validate a given e-mail

        // address for the proper syntax



        if (email == ""){

                return false;

        }

        badStuff = ";:/,' \"\\";

        for (i=0; i<badStuff.length; i++){

                badCheck = badStuff.charAt(i)

                if (email.indexOf(badCheck,0) != -1){

                        return false;

                }

        }

        posOfAtSign = email.indexOf("@",1)

        if (posOfAtSign == -1){

                return false;

        }

        if (email.indexOf("@",posOfAtSign+1) != -1){

                return false;

        }

        posOfPeriod = email.indexOf(".", posOfAtSign)

        if (posOfPeriod == -1){

                return false;

        }

        if (posOfPeriod+2 > email.length){

                return false;

        }

        return true

}



function validateURL(myobject)

{

        var re;

        var checkend=/\w\.[a-zA-Z]{2,3}/;



        var checkend=/^http:\/\/([-_0-9A-Za-z]+)\.([-_0-9A-Za-z]+)\.([0-9A-Za-z]+)/;

        //var oRegExp = /[^:]+:\/\/[^:\/]+(:[0-9]+)?\/?.*/;



        //if (!oRegExp.test(oText.value))





        url=myobject.value;

        url=myobject;



        if(url.search(checkend) == -1)

        {

//                alert("Please enter valid url. \n http://www.domain.com");

                return false;

        }

        return true;

}





function validateURL1(myobject)

{

        var re;

        var checkend=/\w\.[a-zA-Z]{2,3}$/;

        url=myobject.value;



        if(url.search(checkend) == -1)

        {

                alert("Please enter valid url. \n http://www.domain.com");

                return false;

        }

        return true;

}



function MM_openBrWindow(theURL,winName,features) { //v2.0

        winName= "new";

        width=screen.width-50;

        height=screen.height-100;

        features="scrollbars=yes,resizable=yes,width="+width+",height="+height+",left=0,top=0";

//        alert (features);

        newpopupwindow =window.open(theURL,'new',features);

//    winName.focus();

}

function MM_openBrWindow2(theURL,winName,features) { //v2.0

//        winName= "new";

        width=screen.width-50;

        height=screen.height-100;

        features="scrollbars=yes,resizable=yes,width="+width+",height="+height+",left=0,top=0";

//        alert (features);

// newpopupwindow =

         window.open(theURL,winName,features);

}

function MM_openHelpWindow(theURL,winName,features,spos) { //v2.0

        winName= "new";



        width=screen.width-350;

        height=screen.height-450;

        if(spos == 1) {

                stop=0;

                sleft=0;

        }

        if(spos == 2) {

                sleft=screen.width-width;

                stop=0;

        }

        if(spos == 3) {

                stop=screen.height-height;

                sleft=0;

        }

        if(spos == 4) {

                stop=screen.height-height;

                sleft=screen.width-width;

        }

        features="scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+sleft+",top="+stop;

        newpopupwindow =  window.open(theURL,'new',features);

}





function confirmdelete(theform,startElement,endElement)

{

        var flag=0;

        for(i=startElement;i<theform.length-endElement;i=i+1)                  //confirmation message for delete

        {

                if(theform.elements[i].checked==true)

                {

                         flag=1;

                         if (confirm("Are you sure you want delete this record?"))

                                return true;

                        else

                                return false;

                }

        }

        if(flag==0)

        {

                alert("Please select the checkbox before pressing the delete button.");

                return false;

        }

}

function confirmation(theform,startElement,endElement,confirmaction)

{

        var flag=0;

        for(i=startElement;i<theform.length-endElement;i=i+1)                  //confirmation message for delete

        {

                if(theform.elements[i].checked==true)

                {

                         flag=1;

                         if (confirm("Are you sure you want "+confirmaction+" this record?"))

                                return true;

                        else

                                return false;

                }

        }

        if(flag==0)

        {

                alert("Please select the checkbox before pressing the "+confirmaction+" button.");

                return false;

        }

}



function confirmCatDelete(theform,msg)        //orderdetail.php

{

        if (confirm("Are you sure you want to delete this "+msg+"?"))

        {        formName=eval("document."+theform);

                formName.flag.value=1;

                formName.submit();

        }

}

function checkQuantity(theform)                        //shopingcart.php

{

        var flag=0;

        for(i=0;i<theform.length;i=i+2)                  //confirmation message for delete

        {

                if(theform.elements[i].checked==true)

                {

                         flag=1;

                         if (confirm("Are you sure you want delete this record?"))

                                return true;

                        else

                                return false;

                }

        }

        if(flag==0)

        {

                for(i=1;i<theform.length;i=i+2)  //numeric value for quantity if user wants to update quantity

                {

                        if(isNaN(theform.elements[i].value))

                        {

                                alert("Quantity should be numeric.");

                                theform.elements[i].focus();

                                return false;

                        }

                        if(theform.elements[i].value < 0)

                        {

                                alert("Quantity should be greater than 0.");

                                theform.elements[i].focus();

                                return false;

                        }

                }

                return true;

        }

}





 function checkdate(theform)     //,dd1,mm1,yy1,dd2,mm2,yy2)

 {



   day1=theform.dd1.options[theform.dd1.selectedIndex].value;

   mon1=theform.mm1.options[theform.mm1.selectedIndex].value;

   year1=theform.yy1.options[theform.yy1.selectedIndex].value;

   day2=theform.dd2.options[theform.dd2.selectedIndex].value;

   mon2=theform.mm2.options[theform.mm2.selectedIndex].value;

   year2=theform.yy2.options[theform.yy2.selectedIndex].value;



        var fromdate = new Date(year1,mon1,day1);

        var todate=new Date(year2,mon2,day2);



        if(fromdate >todate)

         {

                alert("From date should be less than to date.");

                theform.dd2.focus();

                return false;

         }

         return true;

 }



function validate (field, maxlen, str)

{

        if (field.value.length > maxlen)

        {

//                alert ("Field length exceeded.\nAllowed: "+maxlen+" characters,\nEntered: "+field.value.length+" characters.");

                alert(str+" cannot have more than "+maxlen+" characters.");

                field.focus();

                return  false;

        }

        return true;

}



function validate_min_len (field, minlen, str)

{

        if (field.value.length < minlen)

        {



                alert(str+" cannot be less than "+minlen+" characters.");

                field.focus();

                return  false;

        }

        return true;

}



function fileextension(object,str)

{

        var s=object.value;

        if (s!="")

        {

                array=s.split("\\");

                len=array.length;

                filename=array[len-1];

                array1=filename.split(".");

                if(array1[1]!="jpg" && array1[1]!="jpeg" && array1[1]!="gif")

                {

                        alert(str);

                        object.focus();

                        return false;

                }

        }



        return true;

}

function emailcheck(object,str)

{

        var email=object.value;

        var matcharray=email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)

        if(matcharray==null){

        alert(str)

                 object.focus();

                object.select();

        return false;

        }

        else return true

}



function yearcheck(number)

{

        if (number < 1000)

        {

                 number = number + 1900;

        }



 return number;

}



function changedate(theform,i)

{

        if (i==0)

        {

        theformdd=eval(theform.dd1);

        theformmm=eval(theform.mm1);

        theformyy=eval(theform.yy1);

        }

        else

        {

        theformdd=eval(theform.dd2);

        theformmm=eval(theform.mm2);

        theformyy=eval(theform.yy2);

        }



        day1=theformdd.options[theformdd.selectedIndex].value;

//        alert(theform.elements[i].options[theform.elements[i].selectedIndex].value);

        month1=theformmm.options[theformmm.selectedIndex].value;

        month1=month1-1;

        year1=theformyy.options[theformyy.selectedIndex].value;

        var test = new Date(year1,month1,day1);



        aday=test.getDate();

        if ( (parseInt(yearcheck(test.getYear())) == parseInt(year1)) && (parseInt(month1) == parseInt(test.getMonth())) && (parseInt(day1) == parseInt(test.getDate())) )

        {

                newdate=new Date(year1,month1,aday);

                dayNew=eval("theformdd.options[theformdd.selectedIndex]");

                dayNew.value=newdate.getDate();

                optionNumber=newdate.getDate();

                aku=eval("theformdd.options[optionNumber-1]");

                aku.selected=true;

                monthNew=eval("theformmm.options[theformmm.selectedIndex]");

                if (newdate.getMonth()==0 && newdate.getDate()==1 && newdate.getFullYear()>year1 )

                        {

                        monthNew.value=1;

                        opmonth=1;

                        }

                else

                        {

                        monthNew.value=newdate.getMonth()+1;

                        opmonth=newdate.getMonth()+1;

                        }

                amu=eval("theformmm.options[opmonth-1]");

                amu.selected=true;



                yearNew=eval("theformyy.options[theformyy.selectedIndex]");

                yearNew.value=newdate.getFullYear();

                opyear=newdate.getFullYear();

                abc=eval("theformyy");

                for( var u=0;u<abc.options.length;u++)

                {

                        if(yearNew.value==abc.options[u].text)

                        {

                                ayu=eval("theformyy.options[u]");

                                ayu.selected=true;

                        }

                }

        }

        else

        {

                alert("Please enter valid date.");

                theformdd.focus();

                return false;

        }

                return true;

}



/*

* This function will not return until (at least)

* the specified number of milliseconds have passed.

* It does a busy-wait loop.

*/

function pause(numberMillis)

{

        var now = new Date();

        var exitTime = now.getTime() + numberMillis;

        while (true)

        {

                now = new Date();

                if (now.getTime() > exitTime)

                        return;

        }

}



/*  To ask for confirmation before deleting a FAQ */





function textCounter(field,maxlimit)

{

        if (field.value.length > maxlimit)

                field.value = field.value.substring(0, maxlimit);

}



function delfaq()

{

        if(!confirm("Are you sure you want to delete this FAQ?"))

                return false;



                return true;

}



function delTestimonial()

{

        if(!confirm("Are you sure you want to delete this testimonial?"))

                return false;



                return true;

}



function del(str)

{

        if(!confirm("Are you sure you want to delete this "+str+"?"))

                return false;



                return true;

}



function add_group(src,dst)

{

        var selectone=src;

        var selecttwo=dst;



        var i=0;

        while(i<selectone.length)

        {



        if(selectone.options[i].selected==true)

        {



                var selecttwolength=selecttwo.length;

                selecttwo.options[selecttwolength]=new Option(selectone.options[i].text);

                selecttwo.options[selecttwolength].value=selectone.options[i].value;

                selectone.options[i]=null;

                i=i-1;

        }

        i=i+1;

        }

}



function remove_group(src,dst)

{

        var selectone=src;

        var selecttwo=dst;



        k=(selecttwo.length-1);

        var i=k;

        while(i>=0)

        {



        if(selecttwo.options[i].selected==true)

        {

        var selectonelength=selectone.length;

        var selectoneOption=new Option(selecttwo.options[i].text);

        selectone.options[selectonelength]=selectoneOption;

        selecttwo.options[i]=null;

        k=k-1;

        }

        i=i-1;



        }



}

function addfav(){



if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {



var url="http://www.ofni.us";

var title="OFNI the info base";



window.external.AddFavorite(url,title);



}

else {

var msg = "Don't forget to bookmark us!";

if(navigator.appName == "Netscape") msg += "  (CTRL-D)";

document.write(msg);

}

}



 function checkPostiveNumber(theform,startElement,endElement)

{

        for(i=startElement;i<theform.elements.length-endElement;i=i+1)

        {

                if (isNaN(theform.elements[i].value)==true)

                {

                        alert("Please enter numeric value for sequence.");

                        theform.elements[i].focus();

                        return false;

                }

                if (theform.elements[i].value<=0)

                {

                        alert("Sequence should be greater than 0.");

                        theform.elements[i].focus();

                        return false;

                }

        }

        return true;



}





// Function to Select/Deselect checkboxes on form on basis of start and end indexes, If no index specified then applies to all checkboxes on the form

function ChgChkBoxStatOnForm(theform,startElement,endElement,theStat) {

        for(i=startElement;i<theform.elements.length-endElement;i=i+1) {

                if(theform.elements[i].type == 'checkbox') {

                        theform.elements[i].checked = theStat;

                }

        }

}





function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}





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 for checking that check boxes are selected on form or not

function checkselectedchkboxes(theform,theMsg,startelement,endelement) {

        if(theform.elements.length < endelement) {

                endelement = theform.elements.length;

        }

        for(i=startelement;i<=endelement;i++) {

                if(theform.elements[i].type == 'checkbox') {

                        if(theform.elements[i].checked == true) {

                                return true

                        }

                }

        }

        //}

        alert("Please select at least "+theMsg);

        return false;

}





                function fnselectoption(dd,selval) {

                        for(i=0;i<dd.options.length;i++) {

                                if(dd.options[i].value == selval) {

                                        dd.options[i].selected = true;

                                        break;

                                }

                        }

                }









function trimall(obj) {

        for (i=0;i<obj.elements.length;i++)

        {

                if(obj.elements[i].type== 'text') {

                        obj.elements[i].value = trim(obj.elements[i].value);

                }

        }

}







           function checkLetters( str,message )

           {

                 var i, val;

                 var msg = str.split("") ;

                 for (  i = 0 ; i < str.length ; i ++ )

                 {

                   if ( ( (msg[i] <= "Z") && (msg[i] >= "A") ) || ( (msg[i] <= "z") && (msg[i] >= "a") )|| ( msg[i].indexOf("'")>-1 ));

                   else

                   {

                         val = 1;

                         break ;

                   }

                 }

                 if ( val == 1 )

                 {

                   alert (message) ;

                  return false;

                 }



                 return true;

           }

        function is_alphanumeric(str,message)

        {

                //var

                var asstr=trim(str.value);



                var asstr=asstr.replace("\"","'");

                var alphaCount=0;

                var alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,'";

                var sizechar=asstr.length;



                for (var i=0; i<sizechar; i++) {

                        if (alph_valid.indexOf(asstr.charAt(i)) < 0) {

                                alphaCount++

                        }

                }



                if(alphaCount>0)

                {

                        alert(message);

                        str.focus();

                        return false;

                }

                else

                        return true;



        }





        function Zipcheck(object,str)

        {

         var zip=object.value;

         var allvalid=0;

         var valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

         for (var i=0; i<object.value.length; i++)

         {

          if(valid.indexOf(object.value.charAt(i)) < 0)

          {

                allvalid=1;

          }

         }

         if (allvalid==0)

         {

          alert(str);

           object.focus();

          object.select();

         return false;

         }

         else

                 return true;

        }



        function onlyAlphaNum(object,str)

        {

         var valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

         for (var i=0; i<object.value.length; i++)

         {

          if(valid.indexOf(object.value.charAt(i)) < 0)

          {

           alert(str);

           object.focus();

           return false

          }

         }

         return true

        }





        function validatedomain(myobject)

        {

                var strURL = myobject.value;

                if (strURL!="")

                {

                        var is_protocol_ok=strURL.indexOf('www');

                        var is_dot_ok=strURL.indexOf('.');

                        if (((is_protocol_ok==-1) && (is_dot_ok!=-2)) || ((is_protocol_ok!=-1) && (is_dot_ok==-1)))

                        {

                         alert("Please enter correct DOMAIN. \n www.test.com");

                         myobject.focus();

                         return false;

                        }



                }

                return true;

        }



function checkthesechkboxes(theform,theMsg,objchb) {

        for(i=0;i<theform.length;i++) {

                //alert(objchb);

                //alert(theform.elements[i].name);

                if(theform.elements[i].type == 'checkbox' && theform.elements[i].name.substr(0,2) == objchb) {

                        //alert(theform.elements[i].value)

                        //alert(theform.elements[i].name)

                        //alert(theform.elements[i].checked)

                        if(theform.elements[i].checked == true) {

                                return true

                                break;

                        }

                }

        }

        alert("Please select at least "+theMsg);

        return false;

}



function selchoice(obj,selvalue) {

        //alert(obj.options.length-1);

        for(i=0;i<=obj.options.length-1;i++) {

                //alert(obj.options[i].value == selvalue);

                //alert(obj.options[i].value + " " + selvalue);

                if(obj.options[i].value == selvalue) {

                        obj.options[i].selected = true;

                        break;

                }



        }

                //alert('end');

        return true;

}



function openchat(chaturl,title) {

        window.open(chaturl,title,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=600,height=488,left=380,top=120');

        return false;

}



function fback() {

        history.go(-1);

}



function openPopWindow(theURL,winName,features,spos,wid,hei) { //v2.0

        winName= "new";

        width= wid;

         height=hei;

        if(spos == 1) {

                stop=0;

                sleft=0;

        }

        if(spos == 2) {

                sleft=screen.width-width;

                stop=0;

        }

        if(spos == 3) {

                stop=screen.height-height;

                sleft=0;

        }

        if(spos == 4) {

                stop=screen.height-height;

                sleft=screen.width-width;

        }

        features="scrollbars=yes,resizable=no,width="+width+",height="+height+",left="+sleft+",top="+stop;

        newpopupwindow =  window.open(theURL,'new',features);

}