/*
Javascript
Developed by Ilanthirayan Singaram (ilanthirayan@yahoo.com)
*/
err_msg  = "------------------------------------------------------\n";
err_msg += "    Please include/Re-enter the following:-              \n";
err_msg += "------------------------------------------------------\n\n";

trans_msg  = "-------------------------------------------\n";
trans_msg += "Please click on OK, and wait \nfor the transaction to complete.\n";
trans_msg += "-------------------------------------------\n\n";

var requestSubmitted = false;

function isblank(s)
{
        for (var i = 0; i < s.length; i++){
                var c = s.charAt(i);
                if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
        }
        return true;
}

function field_desc(item){

        switch(item){
                case "fname":
                        return "Enter First Name";
                case "cname":
                        return "Enter Company Name";
                case "lname":
                        return "Enter Last Name";
                case "uname":
                        return "Enter UserName";
                case "pwd":
                        return "Enter Password";
                case "desig":
                        return "Enter Designation";
                case "cpwd":
                        return "Confirm Password";
                case "add1":
                        return "Enter Your Address 1";
                case "city":
                        return "Enter Your City";
                case "state":
                        return "Enter Your State";
                case "phone":
                        return "Enter Your Phone number";
                case "mphone":
                        return "Enter Your Mobile number";
                case "fax":
                        return "Enter Your Fax number";
                case "email":
                        return "Enter Your Email";
        }
}

function validated(string) {
    for (var i=0, output='', valid="1234567890"; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
}
function validate(f){
        var currentDate = new Date()
        var date = new Date();
        var currentHours = date.getHours();
       //+++ do the loop for catching unentered info
        var msg;
        var empty_fields = "";
        var errors = "";
        var a=0;
        var b=0;
	if(f.terms[1].checked){
	alert("You have Disagreed to the Listing Agreement and you will be redirected to our main page")
	window.location='results.php'
	return false
        }
        // Loop thru the elements of the form
        for (var i=0; i < f.length; i++) {
                var e = f.elements[i];
                if (((e.type == "text") || ( e.type == "textarea") || (e.type == "select-one") || (e.type == "password")) && !e.optional) {
                        if (e.type == "select-one"){
                                if (e.options[0].selected){
                                        empty_fields += field_desc(e.name) + "\n";
                                }
                        }
                        if (((e.type == "text") || ( e.type == "textarea") || (e.type == "password")) && !e.optional) {
                                if ((e.value == null) || ( e.value == "") || isblank(e.value)) {
                                        empty_fields += field_desc(e.name) + "\n";
                                        continue;
                                }

                        }
                }
        }
        if(requestSubmitted == false) {
                requestSubmitted = true;
        }else{
                alert("You have already submitted this order.. Please wait");
                return false;
        }

        if (empty_fields) {
                msg = empty_fields;
                alert(err_msg + msg);
                requestSubmitted = false;
                return false;
        }
	
	if(f.pass.value.length>0)
		if(f.pass.value != f.cpass.value) {
		alert('Password and Confirm Password are not matching');
		requestSubmitted = false;
                return false;
}


}
//+++ end of loop

