﻿var ControlPrefix = "#ctl00_cphMain_ctl00_";

$(document).ready(function(){
    $("#EnquiryLink").click(function(){
        ToggleEnquiryForm("show");
    })
});

function ToggleEnquiryForm(ShowOrHide)
{
    
    $(ControlPrefix + "EnquiryReport").hide("slow");
    
    $("#EnquiryLink").unbind();
    
    if(ShowOrHide == "show"){
        $("#EnquiryForm").show("slow");
        $("#EnquiryLink").text("Cancel");
        $("#EnquiryLink").click(function(){
            ToggleEnquiryForm("hide");
        })
    }else{
        $("#EnquiryForm").hide("slow");
        $("#EnquiryLink").text("Make an enquiry");
        $("#EnquiryLink").click(function(){
            ToggleEnquiryForm("show");
        })
    }
    return false;
}

function ValidateEnquiry()
{
    var ErrorMessage = "";
    
    if($(ControlPrefix + "tbName").val() == "")
        ErrorMessage += "Please enter your name.\n";
       
    var EmailAddress =  $(ControlPrefix + "tbEmail").val();
    if(EmailAddress == "")
        ErrorMessage += "Please enter your email address.\n";
    else{
        if(!ValidateEmail(EmailAddress))
            ErrorMessage += "Please enter a valid email address.\n";
    }
     
    if($(ControlPrefix + "tbEnquiry").val() == "")
        ErrorMessage += "Please enter an enquiry.";
        
    if(ErrorMessage != ""){
        alert(ErrorMessage);
        return false;
    }
    
    return true;
}

function ValidateEmail(str){

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

/*function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }*/

