$(document).ready(function(){	$("#request").resizable();	
	var strDefaultRequestText = "Enter your request here...";
	var bRequestFocus = false;
	$("#request").focus(function() {
		if (!bRequestFocus && this.value == strDefaultRequestText) {
			this.value = '';
			bRequestFocus = true;
		}
		
		$("#request").css("background", "#e5fff3");
	}); 
	
	//***************************************************
	// Submit form check
	//***************************************************
	$("#formTellmemore").submit(function() {

		// hide error box
		$("#errorBox").hide();
		
        //Initialise variables
        var errorMsg = "";
        var errorMsgLong = "";
        if ($("#request").val() == strDefaultRequestText || $("#request").val().length < 10){
        	errorMsg += "\n\tRequest information\t- Length of request information is required at least 10 characters.";
        }

        if ($("#request").val().length > 2000){
        	errorMsg += "\n\tRequest information\t- Length of request information is limited up to 2000 characters.";
        }

        if ($("#emailaddress").val() == "" || !EmailCheck($("#emailaddress").val()) )
		{
        	errorMsg +="\n\tEmail\t\t- Enter your valid email address";
        }

	    //Check for a username
	    if ($("#firstname").val().length < 2){
	            errorMsg += "\n\tFirst Name\t- Length of first name is required at least 2 characters.";
	    }

	    if ($("#lastname").val().length < 2){
            errorMsg += "\n\tLast Name\t- Length of last name is required at least 2 characters.";
    }

	    if (($("#company").val().length > 0 && $("#company").val().length < 3) || $("#company").val().length > 60 ){
	    	errorMsg += "\n\tCompany name\t- Length of company name is required at least 3 characters. ";
	    }
	    
	    // phone field is not required. Therefore, empty value is allowed.
	    if ($("#phone").val().length > 0 && $("#phone").val().length < 8){
	    	errorMsg += "\n\tPhone\t- Length of Phone is required at least 8 characters.";
	    }

	    //Check for a security code
        if ($("#secure-code").val().length != 6){
                errorMsg += "\n\tSecurity Code \t- You must enter the security code";
        }

/*	    if ($("#BrokerID").val().length > 0 && $("#BrokerID").val().length < 3 ){
	            errorMsg += "\n\tLength of Broker ID is required at least 3 characters. Or,\n you can leave it empty if you do not have brokerID code. ";
	    }
*/

        //If there is aproblem with the form then display an error
        if ((errorMsg != "") || (errorMsgLong != "")){
                msg = ""; //"_______________________________________________________________\n\n";
                msg += "The form has not been submitted because there are problem(s) with the form.\n";
                msg += "Please correct the problem(s) and re-submit the form.\n";
                msg += "_______________________________________________________________\n\n";
                msg += "The following field(s) need to be corrected: -\n";

                errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
                return false;
        }

        return true;
	});
});

	
function CancelRequest() {
	confCancel = confirm("Are you sure you want to cancel changes?");
		
	if(confCancel){
		window.location.href="index.php";
		return false;
	}	
	else{
		return false;
	}
}

function setbg(color)
{
	document.getElementById("request").style.background=color;
}



