
function CheckPhoneNumber(TheNumber) {
	var valid = 1
	var GoodChars = "0123456789()-+ "
	var i = 0
	if (TheNumber=="") {
		// Return false if number is empty
		valid = 0
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
			valid = 0
		} // End if statement
	} // End for loop
	return valid
}




// Add in markup necessary to make this work. Basically two divs:
// Overlay holds the shadow
// Lightbox is the centered square that the content is put into.
function addLightboxMarkup() {
	
	bod 				= document.getElementsByTagName('body')[0];
	overlay 			= document.createElement('div');
	overlay.id		= 'overlay';
	lb					= document.createElement('div');
	lb.id				= 'lightbox';
	lb.className 	= 'loading';
	lb.innerHTML	= '<div id="lbLoadMessage">' +
						  '<p>Loading</p>' +
						  '</div>';
	bod.appendChild(overlay);
	bod.appendChild(lb);
	
	
	
}





function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function checkForm(name,company,state,phone,email,businesstype,address,enquiry,hearAbtUs,custCount,payFreq,sfga)
{
    var showWarning = false;
    var errorMsg ="";
    
    if (name=="")
    {
        document.getElementById('mandName').style.display='block';
        showWarning=true
        //errorMsg =errorMsg + "Please enter your name.<br>";
    }
    else document.getElementById('mandName').style.display='none';
    
    if (company=="")
    {
        document.getElementById('mandCompany').style.display='block';
        showWarning=true;
        errorMsg =errorMsg + "Please enter your company name.<br>";
    }
    else document.getElementById('mandCompany').style.display='none';
    
    if (state=="-- Please Select --")
    {
        document.getElementById('mandState').style.display='block';
        showWarning=true
        errorMsg =errorMsg + "Please select a State.<br>";
    }
    else 
    {
    if (document.getElementById('mandState')!=null)
        {
            document.getElementById('mandState').style.display='none';
        }
    }

    if (hearAbtUs == "-- Please Select --") {
        document.getElementById('mandState').style.display = 'block';
        showWarning = true
        errorMsg = errorMsg + "Please select a valid option for how did you hear about us.<br>";
    }
    else {
        if (document.getElementById('mandState') != null) {
            document.getElementById('mandState').style.display = 'none';
        }
    }
    
    
    if (CheckPhoneNumber(phone)==false)
    {
        document.getElementById('mandPhone').style.display='block';
        showWarning=true
        errorMsg =errorMsg + "Please enter a valid phone number.<br>";
    }
    else document.getElementById('mandPhone').style.display='none';
    
    if (echeck(email)==false)
    {
        document.getElementById('mandEmail').style.display='block';
        showWarning=true
        errorMsg =errorMsg + "Please enter a valid email address.<br>";
    }
    else document.getElementById('mandEmail').style.display='none';

    //custCount = parseFloat(custCount.replace("$", "").replace(/,/g, ""));
    
    if (showWarning!=true)
        showDiv('thankyou',name,company,state,phone,email,businesstype,address,enquiry,hearAbtUs,custCount,payFreq,sfga)
    //    {
//        document.getElementById('normalText').style.display='none';
//        document.getElementById('warningText').style.display='block';
//        document.getElementById('warningText').innerHTML="<b><font size='1'>" +  errorMsg + "</font></b>";
//    }
//    else
//    {
//        document.getElementById('normalText').style.display='block';
//        document.getElementById('warningText').style.display='none';
//    }
    
    
    
}

        function WatermarkFocus(txtElem, strWatermark) {
            if (txtElem.value == strWatermark) txtElem.value = '';
        }
        function WatermarkBlur(txtElem, strWatermark) {
        if (txtElem.value == '') txtElem.value = strWatermark;
        }
        

function clearForm()
{
    document.getElementById('mandName').style.display='none';
    document.getElementById('mandCompany').style.display='none';
    document.getElementById('mandState').style.display='none';
    document.getElementById('mandPhone').style.display='none';
    document.getElementById('mandEmail').style.display='none';
    //document.getElementById('normalText').style.display='block';
    //document.getElementById('warningText').style.display='none';
}


function prepareIE(height,overflow)
{
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		//bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		//htm.style.overflow = overflow; 
}

function showDiv(formstate, name, company, state, phone, email, businesstype, address, enquiry, hearAbtUs, custCount, payFreq,sfga)
{
	prepareIE('100%','hidden');

    mydiv = document.getElementById("overlay");
    mydiv.style.display = 'block';
    //mydiv.style.height = "auto";
    lb = document.getElementById("lightbox");
    lb.style.display = 'block';

    lb.innerHTML = "Loading, please wait...";

    if (formstate=="form")
    {
        lb.innerHTML = sendRequest("contactForm.aspx");
    }
    else {
        lb.innerHTML = sendRequest("EnquireNowThanks.aspx?name=" + name + "&company=" + company + "&state=" + state + "&phone=" + phone + "&email=" + email + "&businesstype=" + businesstype + "&address=" + address + "&enquiry=" + enquiry + "&hearAbtUs=" + hearAbtUs + "&custCount=" + custCount + "&payFreq=" + payFreq + "&sfga=" + sfga);
    }




}

function hideDiv()
{
		
var myDate = new Date();
mydiv = document.getElementById("overlay");
mydiv.style.display = 'none';
lb = document.getElementById("lightbox");
lb.style.display = 'none';
//lb.innerHTML = sendRequest("contactForm.aspx?time=" + myDate.getSeconds());

}

function sendRequest(url) 
    { 
        
        var response="";
        
        var request = false; 
        if (window.XMLHttpRequest) { 
            req = new XMLHttpRequest(); 
        } 
        else if (window.ActiveXObject) { 
            try { 
                req = new ActiveXObject("Msxml2.XMLHTTP"); 
                } 
        catch (e){ 
        try{ 
            req = new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
        catch (e){} 
        } 
        } 

        
        
        
        //var req = new XMLHttpRequest();   
        req.open('GET', url, false);    
        req.send(null);   
        if(req.status == 200)   
        {
        //dump(req.responseText);
        response=req.responseText;
        }
        else
        {
        response=req.status;
        }
        
        return response; 
        //return false; 
    } 

