﻿var xmlhttp = false;
var XMLDoc;
var ctlAppened = "ctl00_ctl00_IWPContent_frontContent_";
    //var ctlAppened = "ctl00_frontContent_";
var search_id;
getHTTPRequestObject();

function Search_Click()
{
    var searchDef;        
    //Clear values
    pleaseWait(document.getElementById("divPeopleSearchResult"));
    document.getElementById("divPeopleResultDetail").innerHTML = "";
    hideEmailer();
    xmlhttp.open("POST", "http://" + location.host + "/IWPWebService.asmx/peopleGetSearchResult", true);
    xmlhttp.onreadystatechange = function () {runFunction(peopleSearchResult);};

    searchDef += "&indvSalut=" + document.getElementById(ctlAppened + "indvSalut").value;
    searchDef += "&indvFirst=" + escape(document.getElementById(ctlAppened + "indvFirst").value);
    searchDef += "&indvMI=" + escape(document.getElementById(ctlAppened + "indvMI").value);
    searchDef += "&indvLast=" + escape(document.getElementById(ctlAppened + "indvLast").value);
    searchDef += "&indvSuf=" + escape(document.getElementById(ctlAppened + "indvSuf").value);
    searchDef += "&indvTitle=" + escape(document.getElementById(ctlAppened + "indvTitle").value);
    searchDef += "&coName=" + escape(document.getElementById(ctlAppened + "coName").value);
    searchDef += "&address=" + escape(document.getElementById(ctlAppened + "address").value);
    searchDef += "&city=" + escape(document.getElementById(ctlAppened + "city").value);
    searchDef += "&state=" + document.getElementById(ctlAppened + "state").value;
    searchDef += "&coZip=" + document.getElementById(ctlAppened + "coZip").value;
    searchDef += "&coArcode=" + document.getElementById(ctlAppened + "coArcode").value;
    searchDef += "&coPhone=" + document.getElementById(ctlAppened + "coPhone").value;

    searchDef += "&blnRtl=" + document.getElementById(ctlAppened + "chkRetail").checked;
    searchDef += "&blnPgm=" + document.getElementById(ctlAppened + "chkProgram").checked;
    searchDef += "&blnWh=" + document.getElementById(ctlAppened + "chkWholesale").checked;
    searchDef += "&blnMg=" + document.getElementById(ctlAppened + "chkMUnder").checked;
    searchDef += "&blnCar=" + document.getElementById(ctlAppened + "chkCarrier").checked;
    searchDef += "&blnSup=" + document.getElementById(ctlAppened + "chkSupplier").checked;

    searchDef += "&blnAdmitted=" + document.getElementById(ctlAppened + "admitted").checked;
    searchDef += "&blnProgram=" + document.getElementById(ctlAppened + "program").checked;
    searchDef += "&blnSurplus=" + document.getElementById(ctlAppened + "surplus").checked;
    searchDef += "&blnCommercial=" + document.getElementById(ctlAppened + "Commercial").checked;
    searchDef += "&blnPersonal=" + document.getElementById(ctlAppened + "Personal").checked;
    searchDef += "&blnLife=" + document.getElementById(ctlAppened + "life").checked;
    searchDef += "&blnExcessLiability=" + document.getElementById(ctlAppened + "excess").checked;
    searchDef += "&blnProLiability=" + document.getElementById(ctlAppened + "professional").checked;
    searchDef += "&blnBenefits=" + document.getElementById(ctlAppened + "benefits").checked;
    searchDef += "&blnWC=" + document.getElementById(ctlAppened + "WC").checked;
    searchDef += "&blnDBLLTC=" + document.getElementById(ctlAppened + "DBL_LTC").checked;
    searchDef += "&blnBonds=" + document.getElementById(ctlAppened + "bonds").checked;
    searchDef += "&cOpp=" + document.getElementById(ctlAppened + "cOpp").checked;
    searchDef += "&jApp=" + document.getElementById(ctlAppened + "jApp").checked;
    searchDef += "&bOpp=" + document.getElementById(ctlAppened + "bOpp").checked;
    searchDef += "&requests=" + document.getElementById(ctlAppened + "requests").checked;
	
    searchDef += "&position=" + document.getElementById(ctlAppened + "position").value;
    if (document.getElementById(ctlAppened + "staff").checked)
    {     
        searchDef += "&staff_mgt=ST";
    }
    else if (document.getElementById(ctlAppened + "management").checked)
    {
        searchDef += "&staff_mgt=MG";
    }
    else
    {
        searchDef += "&staff_mgt=";
    }
    xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(searchDef);
}
function peopleSearchResult()
{
    var objNodeList = XMLDoc.getElementsByTagName("ReturnDataSet");
    var stringout = "";
    var altColor = "even";
    var strMonth = "";
    var strDay = "";
    var strYear = "";
    var strDate = "";
    var strPrevDate = "";
    if (objNodeList.length > 0)
    {
		search_id = getParsedElement(objNodeList[0], "search_id");
        for (var i = 0;i < objNodeList.length; i++)
        {     
            var dataNodeList;
            var leftDate;
            dataNodeList = objNodeList[i];           
            if (altColor == "even")
            {
                altColor = "odd";
            }
            else
            {
                altColor = "even";
            }
            stringout += "<div class=\"" + altColor + "\" style=\"width: 340px;\"> ";
			stringout += "<img src=\"images/arw_org.gif\" style=\"width: 8px; height:12px;padding-right:5px;float: left;\" alt=\">\"/>";
			stringout += "<div style=\"float: left; width: 250px;\">";
            stringout += "<div class=\"link\" style=\"float: left;\" id=\"edit_left_title\" onClick=\"JavaScript:viewDetail_Click('" + getParsedElement(dataNodeList, "master_listing_id") + "');\">";
            stringout += getParsedElement(dataNodeList, "person_fname") + " " + getParsedElement(dataNodeList, "person_mi") + " " + getParsedElement(dataNodeList, "person_lname");
            stringout += "</div> ";
            stringout += "<div class=\"maEdit_left_location\" id=\"edit_left_location\"> ";
            temp = " ";
            if((getParsedElement(dataNodeList, "person_account_name")!="") && (getParsedElement(dataNodeList, "person_account_city")!=""))
            {temp = ", ";}
            stringout += Trim(getParsedElement(dataNodeList, "person_account_name")) + temp;
            temp = " ";
            if((getParsedElement(dataNodeList, "person_account_city")!="") && (getParsedElement(dataNodeList, "person_account_state")!=""))
            {temp = ", ";}
            stringout += Trim(getParsedElement(dataNodeList, "person_account_city")) + temp;
            stringout += getParsedElement(dataNodeList, "person_account_state");
            stringout += "</div></div></div>";
            strPrevDate = strDate;
	    }
    }
    else { stringout = "No results found."}
    pplTempSO = stringout;
    window.setTimeout("pleaseWaitLoading = false;", simTimer);
    //pleaseWaitLoading = false;
    window.setTimeout("document.getElementById(\"divPeopleSearchResult\").innerHTML = pplTempSO;", simTimer);
    //document.getElementById("divPeopleSearchResult").innerHTML = stringout;
}
function viewDetail_Click(master_listing_id)
{
    pleaseWait(document.getElementById("divPeopleResultDetail"));
    hideEmailer();
    hideTY();
    xmlhttp.open("POST", "http://" + location.host + "/IWPWebService.asmx/peopleGetResultDetail", true);
    xmlhttp.onreadystatechange = function () {runFunction(peopleResultDetail)};
    xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send("master_listing_id="+master_listing_id + "&search_id=" + search_id);
    //xmlhttp.send("person_listing_id=" + person_listing_id);
}    
function peopleResultDetail()
{
    var objNodeList = XMLDoc.getElementsByTagName("ReturnDataSet");
    var stringout = "";
    if (objNodeList.length > 0)
    {
        for (var i = 0;i < objNodeList.length; i++)
        {
            var dataNodeList;
            var leftDate;
            dataNodeList = objNodeList[i];
            stringout = "<div class=\"class_listing_info\" style=\"width: 200px;\">";
            stringout += "<div class=\"maEdit_right_title\" id=\"right_title\">";
            stringout += getParsedElement(dataNodeList, "person_fname") + " " + getParsedElement(dataNodeList, "person_mi") + " " + getParsedElement(dataNodeList, "person_lname");
            stringout += "</div>";
            stringout += "<div style=\"float: left;\">";
            if(notNull(getParsedElement(dataNodeList, "person_title")))
            {
                stringout += "<p>" + getParsedElement(dataNodeList, "person_title") + "</p>";
            }
            if(notNull(getParsedElement(dataNodeList, "person_account_name")))
            {
                stringout += "<p>" + getParsedElement(dataNodeList, "person_account_name") + "<br />";
            }
            if(notNull(getParsedElement(dataNodeList, "person_account_address")))
            {
                stringout += getParsedElement(dataNodeList, "person_account_address") + "<br />";
            }
            temp = " ";
            if((getParsedElement(dataNodeList, "person_account_city")!="") && (getParsedElement(dataNodeList, "person_account_state")!=""))
            {temp = ", ";}
            stringout += Trim(getParsedElement(dataNodeList, "person_account_city")) + temp;
            temp = " ";
            if((getParsedElement(dataNodeList, "person_account_state")!="") && (getParsedElement(dataNodeList, "person_account_zip")!=""))
            {temp = ", ";}
            stringout += Trim(getParsedElement(dataNodeList, "person_account_state")) + temp;
            stringout += Trim(getParsedElement(dataNodeList, "person_account_zip")) + "</p>";
            if(notNull(getParsedElement(dataNodeList, "person_account_www")))
            {
                stringout += "<p> <a href=\"http://" + getParsedElement(dataNodeList, "person_account_www") + "\" target=\"_blank\">"+getParsedElement(dataNodeList, "person_account_www")+"</a></p>";
            }
            stringout += "<p>Phone: ";
            if( (getParsedElement(dataNodeList, "person_arcode").trim().length > 0) && (getParsedElement(dataNodeList, "person_phone").trim().length > 0)){
            stringout += "(" + Trim(getParsedElement(dataNodeList, "person_arcode")) + ") " + Trim(getParsedElement(dataNodeList, "person_phone").substring(0,3)) + "-" + Trim(getParsedElement(dataNodeList, "person_phone").substring(3,8)) + "</p>";}
            stringout += "<p><span class=\"SH\" style=\"float; left; cursor: pointer;\" onclick=\"showEmailer()\">";
			stringout += "<img src=\"images/arw_org.gif\" style=\"width: 8px; height: 12px;padding-right: 5px; float: left;\" alt=\">\"/> Contact ";
            stringout += getParsedElement(dataNodeList, "person_fname") + "by E-mail </span></p>";
            document.getElementById(ctlAppened + "toEmail").value = getParsedElement(dataNodeList, "email");
            stringout += "</div>";
            stringout += "</div>";
        }
	    pplTempSO = stringout;
	    window.setTimeout("pleaseWaitLoading = false;", simTimer);
	    //pleaseWaitLoading = false;
	    window.setTimeout("document.getElementById(\"divPeopleResultDetail\").innerHTML = pplTempSO;", simTimer);
	    //document.getElementById("divPeopleResultDetail").innerHTML = stringout;
    }
}
function ValidateEmail() {
    if (!validEmail(document.getElementById(ctlAppened + "email").value)) {
        alert("Please enter a valid Email");
        document.getElementById(ctlAppened + "email").focus();
        return false;
    }
    if (!notNull(document.getElementById(ctlAppened + "subject").value)) {
        alert("Please enter a Subject.");
        document.getElementById(ctlAppened + "subject").focus();
        return false;
    }
    if (!notNull(document.getElementById(ctlAppened + "message").value)) {
        alert("Can not send blank Email.");
        document.getElementById(ctlAppened + "message").focus();
        return false;
    }
    return true;
}