﻿// JScript File
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function refresh() 
{ 
    window.location.reload(); 
} 

function quick_submit()
{
    var txtName = document.getElementById("ctl00_Navigation_Vertical1_Quick_Contact1_txtFullName");
    var txtEmail = document.getElementById("ctl00_Navigation_Vertical1_Quick_Contact1_txtEmail");
    var txtPhone = document.getElementById("ctl00_Navigation_Vertical1_Quick_Contact1_txtPhone");
    //var txtComments = document.getElementById("ctl00_Quick_Contact1_txtComments");
    var validation_summary = "Please complete and answer the required fields:\n";
    if(trim(txtName.value)=="Full Name" || trim(txtName.value)=="")
    {
        validation_summary = validation_summary + "Full Name\n";
    }
    if(trim(txtPhone.value)=="Phone" || trim(txtPhone.value)=="")
    {
        validation_summary = validation_summary + "Phone\n";
    }
    if(trim(txtEmail.value)=="Email Address" || trim(txtEmail.value)=="")
    {
        validation_summary = validation_summary + "E-mail\n";
    }
    else
    {
        retxtname = new RegExp(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
       	if (!(retxtname.test(trim(txtEmail.value))))
        {
            validation_summary = validation_summary + "E-mail address is not valid\n";
            
       	}
    }
     // if(trim(txtComments.value)=="Comments" || trim(txtComments.value)=="")
//    {
//        validation_summary = validation_summary + "Comments / Inquiry\n";
//    }
    if (validation_summary == "Please complete and answer the required fields:\n")
    {
        return true;
    }
    else
    {
        alert(validation_summary);
        return false;
    }
}

function contactus_submit()
{
    var txtFName = document.getElementById("ctl00_Body_Contact_Form1_txtFirstName");
    var txtLName = document.getElementById("ctl00_Body_Contact_Form1_txtLastName");
    var txtEmail = document.getElementById("ctl00_Body_Contact_Form1_txtEmail");
    var txtHow = document.getElementById("ctl00_Body_Contact_Form1_referral");
    var txtTel1 = document.getElementById("ctl00_Body_Contact_Form1_tel");
    var txtTel2 = document.getElementById("ctl00_Body_Contact_Form1_tel2");
    var txtTel3 = document.getElementById("ctl00_Body_Contact_Form1_tel3");
    
    var lblFName = document.getElementById("lblFName");
    var lblLName = document.getElementById("lblLName");
    var lblEmail = document.getElementById("lblEmail");
    var lblPhone = document.getElementById("lblPhone");
    var lblHow = document.getElementById("lblHow");
    
    lblFName.style.color = "#000000";
    lblLName.style.color = "#000000";
    lblEmail.style.color = "#000000";
    lblPhone.style.color = "#000000";
    lblHow.style.color = "#000000";
    
    var validation_summary = "Please complete and answer the required fields:\n";
    if(trim(txtFName.value)=="")
    {
        validation_summary = validation_summary + "First Name\n";
        lblFName.style.color = "#ff0000";
    }
    if(trim(txtLName.value)=="")
    {
        validation_summary = validation_summary + "Last Name\n";
        lblLName.style.color = "#ff0000";
    }
    if(trim(txtEmail.value)=="")
    {
        validation_summary = validation_summary + "E-mail\n";
        lblEmail.style.color = "#ff0000";
    }
    else
    {
        retxtname = new RegExp(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
       	if (!(retxtname.test(trim(txtEmail.value))))
        {
            validation_summary = validation_summary + "E-mail address is not valid\n";
            lblEmail.style.color = "#ff0000";
       	}
    }
    if(trim(txtTel1.value)=="" || trim(txtTel2.value)=="" || trim(txtTel3.value)=="")
    {
        validation_summary = validation_summary + "Main Phone\n";
        lblPhone.style.color = "#ff0000";
    }
    if(trim(txtHow.value)=="")
    {
        validation_summary = validation_summary + "How did you hear about me?\n";
        lblHow.style.color = "#ff0000";
    }
    if (validation_summary == "Please complete and answer the required fields:\n")
    {
        return true;
    }
    else
    {
        alert(validation_summary);
        return false;
    }
}

function LoadPriceFeed()
{
    if (window.ActiveXObject)
    {
        httpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
    else if (window.XMLHttpRequest)
    {
	    httpReq = new XMLHttpRequest();
	}

    
    //Append the name to search for to the requestURL 
    var url = "http://pricefeed.hwcom.com/webprices/";
    httpReq.onreadystatechange = processReqPF;
    httpReq.open('GET', url, true);
    httpReq.send(null);
}

function processReqPF()
{
    if (httpReq.readyState == 4)
        {
            if(httpReq.status == 200)
            {
                  var xmldoc = httpReq.responseXML;
                  var xmlPrices = xmldoc.responseXML.getElementsByTagName("webprices")[0];
				  var xmlrow = xmlPrices.getElementsByTagName("row")[0];		 
				  var strName = xmlrow.getAttributeNode("DisplayName").nodeValue;
            }
            else
            {
                alert("Error loading page\n"+ httpReq.status +":"+ httpReq.statusText);
            }
        } 
}

 
pageMethodConcept={
            callServerSideMethod:function(){
                PageMethods.ProcessRSSItem("http://pricefeed.hwcom.com/webprices/",pageMethodConcept.callback);

                // I am passing 3 and 4 to get sum and set callback method
            },
            callback:function(result){
                alert(result);
            }
        }
//window.onload=pageMethodConcept.callServerSideMethod;
