////////////////////////////////////////////////////////////////////////////////////////////////
// CAPTURE THE ENTER PRESS
////////////////////////////////////////////////////////////////////////////////////////////////
var currTAB="FINDAPRO";
var loginOPEN=0;
var editOPEN=0;
function keyPress(d) {
    if (nn4) {var key=d.which;}
    if (ie4) {var key=event.keyCode;}
    if (key == 13) { 
        if (loginOPEN == 1) {
            dsProcessLoginNFO();
        } else { 
            switch(currTAB) {
                case "FINDAPRO":
                dsSearchDir();
                break;
                case "CHECKMEOUT":
                dsCheckMeOut();
                break;
            }         
        } 
    }
} 
if (navigator.appName.indexOf("Netscape") >= 0 && parseInt
(navigator.appVersion) >= 4) { var nn4 = true }
if (navigator.appName.indexOf("Explorer") >= 0 && parseInt
(navigator.appVersion) >= 4) { var ie4 = true }
document.onkeydown = keyPress;
if (nn4) document.captureEvents(Event.KEYDOWN);

////////////////////////////////////////////////////////////////////////////////////////////////
// MENU & TAB FUNX
////////////////////////////////////////////////////////////////////////////////////////////////

var searchedFAP = 0;
var searchedCMO = 0;
var currON = "FAP";
function showResultsFor(which) {
    if (which == "CheckMeOut") {
        currON = "CMO";
        if (searchedCMO == 0) {
            document.getElementById("hideContent").style.display="block";
	        document.getElementById("showResultsFAP").style.display="none";
	        document.getElementById("FAPdisclaimer").style.display = "none";
        } else {
            document.getElementById("showResultsCMO").style.display="block";
	        document.getElementById("showResultsFAP").style.display="none";
	        document.getElementById("hideContent").style.display="none";
	        document.getElementById("FAPdisclaimer").style.display = "block";
        }
    } else {
        currON = "FAP";
        if (searchedFAP == 0) {
            document.getElementById("hideContent").style.display="block";
	        document.getElementById("showResultsCMO").style.display="none";
	        document.getElementById("FAPdisclaimer").style.display = "none";
        } else {
            document.getElementById("showResultsFAP").style.display="block";
	        document.getElementById("showResultsCMO").style.display="none";
	        document.getElementById("hideContent").style.display="none";
	        document.getElementById("FAPdisclaimer").style.display = "block";
        }
    }
}


// show the menu highlight
var last_menu="";
function menu_swapbg(cellID) { 
    if (last_menu != "") {
        document.getElementById(last_menu).className='';
    }
    
    if (cellID != "" && cellID != last_menu) {        
        document.getElementById(cellID).className='box_form_fullfill_red';
        last_menu = cellID;
    }
}

// hide the menu hightlight
function menu_hidebg() { 
    if (last_menu != "") {
        document.getElementById(last_menu).className='';
        last_menu = "";
        dont = "";
    }   
}

// hide one div + show another
function showHide(showthisDiv,hidethisDiv)  {
	document.getElementById(showthisDiv).style.display="block";
	document.getElementById(hidethisDiv).style.display="none";
	
	if (showthisDiv == "FindAPro") {
	    currTAB="FINDAPRO";
	} 
	if (showthisDiv == "CheckMeOut") {
	    currTAB="CHECKMEOUT";
	}
}

// A to Z category menu
var lastATOZshown = "Bricklayer";
function showAtoZTrade(which) {
    document.getElementById("ATOZ" + lastATOZshown).src="pixx/atoz_" + lastATOZshown + ".jpg";
    document.getElementById(lastATOZshown + "_TERMS").style.display = "none";
    document.getElementById("ATOZ" + which).src="pixx/atoz_" + which + "_up.jpg";
    document.getElementById(which + "_TERMS").style.display = "block";
    document.getElementById(lastATOZTermShown).style.display = "none";
    document.getElementById(which.toUpperCase() + "1").style.display = "block";
    lastATOZTermShown = which.toUpperCase() + "1";
    lastATOZshown = which;
    domRollover();
}

// show the term detail
var lastATOZTermShown = "BRICKLAYER1";
function showAtoZDetail(which) {
    document.getElementById(lastATOZTermShown).style.display = "none";
    lastATOZTermShown = which;
    document.getElementById(which).style.display = "block";
}

// splitup login name
function splitMe(iIn, len) {
    var sOut="";
    var loopy = parseInt(iIn.length / len);
    for (var i=0;i<loopy;i++) {
        
        if (i != (loopy-1)) {
            sOut += iIn.slice(i * len, (i * len) + len) + "<BR/>";
        } else {
            sOut += iIn.slice(i * len, iIn.length);
        }
    }

    return sOut;
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}
	
//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}
	
function isMoney(text){
   var notAllowed= /[^0-9,\.]+/ig;
  
   return !notAllowed.test(text);
}


// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


// whitespace characters
var whitespace = " \t\n\r";


// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
var defaultEmptyOK = true;

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


////////////////////////////////////////////////////////////////////////////////////////////////
// CONTRACTOR VIEW CHANGING FUNX
////////////////////////////////////////////////////////////////////////////////////////////////

// expand main FAP (dont laugh) box
var whichBID;
var isDir;
var openWhich=-1;
var openDir;
function dsShowMoreDetailFAP(which, dir)  {
    // check for login
    //if (document.getElementById("LOGINNAME").innerHTML == "") {
    //    openWhich = which;
    //    openDir = dir;
    //    logInOut("IN");
    //} else { // revert previous opened contractor    
        if (whichBID != -1) {
            mapON = 0;
            back2MainView(whichBID);
        }
        currListPos = 0;

        // open up this contractor
        openWhich = -1;
        document.getElementById("MAIN" + which).style.display="none";
        document.getElementById("MAINR" + which).style.display="none";
        document.getElementById("FULL" + which).style.display="block";
        document.getElementById("FULL" + which).innerHTML = 
            "<table width=100% cellspacing=0 cellpadding=0>" + 
            "<tr><td width=23px align=left><img src=pixx/logo_house.gif /></td>" + 
            "<td class=findapro_results align=left>" + 
                document.getElementById("MAINNAME" + which).innerHTML + 
            "</td><td id=2ICONS" + which + " width=20%>Loading..</td></tr></table>";
            
        if (dir == 1) {
            document.getElementById("BG" + which).style.background = "";
        }
            
        whichBID = which;
        isDir = dir;
        index.dsShowMoreDetailFAP(which, callback_dsShowMoreDetailFAP);
    //}
    mapON = 0;
}		

// cache the results returned from the server
function callback_dsShowMoreDetailFAP(res)  {
    var ds = res.value;
    try {
        if (ds != null && typeof(ds) == "object" && ds.Tables != null)  {
            document.getElementById("EXPAND" + whichBID).style.height="300px";
            try { 
                document.getElementById("2ICONS" + whichBID).innerHTML = document.getElementById("ICONS" + whichBID).innerHTML; 
            } catch(e) {
                document.getElementById("2ICONS" + whichBID).innerHTML = "";
            }
            var s =
                "<BR /><div id='HIDEMAP" + whichBID + "'><table width=100% cellspacing=0 cellpadding=0><tr><td width=23px></td><td class=findapro_results width=28% valign=top align=left>" + 
                    document.getElementById("MAINADDR" + whichBID).innerHTML;// + 
                    //"<BR /><BR /><img src=pixx/logo_phone.gif width=10px />" + ds.Tables[0].Rows[0].telno + "<BR />";
            try {
                if (ds.Tables[0].Rows[0].WWW != "") {    
                    s += "<img src=pixx/logo_IE2.gif height=10px /><a href='http://" + ds.Tables[0].Rows[0].WWW + "' class=defaultLink target='_new'>View WebSite</a>";
                } 
            } catch(e) {}   
          
            s +=
                "<BR /><BR />" + document.getElementById("BIZSTART" + whichBID).innerHTML + 
                "</td><td class=findapro_detail width=160px align=center valign=top>" + ds.Tables[0].Rows[0].jobtypes + "</td>" + 
                "<td class=findapro_detail valign=bottom>" + 
                    "<table width=100% cellspacing=0 cellpadding=0>" +             
                    "<tr><td width=8px></td><td class=findapro_detail align=right>";
                        if (ds.Tables[0].Rows[0].testCnt > 0) {
                            s += "<BR /><BR >Customer Testimonials are available for this contractor<BR />" + 
                                 "<a href=# onclick='dsGrabTestimonials(" + whichBID + ");return false'>" + 
                                 "<img src='pixx/btn_viewtestimonials.gif' class='domroll pixx/btn_viewtestimonials_up.gif' border=0 /></a><BR /><BR />";
                        }
                        
                        if (ds.Tables[0].Rows[0].refscore > 0) {
                            s += "Overall Score : " + ds.Tables[0].Rows[0].refscore + "/10<BR />" + 
                            "Quality : " + ds.Tables[0].Rows[0].ref1 + "/10<BR />" + 
                            "Courtesy : " + ds.Tables[0].Rows[0].ref2 + "/10<BR />" + 
                            "Timeliness : " + ds.Tables[0].Rows[0].ref3 + "/10<BR />" + 
                            "Value for money : " + ds.Tables[0].Rows[0].ref4 + "/10<BR /><BR />";
                        }
                        
                        if (ds.Tables[0].Rows[0].refcount > 0) {                    
                            s += "References Count : " + ds.Tables[0].Rows[0].refcount + "<BR />";
                        }
                        if (ds.Tables[0].Rows[0].lastrefdate != "") {
                            s += "Date Last : " + ds.Tables[0].Rows[0].lastrefdate + "<BR />";
                        }
                        
    //                    s += "<BR /><BR ><table width=98% cellpadding=1 cellspacing=0>" + 
    //                    "<tr><td width=35px><img src=pixx/ref_legal.gif width=35px /></td>" + 
    //                        "<td align=center>Excellent Credit &<BR />Legal History</td>" + 
    //                        "<td width=35px><img src=pixx/ref_credit.gif width=35px height=40px /></td>" + 
    //                    "</tr></table>";

                        s += "</tr></table><BR /><BR >";

                s += "</td></tr>" + 
                "<tr><td colspan=4 class=findapro_results valign=top align=left>" + 
                        "<table width=100% cellspacing=0 cellpadding=0>" + 
                        "<tr><td width=88px><a href=# onclick='dsEmailContractor(" + whichBID + ");return false'><img src=pixx/btn_sendbyemail.gif class='domroll pixx/btn_sendbyemail_up.gif' border=0></a></td>" + 
                            "<td width=2px></td>" + 
                            "<td width=65px><a href='javascript:showHideMap(1," + whichBID + ")'><img src=pixx/btn_showmap.gif class='domroll pixx/btn_showmap_up.gif' border=0></a></td>" + 
                            "<td align=right class=findapro_detail><table width=100% cellspacing=0 cellpadding=0><tr><td width=159px>";
                            
                            if (ds.Tables[0].Rows[0].jobtypesScroll != "") {
                                s += ds.Tables[0].Rows[0].jobtypesScroll;    
                            }
                            
                            s += "</td><td></td><td align=right><a href='javascript:back2MainView(" + whichBID + ")'><img src='pixx/btn_back.gif' class='domroll pixx/btn_back_up.gif' alt='Back To Normal View..' border=0 /></a></td></tr></table></td>" + 
                        "</tr></table>" + 
                    "</td>" + 
                "</tr></table></div>" + 
                "<div id='SHOWMAP" + whichBID + "' style='display:none'><table width=100% cellspacing=0 cellpadding=0><tr><td width=23px></td><td class=findapro_results width=28% valign=top align=left>" + 
                    document.getElementById("MAINADDR" + whichBID).innerHTML + 
                    "<BR /><BR /><img src=pixx/logo_phone.gif width=10px />" + ds.Tables[0].Rows[0].telno + "<BR />";
                    try {
                        if (ds.Tables[0].Rows[0].WWW != "") {    
                            s += "<img src=pixx/logo_IE2.gif height=10px /><a href='http://" + ds.Tables[0].Rows[0].WWW + "' class=defaultLink target='_new'>View WebSite</a>";
                    } 
                    } catch(e) {}   
            s +=
                "<BR /><BR />" + document.getElementById("BIZSTART" + whichBID).innerHTML +  
                "</td><td>" +
                    "<table width=100% cellspacing=0 cellpadding=0 align=center>" +
                    "<tr><td class=box_inset_top_left></td>" +
                        "<td class=box_inset_top_fill></td>" +
                        "<td class=box_inset_top_right></td>" +
                    "</tr>" +
                    "<tr><td class=box_inset_left></td>" + 
                        "<td bgcolor=#eaeaef id='MAPHERE" + whichBID + "'></td>" + 
                        "<td class=box_inset_right></td>" + 
                    "</tr>" + 
                    "<tr><td class=box_inset_end_left></td>" +
                        "<td class=box_inset_end_fill></td>" +
                        "<td class=box_inset_end_right></td>" +
                    "</tr></table>" + 
                "</td></tr>" + 
                "<tr><td colspan=4 class=findapro_results valign=top align=left>" + 
                        "<table width=100% cellspacing=0 cellpadding=0>" + 
                        "<tr><td width=88px><a href=# onclick='dsEmailContractor(" + whichBID + ");return false'><img src=pixx/btn_sendbyemail.gif class='domroll pixx/btn_sendbyemail_up.gif' border=0></a></td>" + 
                            "<td width=2px></td>" + 
                            "<td width=65px><div id='HIDEHIDEMAP" + whichBID + "'><a href='javascript:showHideMap(0," + whichBID + ")'><img src=pixx/btn_hidemap.gif class='domroll pixx/btn_hidemap_up.gif' border=0></a></div></td>" + 
                            "<td align=right class=findapro_detail><table cellspacing=0 cellpadding=0><tr><td id='FULLMAP" + whichBID + "'><i>Click <a href=#>here</a> for FULL Google Map with route planning</i><img src=pixx/spacer.gif width=10px /><BR /><img src=pixx/spacer.gif height=3px /></td>" + 
                            "<td align=right><a href='javascript:back2MainView(" + whichBID + ")'><img src='pixx/btn_back.gif' class='domroll pixx/btn_back_up.gif' alt='Back To Normal View..' border=0 /></a></td></tr></table></td>" + 
                        "</tr></table>" + 
                    "</td>" + 
                "</tr></table></div>";
                
            document.getElementById("FULL" + whichBID).innerHTML += s;
            if (isDir == 1) {
                document.getElementById("BG" + whichBID).style.background = "url('pixx/directory_hightlight_big2.gif')";
            }
            domRollover();
        }
    
    } catch(e) {
        back2MainView(whichBID);
    }   
} 

// show/hide the google map
var mapON = 0;
function showHideMap(show, whichBID) {
    if (show == 1) {
        document.getElementById("HIDEMAP" + whichBID).style.display = "none";
        document.getElementById("SHOWMAP" + whichBID).style.display = "block";
        document.getElementById("MAPHERE" + whichBID).innerHTML = 
            "<iframe width='309px' height='270px' src='googlemap.aspx?POSTCODE=" + 
            document.getElementById("MAINADDRPCODE" + whichBID).innerHTML.replace(" ","%20") + 
            "' frameborder='no' scrolling='no'></iframe>";
        document.getElementById("FULLMAP" + whichBID).innerHTML =
            "<i>Click <a href='http://maps.google.com/maps?q=" + 
            document.getElementById("MAINADDRPCODE" + whichBID).innerHTML.replace(" ","%20") + 
            "' target='_NEW'>here</a> for FULL Google Map with route planning</i><img src=pixx/spacer.gif width=10px /><BR /><img src=pixx/spacer.gif height=3px />";
        mapON = 1;    
    } else {
        document.getElementById("HIDEMAP" + whichBID).style.display = "block";
        document.getElementById("SHOWMAP" + whichBID).style.display = "none";
        document.getElementById("HIDEHIDEMAP" + whichBID).style.display = "block";
        mapON = 0;
    }   
}

// scroll the job types list for the current bid
var currListPos=0;
var step=1;
var keepScrolling="F";
function scrollJobTypes(direction, bid, max) {
    // calc the scroll value
    if (direction == "DWN") {
        if ((currListPos-step) <= (max * -14)) {
            currListPos = (max * -14);
        } else { 
            currListPos -= step;
        }
    } else {
        if ((currListPos+step) >= 0) {
            currListPos = 0;
        } else { 
            currListPos += step;
        }
    }    
    
    // scroll the list 
    document.getElementById("mg" + bid).style.top = currListPos + "px";
    
    // if button still pressed, keep scrolling
	if (keepScrolling == "T") {
		setTimeout("scrollJobTypes('" + direction + "'," + bid + "," + max + ");", 5);
		setTimeout("scrollJobTypes('" + direction + "'," + bid + "," + max + ");", 20);
	}
}      

// swap view back to main (no detail)
function back2MainView(which) {
    if (mapON == 0) {
        document.getElementById("MAIN" + which).style.display="block";
        document.getElementById("MAINR" + which).style.display="block";
        document.getElementById("FULL" + which).style.display="none";
        document.getElementById("EXPAND" + which).style.height="122px";
        document.getElementById("EXPAND" + which).style.width="190px";
                 
        whichBID = -1;
        if (isDir == 1) {
            document.getElementById("BG" + which).style.background = "url('pixx/directory_hightlight4.gif')";
        }    
    } else {  // hide tha map
        showHideMap(0,whichBID);
    }
} 

// expand info tabs on the left
function expandLeftTabs(bid, expand, whichText) {
    if (expand == 1) { // expand
        document.getElementById("CHARTER" + bid).style.display="none";
        document.getElementById("LEGAL" + bid).style.display="none";
        try { document.getElementById("HIDEICONS2" + bid).style.display="none"; } catch(e) {}
        document.getElementById("PIBG" + bid).style.display="none";
        document.getElementById("DETAIL" + bid).style.display="block";
        document.getElementById("DETAILSPACER" + bid).style.height="172px";
        
        // add relevent text
        switch(whichText) {
        case 0:
            document.getElementById("TOPINFO" + bid).style.display="block";
            break;
        case 1:
            document.getElementById("CHARTERINFO" + bid).style.display="block";
            break;
        case 2:
            document.getElementById("LEGALINFO" + bid).style.display="block";
            break;
        case 3:
            document.getElementById("IBGINFO" + bid).style.display="block";
            break;            
        }       
    } else { // revert
        document.getElementById("DETAIL" + bid).style.display="none";
        document.getElementById("CHARTER" + bid).style.display="block";
        document.getElementById("LEGAL" + bid).style.display="block";
        document.getElementById("PIBG" + bid).style.display="block";
        try { document.getElementById("HIDEICONS2" + bid).style.display="block"; } catch(e) {}
           
        document.getElementById("TOPINFO" + bid).style.display="none";
        document.getElementById("IBGINFO" + bid).style.display="none";
        document.getElementById("CHARTERINFO" + bid).style.display="none";
        document.getElementById("LEGALINFO" + bid).style.display="none";
    }
     domRollover();
}

// check me out search
function dsGrabTestimonials(bid)  {
    index.dsGrabTestimonials(bid, callback_dsGrabTestimonials);
}		

// cache the results returned from the server
function callback_dsGrabTestimonials(res)  {
    var ds = res.value;
    if (ds != null && typeof(ds) == "object" && ds.Tables != null)  { 
        var s = "<table width='309px' height='270px' cellpadding=0 cellspacing=1><tr><td align=left valign=top>";
        for (var i=0; i<ds.Tables[0].Rows.length; i++) {
            s += "<BR />" + ds.Tables[0].Rows[i].comments + "<BR /><b>" + ds.Tables[0].Rows[i].refName + "</b><BR />";
        }
        s += "</td></tr></table>";
        
        document.getElementById("HIDEMAP" + whichBID).style.display = "none";
        document.getElementById("SHOWMAP" + whichBID).style.display = "block";
        document.getElementById("MAPHERE" + whichBID).innerHTML = s;
        document.getElementById("FULLMAP" + whichBID).innerHTML = "";
        document.getElementById("HIDEHIDEMAP" + whichBID).style.display = "none";
        mapON = 1;
    }    
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//// GRAB TRADE TYPES @ STARTUP
//////////////////////////////////////////////////////////////////////////////////////////////////

//// fill the trade types combo box  
//function dsGetTradeList()  {
//    index.dsGetTradeList(callback_dsGetTradeList);
//}		

//// cache the results returned from the server
//function callback_dsGetTradeList(res)  {
//    var ds = res.value;
//    if (ds != null && typeof(ds) == "object" && ds.Tables != null)  {
//        var s="<div id=HIDETRADESELECT><select name='fap_tradetype' id='fap_tradetype' size=1 class=inputtext tabindex=2>";
//        s += "<OPTION value=0>Please Select...</option>";
//        
//        for (var i=0; i<ds.Tables[0].Rows.length; i++) {
//            s+="<OPTION value=" + ds.Tables[0].Rows[i].tid + ">" + ds.Tables[0].Rows[i].trade + "</option>";
//        }
//        document.getElementById("selectgoeshere").innerHTML = s + "</select></div>";
//    }
//}

////////////////////////////////////////////////////////////////////////////////////////////////
// POSTCODE FUNX
////////////////////////////////////////////////////////////////////////////////////////////////

// reformat the postcode
function reformatPostCode(sIn) {
    sIn = sIn.replace(" ","");
    switch(sIn.length) {
        case 5:
	        sIn = sIn.substring(0,2) + "  " + sIn.substring(3,5);
	    case 6:
	        sIn = sIn.substring(0,3) + " " + sIn.substring(3,6);
	    case 7:
	        // do nothing, is ok as is
	}
	return sIn;
}

// is pcode valid
function isPostcode(str) {
    var Exp = new RegExp("^[A-Z]{1,2}[0-9]{1,2}[A-Z]? ?[0-9][A-Z]{2}$","i");
    if (Exp.test(str)) 
        return true;
    else
        return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////
// PURCHASE IBG FUNX
////////////////////////////////////////////////////////////////////////////////////////////////
// grab detail of IBG policy
var purchaseStep="";

function dsPurchaseIBG()  {
    // check enter wasnt ment for login
    if (loginOPEN == 1) {
        dsProcessLoginNFO();
    } else { // validate inputs
        whichBID = -1;
        var policyId = document.getElementById("IBG_POLICYID").value;
        var pcode = document.getElementById("IBG_PCODE").value;

        if ((policyId.length >= 6) && (pcode.length >= 2)) {
            purchaseStep = "1";
            showHide("PurchaseIBG_LOADING", "PurchaseIBG_STEP3");
            index.dsPurchaseIBG(policyId, pcode, callback_dsPurchaseIBG);  
        } else {
            alert("Please ensure you have entered the policy number and postcode in full.");
        } 
    }
}

function submit_Step1() {
    //gets the price ready for SecPay
     if (loginOPEN == 1) {
        dsProcessLoginNFO();
    } else { // validate inputs
        //HO Details
        var bil_name = document.getElementById("bil_name").value;
        var bil_addr_1 = document.getElementById("bil_addr_1").value;
        var bil_city = document.getElementById("bil_city").value;
        var bil_post_code = document.getElementById("bil_post_code").value;
        var ship_name = document.getElementById("ship_name").value;
        var ship_addr_1 = document.getElementById("ship_addr_1").value;
        var ship_addr_2 = document.getElementById("ship_addr_2").value;
        var ship_city = document.getElementById("ship_city").value;
        var ship_state = document.getElementById("ship_state").value;
        var ship_post_code = document.getElementById("ship_post_code").value;
        var bil_email = document.getElementById("bil_email").value;
        var bil_tel = document.getElementById("bil_tel").value;    
        var ship_forename = document.getElementById("ship_forename").value;
        var ship_title = document.getElementById("ship_title").value;          
        
        //Policy Details
        var policyId = document.getElementById("IBG_POLICYID").value;
        var cmo_trade = document.getElementById("cmo_trade");
        var tradetype = cmo_trade.options[cmo_trade.selectedIndex].value
        var contract_value = document.getElementById("contract_value").value; 
        var deposit_cover = document.getElementById("deposit_rdo_yes").checked;
        var deposit_cover2 = document.getElementById("deposit_rdo_no").checked; //to check if one has been selected
        var failReason = "";
 
        //form validation
        if ( (!(isMoney(contract_value)) && (contract_value != "")) || (contract_value == "") || (contract_value.length < 3) ) {
            failReason += "\nContract Value";
        }      
                
        if ((tradetype == 0)) {
            failReason += "\nTrade Type";
        }
        
        if ((deposit_cover == false && deposit_cover2 == false)) {
            failReason += "\nDeposit Selection";
        }
        
        if (ship_name.length < 3) {
            failReason += "\nInstallation Surname";
        } 
        
        if (ship_addr_1.length < 3) {
            failReason += "\nInstallation Address 1";
        } 
        
        if (ship_city.length < 3) {
            failReason += "\nInstallation Town/City";
        } 
        
        if (!(isPostcode(ship_post_code))) {
            failReason += "\nInstallation PostCode";
        }
         
        if (bil_name.length < 3) {
            failReason += "\nBilling Name";
        } 
        
        if (bil_addr_1.length < 3) {
            failReason += "\nBilling Address 1";
        } 
        
        if (bil_city.length < 3) {
            failReason += "\nBilling Town/City";
        } 
        
        if (!(isPostcode(bil_post_code))) {
            failReason += "\nBilling PostCode";
        } 
        
        if (!isEmail(bil_email)) {
          failReason += "\nEmail";
        }
        
        if (contract_value > 30000) {
            if (failReason.length == 0) { 
                failReason += "\nContract Value exceeds online insurable limit, for\na quote on this policy please phone 08707 344 344";}
            else {
                failReason += "\n\nContract Value exceeds online insurable limit, for\na quote on this policy please phone 08707 344 344";}          
        }
        
        if (failReason.length == 0) { //if not validation failed
               purchaseStep = "2"; 
               showHide("PurchaseIBG_LOADING", "PurchaseIBG_STEP1");
               
               index.dsPurchaseIBG_PRICES(policyId, tradetype, contract_value, deposit_cover,
                ship_name, ship_addr_1, ship_addr_2, ship_city, ship_state, ship_post_code, bil_email, bil_tel, ship_forename, ship_title,
                         callback_dsPurchaseIBG_PRICES);
                                     
        } else {
            alert("Validation failed on :\n" + failReason);
        } 
    }
}

function bil_Chked() {
    var sTitle = document.getElementById("ship_title").options[document.getElementById("ship_title").selectedIndex].innerHTML
    
    //copies the billing detail into the shipping detail values
    if (document.getElementById("bil_chk").checked == true) {
        //sort out the title
        if (document.getElementById("ship_title").value != 0) {
            if (document.getElementById("ship_title").selectedIndex == 7) {
              document.getElementById("bil_name").value = "Mr & Mrs"
            } else {
              document.getElementById("bil_name").value =  sTitle;}
            
            if (sTitle.length != 0) {
             document.getElementById("bil_name").value += " " + document.getElementById("ship_name").value;
            }
            else {
             document.getElementById("bil_name").value = document.getElementById("ship_name").value;}            
        }
        else {
            document.getElementById("bil_name").value = document.getElementById("ship_name").value;
        }       
        
        document.getElementById("bil_addr_1").value = document.getElementById("ship_addr_1").value;
        document.getElementById("bil_addr_2").value = document.getElementById("ship_addr_2").value;
        document.getElementById("bil_city").value = document.getElementById("ship_city").value;
        document.getElementById("bil_state").value = document.getElementById("ship_state").value;
        document.getElementById("bil_post_code").value = document.getElementById("ship_post_code").value;                                                
    } else {
        document.getElementById("bil_name").value = "";
        document.getElementById("bil_addr_1").value = "";
        document.getElementById("bil_addr_2").value = "";
        document.getElementById("bil_city").value = "";
        document.getElementById("bil_state").value = "";
        document.getElementById("bil_post_code").value = "";      
    }
}

function deposit_rdo_Chked(res) {
    //selects whether the user requires deposit cover    
    if (res == "YES") {
        //checked yes
        if (document.getElementById("deposit_rdo_yes").checked == true) {
            document.getElementById("deposit_rdo_no").checked = false;
        }  
    }   
    if (res == "NO") {
        //checked no
        if (document.getElementById("deposit_rdo_no").checked == true) {
            document.getElementById("deposit_rdo_yes").checked = false;
        }   
    }
}

function callback_dsPurchaseIBG_FillTradeList(res) {
    //process returned dataset
    var ds = res.value;
    var noerro="NOPE";
    var s="";
    try {
        noerror = ds.Tables[0].Rows[0].ERROR;  
        if (typeof(noerror) == "undefined") noerror = "NOPE";
    } catch(e) { noerror="NOPE"; }
    if (ds != null && typeof(ds) == "object" && ds.Tables != null && noerror == "NOPE")  { 
        //check for results    
        if (ds.Tables[0].Rows.length == 0) {
           alert("Record not found, please check your details.");
        }
        else {
             for (var i=0; i<ds.Tables[0].Rows.length; i++) {
                 s += "<option value=" + ds.Tables[0].Rows[i].ID + ">" + ds.Tables[0].Rows[i].trade + "</option>";
             }
             document.getElementById("cmo_tradeTd").innerHTML = "<select name='cmo_trade' id='cmo_trade'>" + s + "</select>";
             document.getElementById("cmo_trade").readOnly = false;
        } //got records
    }
}

function callback_dsPurchaseIBG(res) {  
    // process return
    var ds = res.value;
    var policyId = document.getElementById("IBG_POLICYID").value;
    var noerror="NOPE";
    try {
        noerror = ds.Tables[0].Rows[0].ERROR;  
        if (typeof(noerror) == "undefined") noerror = "NOPE";
    } catch(e) { noerror="NOPE"; }
           
     if (ds != null && typeof(ds) == "object" && ds.Tables != null && noerror == "NOPE")  { 
        //check for results    
        if (ds.Tables[0].Rows.length == 0) {
            showHide("PurchaseIBG_STEP1", "PurchaseIBG_LOADING");
             alert("Record not found, please check your details.");
        }
        else {
        //record found continue...
        showHide("PurchaseIBG_STEP2", "PurchaseIBG_STEP1");
        showHide("PurchaseIBG_STEP2", "PurchaseIBG_LOADING");
        showHide("PurchaseIBG_STEP3", "PurchaseIBG_LOADING");
        
        document.getElementById("cmo_tradeTd").innerHTML = "<SELECT name='cmo_trade' id='cmo_trade'><OPTION>Loading...</OPTION></SELECT>";
        document.getElementById("cmo_trade").readOnly = true; //close whilst loading
        index.dsPurchaseIBG_FillTradeList(policyId, callback_dsPurchaseIBG_FillTradeList);
                   
        for (var i=0; i<ds.Tables[0].Rows.length; i++) {
        // fill div with results returned   
            if (ds.Tables[0].Rows[i].proposalid == policyId) {
               //fill fields from database
               document.getElementById("ship_title").value = ds.Tables[0].Rows[i].title;
               document.getElementById("ship_forename").value = ds.Tables[0].Rows[i].fname;
               document.getElementById("ship_name").value = ds.Tables[0].Rows[i].lname;
               document.getElementById("ship_addr_1").value = ds.Tables[0].Rows[i].add1;
               document.getElementById("ship_addr_2").value = ds.Tables[0].Rows[i].add2;
               document.getElementById("ship_city").value = ds.Tables[0].Rows[i].add4;
               document.getElementById("ship_state").value = ds.Tables[0].Rows[i].county;
               document.getElementById("ship_post_code").value = ds.Tables[0].Rows[i].postcode;
               document.getElementById("bil_email").value = ds.Tables[0].Rows[i].email;
               document.getElementById("bil_tel").value = ds.Tables[0].Rows[i].contactnumber;            
            } else {
               alert("ERROR: There was a problem retrieving the data, please try later.");  
               document.getElementById("purchaseIBGSubmit1").innerHTML = "";
            }  
        }
        } //got records
      }
      else {
        alert("Record not found, please check your details.");
      }
}

function callback_dsPurchaseIBG_PRICES(res) {
  // process return
    var ds = res.value;
    var noerror="NOPE";
    try {
        noerror = ds.Tables[0].Rows[0].ERROR;  
        if (typeof(noerror) == "undefined") noerror = "NOPE";
    } catch(e) { noerror="NOPE"; }
           
     if (ds != null && typeof(ds) == "object" && ds.Tables != null && noerror == "NOPE")  { 
        //check for results    
        if (ds.Tables[0].Rows.length == 0) {
            showHide("PurchaseIBG_STEP3", "PurchaseIBG_LOADING");
            alert("No prices found for this type of project.\nPlease check your selections.");
        }
        else {  //record found continue...                
                showHide("PurchaseIBG_STEP3", "PurchaseIBG_LOADING");
                
                //readonly on
                switchReadOnly(true);   
                                
                var r=confirm("Your policy will cost " + ds.Tables[0].Rows[0].retailPrice + "\nPress OK to confirm and pay securely.")
                if (r==true)
                 { 
                    //fill relevant fields
                     document.getElementById("amount").value = ds.Tables[0].Rows[0].retailPrice.substr(1,(ds.Tables[0].Rows[0].retailPrice.length-1));
                     document.getElementById("order").value = "Policy ID : " + document.getElementById("IBG_POLICYID").value;
                     document.getElementById("trans_id").value = document.getElementById("IBG_POLICYID").value;
                     document.getElementById("customer").value = document.getElementById("bil_name").value;
        
                     document.frmIndex.action = "https://www.secpay.com/java-bin/ValCard";
                     switchReadOnly(false); //switch inputs back on so form can function
                     document.getElementById("purchaseIBGSubmit").innerHTML = "";
                     document.frmIndex.submit();
                  }
                else
                 {
                  //readonly off
                  switchReadOnly(false);
                 }
                
        } //got records
     } 
      else {
        alert("No prices found for this type of project.\nPlease check your selections.");
        showHide("PurchaseIBG_STEP3", "PurchaseIBG_LOADING");
      }
}
 
function switchReadOnly(disable) {
    //disable or enable all INPUT/SELECT form objects
    var tagINPUT = document.getElementsByTagName('INPUT') //gets all INPUT objects
         for(x=0; x<tagINPUT.length; x++){
            tagINPUT[x].disabled =  disable; 
         } 
    
    var tagSELECT = document.getElementsByTagName('SELECT') //gets all SELECT objects
         for(x=0; x<tagSELECT.length; x++){
            tagSELECT[x].disabled =  disable; 
         }     
}

//responses to the CR keypress events within the Payment app
function ibgPayment_keypress(step) {
             //which step are we in            
            switch(step) {
                case 1:
                  dsPurchaseIBG();
                break;
                case 2:
                  submit_Step1();
                break;
                case 3:
                  dsPurchaseIBG();
                break;
                default :
                  //dsPurchaseIBG();
                break;
            }         
            return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////
// DIR/CMO SEARCH FUNX
////////////////////////////////////////////////////////////////////////////////////////////////

// directory search 
var justSearched="";
function dsSearchDir()  {
    // check enter wasnt ment for login
    if (loginOPEN == 1) { 
        dsProcessLoginNFO();
    } else {    // validate inputs    
        whichBID = -1;
        justSearched = "FAP";
        //var pcode = reformatPostCode(document.getElementById("fap_pcode").value);
        var pcode = document.getElementById("fap_pcode").value;
        var tradetypebase = document.getElementById("fap_tradetype");
        var tradetype= tradetypebase.options[tradetypebase.selectedIndex].value;
        var trustmark = getQueryVariable("TRUSTMARK");
        
        if (typeof(trustmark) == "undefined") {
            trustmark = "N"; 
        }
        document.getElementById("showFindAProMenu").style.display = "block";
        document.getElementById("FAPpage_content").style.display = "block";
        document.getElementById("frontpage_content").style.display = "none";

        if (pcode != "" && pcode.length > 4 && tradetype > 0) {
            searchedFAP = 1;
            showHide("showLoading", "hideContent");
            document.getElementById("hideSEARCH").style.display = "none";
            document.getElementById("showSEARCH").style.display = "block";
            index.dsSearchDir(pcode, tradetype, trustmark, callback_dsSearchDir);
        } else {
            if (pcode == "") alert("VALIDATION FAIL: Empty PostCode..");
            else if (pcode.length <= 4) alert("VALIDATION FAIL: InValid PostCode..");
            else alert("VALIDATION FAIL: Trade Type has NOT been Selected..");
        } 
    }
}	

// check me out search
function dsCheckMeOut()  {
    // check enter wasnt ment for login
    if (loginOPEN == 1) {
        dsProcessLoginNFO();
    } else { // validate inputs
        whichBID = -1;
        justSearched = "FAP";
        var cname = document.getElementById("cmo_cname").value;
        var town = document.getElementById("cmo_town").value;
        var pcode = document.getElementById("cmo_pcode").value;
        var telno = document.getElementById("cmo_telno").value;
        var ftid = document.getElementById("cmo_FTID").value;

        if ((cname.length >= 2 && (town.length >= 2 || pcode.length >= 2 || telno.length >= 3 )) || ftid.length == 8) {
            searchedCMO = 1;
            showHide("showLoading", "hideContent");
            index.dsCheckMeOut(cname, pcode, town, telno, ftid, callback_dsSearchDir);
        } else {
            alert("VALIDATION FAIL: The Minimum Required Data for a Search was not present..\n" + 
                "(see 'The Check A Tradesman service explained' hyperlink for full search Rules)");
        } 
    }
}

// cache the results returned from the server
var testimonLen;
var testimonPos;
function callback_dsSearchDir(res)  {
    // kill the testimonial timer
    if (interval != null) {
        clearInterval(interval);
		interval=null;
    }
    document.getElementById("hideSEARCH").style.display = "block";
    document.getElementById("showSEARCH").style.display = "none";
    
    // process return
    var ds = res.value;
    var noerror="NOPE";
    try {
        noerror = ds.Tables[0].Rows[0].ERROR;  
        if (typeof(noerror) == "undefined") noerror = "NOPE";
    } catch(e) { noerror="NOPE"; }
    if (ds.Tables[0].Rows.length == 0) ds = null;

    if (ds != null && typeof(ds) == "object" && ds.Tables != null && noerror == "NOPE")  { 
        // fill div with results returned   
        var s="";
        var dir;
        testimonLen = null;
        testimonLen = new Array();
        testimonPos = null;
        testimonPos = new Array();

        for (var i=0; i<ds.Tables[0].Rows.length; i++) {
            if (ds.Tables[0].Rows[i].directory == 1) {
                s += "<table style='background-image:url(pixx/directory_hightlight4.gif);' id=BG" + ds.Tables[0].Rows[i].bid + ">" + 
                     "<tr><td style='padding-left:10px;padding-right:11px;padding-top:7px;padding-bottom:8px;'>";
                dir = 1;
            } else {
                s += "<table><tr><td>";
                dir = 0;
            }

            s +=
                "<table width=495px cellspacing=0 cellpadding=0 align=center>" +               
                "<tr><td width=50%>" + 
                    "<table width=100% cellspacing=0 cellpadding=0>" +
                    "<tr><td class=box_form_top_left></td>" + 
                        "<td class=box_form_top_fill></td>" + 
                        "<td class=box_form_top_right></td>" + 
                    "</tr>" + 
                    "<tr><td class=box_form_left></td>" +
                        "<td bgcolor=#eaeaef valign=top>" + 
                            "<div id=MAIN" + ds.Tables[0].Rows[i].bid + "><table width=100% cellspacing=0 cellpadding=0>" +
                            "<tr><td width=23px align=left valign=top><img src=pixx/logo_house.gif /></td>" + 
                                "<td width=1px><img src=pixx/spacer.gif height=25px width=1px /></td>" + 
                                "<td class=findapro_results align=left width=220px valign=top><div id=MAINNAME" + ds.Tables[0].Rows[i].bid + " style='position:relative;width:200px;height:25px;overflow:hidden;vertical-align:bottom;'><b>" + 
                                    ds.Tables[0].Rows[i].businessName.toUpperCase() + "</b></div>" + 
                            "</td><td width=10px></td></tr>" +
                            "<tr><td colspan=3 valign=bottom>" + 
                                "<table cellspacing=0 cellpadding=0>" +
                                "<tr><td width=24px><img src=pixx/spacer.gif width=24px /></td>" + 
                                    "<td class=findapro_results valign=top align=left width=200px height=122px id=EXPAND" + ds.Tables[0].Rows[i].bid + ">" + 
                                        "<div id=MAINADDR" + ds.Tables[0].Rows[i].bid + "><BR />" + 
                                        ds.Tables[0].Rows[i].address1 + "<BR />";
                                  
                                        if (ds.Tables[0].Rows[i].address2 != "" && ds.Tables[0].Rows[i].address2 != " " && ds.Tables[0].Rows[i].address2 != null) {
                                            s += ds.Tables[0].Rows[i].address2 + "<BR />";
                                        }
                                        
                                        s += ds.Tables[0].Rows[i].address4 + "<BR />" +
                                            "<div id=MAINADDRPCODE" + ds.Tables[0].Rows[i].bid + ">" + 
                                            ds.Tables[0].Rows[i].pcode + "</div>" + 
                                            "<table><tr><td><img src=pixx/logo_phone.gif width=10px /></td><td>" + ds.Tables[0].Rows[i].telephone + "</td></tr></table><BR />" + 
                                            "</div>" + 
                                            "<div id=BIZSTART" + ds.Tables[0].Rows[i].bid + ">" + 
                                            "(Established  " + ds.Tables[0].Rows[i].businessstart + ")";
                                            
                                        if (ds.Tables[0].Rows[i].DateOfIncorp != null) {
                                            s += "<BR />(Incorporated  " + ds.Tables[0].Rows[i].OKDateOfIncorp + ")</div>";
                                        }

                             s +=   "</td></tr>" + 
                                "<tr><td colspan=3 class=findapro_results align=right height=25px>";
                                    if (ds.Tables[0].Rows[i].testimonial != "") {
                                            s += 
                                                "<table cellspacing=0 cellpadding=0><tr><td><img src=pixx/spacer.gif width=5px /></td><td><table width=220px cellspacing=0 cellpadding=0 align=center>" + 
                                                "<tr><td class=box_inset_top_left></td>" +
                                                    "<td class=box_inset_top_fill></td>" + 
                                                    "<td class=box_inset_top_right></td>" +
                                                "</tr>" +
                                                "<tr><td class=box_inset_left></td>" + 
                                                    "<td bgcolor=#eaeaef align=left>" +
                                                        "<div id='testIc" + testimonLen.length + "' style='position:relative;width:210px;height:13px;overflow:hidden;'>" +
                                                        "<div id='testIg" + testimonLen.length + "' style='position:absolute;left:0;top:0;white-space:nowrap;'>" +
                                                        "<nobr id='testIt" + testimonLen.length + "'>" + 
                                                        ds.Tables[0].Rows[i].testimonial +
                                                        "</nobr></div></div>" + 
                                                    "</td><td class=box_inset_right></td>" + 
                                                "</tr>" + 
                                                "<tr><td class=box_inset_end_left></td>" +
                                                "<td class=box_inset_end_fill></td>" +
                                                "<td class=box_inset_end_right></td>" +
                                                "</tr></table></td></tr></table>";
                                            testimonLen[testimonLen.length] = ds.Tables[0].Rows[i].testimonial.length;
                                            testimonPos[testimonPos.length] = 0;
                                    } else {
                                            s += 
                                                "<table cellspacing=0 cellpadding=0><tr><td><img src=pixx/spacer.gif width=5px /></td><td><table width=220px cellspacing=0 cellpadding=0 align=center>" + 
                                                "<tr><td><img src=pixx/spacer.gif width=4px height=4px /></td>" +
                                                    "<td><img src=pixx/spacer.gif width=210px height=4px /></td>" + 
                                                    "<td><img src=pixx/spacer.gif width=4px height=4px /></td>" +
                                                "</tr>" +
                                                "<tr><td></td>" + 
                                                    "<td><img src=pixx/spacer.gif width=210px height=13px /></td>" + 
                                                    "<td</td>" + 
                                                "</tr>" + 
                                                "<tr><td><img src=pixx/spacer.gif width=4px height=4px /></td>" +
                                                    "<td><img src=pixx/spacer.gif width=212px height=4px /></td>" + 
                                                    "<td><img src=pixx/spacer.gif width=4px height=4px /></td>" +
                                                "</tr></table></td></tr></table>";
                                    }
                                s += "</td></tr>" +
                                "<tr><td colspan=3 class=findapro_results align=right>" + 
                                    "<a href=# onclick='dsEmailContractor(" + ds.Tables[0].Rows[i].bid + ");return false'><img src=pixx/btn_sendbyemail.gif class='domroll pixx/btn_sendbyemail_up.gif' border=0></a><img src=pixx/spacer.gif width=58px height=1px /><a href='#' onclick='dsShowMoreDetailFAP(" + 
                                    ds.Tables[0].Rows[i].bid + "," + dir + ");return false;'><img src='pixx/btn_moreinfo.gif' class='domroll pixx/btn_moreinfo_up.gif' alt='Show Full Details for this Contractor; including Contact Info, Scrollable Map, Job Types & Reference Scores..' border=0 /></a><BR /><img src=pixx/spacer.gif height=2px />" + 
                                "</td></tr></table>" +
                            "</td></tr></table></div>" + 
                            "<div id=FULL" + ds.Tables[0].Rows[i].bid + " style='display:none'></div>" + 
                        "</td>" + 
                        "<td class=box_form_right><img src=pixx/spacer.gif height=190px width=1px /></td>" + 
                    "</tr>" + 
                    "<tr><td class=box_form_end_left></td>" + 
                        "<td class=box_form_end_fill></td>" + 
                        "<td class=box_form_end_right></td>" + 
                    "</tr></table>" + 
                    "</td><td><div id=MAINR" + ds.Tables[0].Rows[i].bid + ">" + 
                        "<table width=100% cellspacing=0 cellpadding=0 align=center>" +
                        "<tr><td class=box_form_top_fill><img src=pixx/spacer.gif width=1px /></td>" + 
                            "<td class=box_form_top_right></td>" + 
                        "</tr></table>";
                        
                        if (ds.Tables[0].Rows[i].substatus == 1) {
                            s += "<table width=100% cellspacing=0 cellpadding=0 bgcolor=#eaeaef id=HIDEICONS2" + ds.Tables[0].Rows[i].bid + "><tr><td width=17px><div style='float:left;position:relative;left:226px;top:-13px;'><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",1,0);return false;'><img src='pixx/btn_expand.gif' class='domroll pixx/btn_expand_up.gif' alt='Click to find out what these icons represent..' border=0 /></a></div></td><td>" +                         
                            "<table width=100% cellspacing=0 cellpadding=0 align=center id=HIDEICONS" + ds.Tables[0].Rows[i].bid + ">" +
                            "<tr><td bgcolor=#eaeaef class=findapro_results id=ICONS" + ds.Tables[0].Rows[i].bid + ">" +                                
                                    "<table cellpadding=3 cellspacing=0 width=220px >" + 
                                    "<tr><td></td>";
                                    if (ds.Tables[0].Rows[i].fair == "YES") {
                                        s += "<td align=left width=34px><img src=pixx/logo_fairtrades.gif /></td>";
                                    }
                                    if (ds.Tables[0].Rows[i].trustmark == 1) {
                                        s += "<td align=left><img src=pixx/logo_trustmark.gif alt='TrustMark Approved'/></td>";
                                    }
                                    
                                    if (ds.Tables[0].Rows[i].refscore > 0) {
                                        s += "" + 
                                        "<td align=right class=refscore width=30px><table cellpadding=0 cellspacing=0><td width=16px><img src=pixx/gold_star.gif /></td><td width=16px><img src=pixx/gold_star.gif /></td><td width=16px><img src=pixx/gold_star.gif /></td>"; 
                                            
                                        switch(ds.Tables[0].Rows[i].refscore) {
                                            case 7:
                                                s += "<td width=16px><img src=pixx/gold_star_half.gif /></td><td width=16px><img src=pixx/gold_star_up.gif />";
                                            break;
                                            case 8:
                                                s += "<td width=16px><img src=pixx/gold_star.gif /></td><td width=16px><img src=pixx/gold_star_up.gif />";
                                            break;
                                            case 9:
                                                s += "<td width=16px><img src=pixx/gold_star.gif /></td><td width=16px><img src=pixx/gold_star_half.gif />";
                                            break;
                                            case 10:
                                                s += "<td width=16px><img src=pixx/gold_star.gif /></td><td width=16px><img src=pixx/gold_star.gif />";
                                            break;
                                            default :
                                                s += "<td width=16px><img src=pixx/gold_star_up.gif /></td><td width=16px><img src=pixx/gold_star_up.gif />";
                                            break;
                                        }    
                                                                       
                                        s +=     
                                            "</td><td width=17px><img src=pixx/spacer.gif width=17px /></td></tr><tr><td colspan=5>Ratings Score<img src=pixx/spacer.gif width=3px /></td><td></td></tr></table></td>";
                                    } else {
                                        s += "<td align=right class=findapro_results width=100px height=26px><b>Non-Member Contractor</b></td><td width=10px></td>";
                                    }
                                        
                                    s +=  "</tr></table>" + 
                                 "</td>" + 
                                 "<td class=box_form_right></td>" + 
                            "</tr></table></td></tr></table>";
                        }
                        
                        if (ds.Tables[0].Rows[i].substatus == 1) {
                            s += 
                                "<table width=100% cellspacing=0 cellpadding=0 align=center id='CHARTER" + ds.Tables[0].Rows[i].bid + "'>" +
                                "<tr><td class=box_form_top_fill><img src=pixx/spacer.gif width=236px height=1px /></td>" + 
                                    "<td class=box_form_right_tabbed></td>" + 
                                "</tr>" + 
                                "<tr><td bgcolor=#eaeaef class=findapro_results>" + 
                                         "<table cellpadding=3 cellspacing=0 width=236px>" + 
                                         "<tr><td width=2px>" + 
                                             "<div style='float:left;position:relative;left:223px;top:-10px;'><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",1,1);return false;',1><img src='pixx/btn_expand.gif' class='domroll pixx/btn_expand_up.gif' alt='Discover more about the Customer Charter..'  border=0 /></a></div>" +
                                         "</td><td align=left width=65%>Customers Charter?<BR /><BR /></td>" +                 
                                             "<td align=center><img src=pixx/checkbox3.gif /></td><td width=2px></td>" + 
                                         "</tr></table>" +     
                                     "</td>" + 
                                     "<td class=box_form_right></td>" + 
                                "</tr></table>" + 
                                "<table width=100% cellspacing=0 cellpadding=0 align=center id='LEGAL" + ds.Tables[0].Rows[i].bid + "'>" +
                                "<tr><td class=box_form_top_fill><img src=pixx/spacer.gif width=236px height=1px /></td>" + 
                                    "<td class=box_form_right_tabbed></td>" + 
                                "</tr>" + 
                                "<tr><td bgcolor=#eaeaef class=findapro_results>" + 
                                         "<table cellpadding=3 cellspacing=0 width=236px>" + 
                                         "<tr><td width=2px>" + 
                                             "<div style='float:left;position:relative;left:223px;top:-10px;'><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",1,2);return false;'><img src='pixx/btn_expand.gif' class='domroll pixx/btn_expand_up.gif' alt='Discover more about the Contractor Legal Checks..' border=0 /></a></div>" +                                 
                                             "</td><td align=left width=65%>Credit/Legal<BR />History Checked?</td>" +                 
                                             "<td align=center><img src=pixx/checkbox3.gif /></td><td width=2px></td>" + 
                                         "</tr></table>" +                                      
                                     "</td>" + 
                                     "<td class=box_form_right></td>" + 
                                "</tr></table>";
                        } else {
                            s += "<table width=100% cellspacing=0 cellpadding=0 align=center id='LEGAL" + ds.Tables[0].Rows[i].bid + "'>" +
                                "<tr><td bgcolor=#eaeaef class=findapro_results>" + 
                                         "<table cellpadding=3 cellspacing=0 width=236px>" + 
                                         "<tr><td width=2px>" + 
                                             "<div style='float:left;position:relative;left:223px;top:-10px;'><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",1,2);return false;'><img src='pixx/btn_expand.gif' class='domroll pixx/btn_expand_up.gif' alt='Discover more about the Contractor Legal Checks..' border=0 /></a></div>" +                                 
                                             "</td><td align=left width=65%>Credit/Legal<BR />History Checked?</td>" +                 
                                             "<td align=center><img src=pixx/checkbox3.gif /></td><td width=2px></td>" + 
                                         "</tr></table>" +                                      
                                     "</td>" + 
                                     "<td class=box_form_right></td>" + 
                                "</tr></table>" + 
                                "<table width=100% cellspacing=0 cellpadding=0 align=center id='CHARTER" + ds.Tables[0].Rows[i].bid + "'>" +
                                "<tr><td bgcolor=#eaeaef ><img src=pixx/spacer.gif width=236px height=88px /></td>" + 
                                    "<td class=box_form_right></td>" + 
                                "</tr></table>";
                        }

                        if (ds.Tables[0].Rows[i].applicable == 1 && ds.Tables[0].Rows[i].substatus == 1) {
                            s += "<table width=100% cellspacing=0 cellpadding=0 align=center id='PIBG" + ds.Tables[0].Rows[i].bid + "'>" +
                            "<tr><td class=box_form_top_fill><img src=pixx/spacer.gif width=236px height=1px /></td>" + 
                                "<td class=box_form_right_tabbed></td>" + 
                            "</tr>" + 
                            "<tr><td bgcolor=#eaeaef class=findapro_results>" + 
                                     "<table cellpadding=3 cellspacing=0 width=100%>" + 
                                     "<tr><td width=2px>" + 
                                         "<div style='float:left;position:relative;left:223px;top:-18px;'><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",1,3);return false;'><img src='pixx/btn_expand.gif' class='domroll pixx/btn_expand_up.gif' alt='Discover more about the Insurance Backed Guarantees..' border=0 /></a></div>" +                                 
                                         "</td><td align=left width=65%>";
                                         
                                         if (ds.Tables[0].Rows[i].applicable == 1 && ds.Tables[0].Rows[i].tb == "YES") {
                                            s += "Able to provide an Insurance Backed Guarantee From ";
                                         }
                                         if (ds.Tables[0].Rows[i].applicable == 1 && ds.Tables[0].Rows[i].tb == "NO") {
                                            s += "Able to have an Insurance Backed Guarantee Offered by ";
                                         }
                                         
                                         s += "</td>" +                 
                                         "<td align=center><a href='http://www.homeproinsurance.co.uk' target='_new'><img src=pixx/logo_homeproIns.gif border=0 /></a></td>" + 
                                     "</tr></table>" + 
                                 "</td>" + 
                                 "<td class=box_form_right></td>" + 
                            "</tr></table>";
                        } else {
                            s += "<table width=100% cellspacing=0 cellpadding=0 align=center id='PIBG" + ds.Tables[0].Rows[i].bid + "'>" +
                                "<tr><td bgcolor=#eaeaef ><img src=pixx/spacer.gif width=236px height=50px /></td>" + 
                                    "<td class=box_form_right></td>" + 
                                "</tr></table>";
                        }
                        
                        s += "<table width=100% cellspacing=0 cellpadding=0 align=center id='DETAIL" + ds.Tables[0].Rows[i].bid + "' style='display:none'>" +
                        "<tr><td bgcolor=#eaeaef class=findapro_results id='DETAILSPACER" + ds.Tables[0].Rows[i].bid + "' valign=top>" + 
                             "<table cellpadding=3 cellspacing=0 width=100%>" + 
                             "<tr><td width=10px></td>" + 
                                 "<td align=left id='INFOHERE" + ds.Tables[0].Rows[i].bid + "'>" +  

                                 "<div id='LEGALINFO" + ds.Tables[0].Rows[i].bid + "' style='display:none'>" + 
                                 "<table width=100% cellspacing=0 cellpadding=0><tr><td height=150px valign=top>This contractor has passed our credit and legal checks to ensure that they are of sound financial standing.<BR /><BR />We undertake these checks through some of the UKs largest credit checking agencies such as Dun & Bradstreet and Experian.." + 
                                 "</td></tr><tr><td align=right><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",0,0);return false;'><img src='pixx/btn_back.gif' class='domroll pixx/btn_back_up.gif' alt='Back To Normal View..' border=0 /></a></td></tr></table></div>" + 
                                
                                 "<div id='CHARTERINFO" + ds.Tables[0].Rows[i].bid + "' style='display:none'>" + 
                                 "<table width=100% cellspacing=0 cellpadding=0><tr><td height=150px valign=top>This contractor has committed to uphold our customers charter.<BR /><BR />This charter is a set of principles about how the company deals with customers, their works and how they runs their businesses.<BR /><BR />Click <a href='index.aspx?GO=PROTECTING&SUB=CHARTER'>here</a> to see the full charter.." + 
                                 "</td></tr><tr><td align=right><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",0,0);return false;'><img src='pixx/btn_back.gif' class='domroll pixx/btn_back_up.gif' alt='Back To Normal View..' border=0 /></a></td></tr></table></div>" + 
                                 
                                 "<div id='IBGINFO" + ds.Tables[0].Rows[i].bid + "' style='display:none'>" + 
                                 "<table width=100% cellspacing=0 cellpadding=0><tr><td height=150px valign=top class=small_expand>";

                                 if (ds.Tables[0].Rows[i].applicable == 1 && ds.Tables[0].Rows[i].tb == "YES") {
                                    s += "This contractor is a member of our Trade Bonus scheme and as such should be " +
                                        "able to provide an Insurance Backed Guarantee as standard on many of their works " + 
                                        "to protect your investment - ask them for details.  <BR /><BR />For more information on Insurance " + 
                                        "Backed Guarantees, click <a href='http://www.homeproinsurance.co.uk' target='_blank'>here</a> to visit homeproinsurance.co.uk.<BR /><BR />";                                    
                                 }
                                 if (ds.Tables[0].Rows[i].applicable == 1 && ds.Tables[0].Rows[i].tb == "NO") {
                                    s += "This contractor has arranged an Insurance Backed Guarantee facility with us " + 
                                        "to enable you to purchase a policy to protect your investment.  <BR /><BR />For more " + 
                                        "information on Insurance Backed Guarantees, click <a href='http://www.homeproinsurance.co.uk' target='_blank'>here</a> to visit homeproinsurance.co.uk.<BR /><BR />";
                                 }
                                 if (ds.Tables[0].Rows[i].trustmark == 1) {
                                    s += "Approved on the Trustmark scheme.";
                                 }
                                 
                                 s += "</td></tr><tr><td align=right><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",0,0);return false;'><img src='pixx/btn_back.gif' class='domroll pixx/btn_back_up.gif' alt='Back To Normal View..' border=0 /></a></td></tr></table></div>" + 
                                      "<div id='TOPINFO" + ds.Tables[0].Rows[i].bid + "' style='display:none'>" + 
                                      "<table width=100% cellspacing=0 cellpadding=0><tr><td height=150px valign=top class=small_expand>";
                                 
                                 if (ds.Tables[0].Rows[i].refscore > 0) {
                                    s += "This contractor has scored an average score of <b>" + ds.Tables[0].Rows[i].refscore + 
                                         "/10 </b>on previous customer references";                                   
                                 }
                                 if (ds.Tables[0].Rows[i].OKLastRef != null) {
                                    s += ", most recent reference obtained " + 
                                         ds.Tables[0].Rows[i].OKLastRef + ".<BR /><BR />"; 
                                 } else {
                                    s += ".<BR /><BR />";
                                 }
                                 if (ds.Tables[0].Rows[i].fair == "YES") {
                                    s += "This contractor is a member of the elite FairTrades trade association and " + 
                                         "will be able to confirm their identity and membership with their id card.<BR /><BR />";
                                 }
                                 if (ds.Tables[0].Rows[i].trustmark == 1) {
                                     s += "Approved on the Trustmark scheme.";
                                 }
                                 s += "</td></tr><tr><td align=right><a href=# onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",0,0);return false;'>" + 
                                      "<img src='pixx/btn_back.gif' class='domroll pixx/btn_back_up.gif' alt='Back To Normal View..' border=0 /></a></td></tr></table></div>" +
                                      "</td></tr></table>" + 
                             "</td>" + 
                             "<td class=box_form_right></td>" + 
                        "</tr></table>" + 
                        "<table width=100% cellspacing=0 cellpadding=0>" + 
                        "<tr><td class=box_form_end_fill height=11px><img src=pixx/spacer.gif width=10px height=1px /></td>" + 
                            "<td class=box_form_end_right width=11px></td>" + 
                        "</tr></table></div>" +        
                    "</td>" + 
                "</tr></table></td></tr></table><BR />";
        }   
        
        // display the results
        if (justSearched == "FAP") {
            document.getElementById("showResultsFAP").innerHTML = s + "<BR /><BR />";
            showHide("showResultsFAP", "showLoading");
        } else {
            document.getElementById("showResultsCMO").innerHTML = s + "<BR /><BR />";    
            showHide("showResultsCMO", "showLoading");
        }
        
        // start the testimonials ticker
        //window.setTimeout("rotateTestimonials()",5000);  
        interval = window.setInterval("rotateTestimonials()", 15);  
                
        // reset the domroll array
        domRollover();                   
    } else {  // no results found or error occurred
        if (justSearched == "FAP" ) {  // Find A Pro Errors
            var s =
                "<table width=495px cellspacing=0 cellpadding=0 align=center>" +
                "<tr><td class=box_form_top_left></td>" + 
                    "<td class=box_form_top_fill></td>" + 
                    "<td class=box_form_top_right></td>" + 
                "</tr>" + 
                "<tr><td class=box_form_left></td>" +
                    "<td bgcolor=#eaeaef class=findapro_results align=center><BR /><b>";
     
            switch(noerror) {
                case "POSTCODE2":
                    s += "Sorry that postcode is not recognised <BR/>Please try another postcode...<BR />";
                    break; 
                case "INVALID_MIN":
                    s += "Sorry, you have passed the maximum allowed<BR />searches in this time period (MINUTE) <BR/>" +
			            "Please try again later...<BR/>";
			        break; 
			    case "INVALID_DAY":
                    s += "Sorry, you have passed the maximum allowed<BR />searches in this time period (DAY)<BR/>" +
			            "Please try again later...<BR/>";
			        break; 
		        default : 
		            var tradetypebase = document.getElementById("fap_tradetype");
		            if (searchedCMO != 1) {
		            s += "Sorry at present we have no " + tradetypebase.options[tradetypebase.selectedIndex].text + 
                        " professionals in this area who have passed our rigorous " +
			            "vetting criteria";
			        
		            var trustmark = getQueryVariable("TRUSTMARK"); //get trustmark status
		            var tmPCode = getQueryVariable("FAP_POSTCODE"); //get trustmark postcode
                    if (typeof(trustmark) == "undefined") {
                        trustmark = "N";}
                    else {
                        s += " and are TrustMark approved"
                    }
			        
			        s += ".<BR /><BR />To search our vetted none TrustMark Approved database click " +
			            "<a href='index.aspx?GO=FINDAPRO&TRUSTMARK=N&FAP_POSTCODE=" + tmPCode + "' + title='Find a Pro'>here</a>" + "<BR />";}
			        else {
			        s += "Sorry, Your Search Returned No Results";
			        }
			        
			        break; 
            }

            s += 
                    "</b><BR /></td>" + 
                    "<td class=box_form_right></td>" + 
                "</tr>" + 
                "<tr><td class=box_form_end_left></td>" + 
                    "<td class=box_form_end_fill></td>" + 
                    "<td class=box_form_end_right></td>" + 
                "</tr></table><BR />";
            document.getElementById("showResultsFAP").innerHTML = s;
            showHide("showResultsFAP", "showLoading");
        } else {  // check me out errors
            document.getElementById("showResultsCMO").innerHTML =
                "<table width=495px cellspacing=0 cellpadding=0 align=center>" +
                "<tr><td class=box_form_top_left></td>" + 
                    "<td class=box_form_top_fill></td>" + 
                    "<td class=box_form_top_right></td>" + 
                "</tr>" + 
                "<tr><td class=box_form_left></td>" + 
                    "<td bgcolor=#eaeaef class=findapro_results align=center><BR /><b>" +
                        "Sorry, Your Search Returned No Results" +
                    "</b><BR /></td>" + 
                    "<td class=box_form_right></td>" + 
                "</tr>" + 
                "<tr><td class=box_form_end_left></td>" + 
                    "<td class=box_form_end_fill></td>" + 
                    "<td class=box_form_end_right></td>" + 
                "</tr></table><BR />";
            showHide("showResultsCMO", "showLoading");
        }
    }
    
    // show the disclaimer
    document.getElementById("FAPdisclaimer").style.display = "block";
}

// rotate testimonials
var interval = null;
function rotateTestimonials() {
    if (testimonLen.length > 0) {
        for (var i=0; i<testimonLen.length; i++)  { 
            if (testimonPos[i] < (testimonLen[i] * -5)) {
                document.getElementById("testIg" + i).style.left = "0px";
                testimonPos[i] = 0;
            } else {
                testimonPos[i] -= 1;
                document.getElementById("testIg" + i).style.left = testimonPos[i] + "px";
            }            
        }
        //window.setTimeout("rotateTestimonials()",35);         
    } else {
        if (interval != null) {
            clearInterval(interval);
			interval=null;
        }
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////
// PRELOAD IMAGES
////////////////////////////////////////////////////////////////////////////////////////////////

// preload the main images used for the FAP/CMO
function preLoadImages() {
    var pre_img_names = new Array(
        'pixx/box_main_top_left.gif',
        'pixx/box_main_top_fill.gif',
        'pixx/box_main_top_right.gif',
        'pixx/box_main_left.gif',
        'pixx/box_main_right.gif',
        'pixx/box_main_end_left.gif',
        'pixx/box_main_end_fill.gif',
        'pixx/box_main_end_right.gif',
        'pixx/box_form_top_left3.gif',
        'pixx/box_form_top_fill3.gif',
        'pixx/box_form_top_right3.gif',
        'pixx/box_form_left2.gif',
        'pixx/box_form_left_tabbed2.gif',
        'pixx/box_form_right_tabbed2.gif',
        'pixx/box_form_right2.gif',
        'pixx/box_form_end_left3.gif',
        'pixx/box_form_end_fill3.gif',
        'pixx/box_form_end_right3.gif',
        'pixx/directory_hightlight3.gif',
        'pixx/directory_hightlight_big2.gif',
        'pixx/gold_star.gif',
        'pixx/gold_star_up.gif',
        'pixx/gold_star_half.gif'
    );
    var pre_img = new Array();

    for (var i = 0; i < pre_img_names.length; i++) {
        pre_img[i] = new Image();
        pre_img[i].src = pre_img_names[i];
    } 
}

////////////////////////////////////////////////////////////////////////////////////////////////
// LOGIN FUNX
////////////////////////////////////////////////////////////////////////////////////////////////

// check for login @ startup
function checkForLogin() {
    var loginName = getCookie("HOMEPRO_LOGIN");
    if (loginName != null && loginName != "") {
        document.getElementById("LOGINNAME").innerHTML = "<b>" + splitMe(loginName,11) + "</b>";
        document.getElementById("URARNTLOGGEDIN").style.display = "none";
        document.getElementById("URLOGGEDIN").style.display = "block";  
    }
}

// log user in/out
function logInOut(inorout) {
    if (inorout == "IN") { // show login box      
        document.getElementById("login_newuser").style.display = "none";
        document.getElementById("login_lostpass").style.display = "none";
        document.getElementById("login_main").style.display = "block";        
        document.getElementById("disableMAINContent").style.display = "block";
        document.getElementById("SIGNUP_NEWUSER").style.display = "block";
        document.getElementById("SIGNUP_EDIT").style.display = "none";
        
        try { document.getElementById("login_pcode").value = document.getElementById("fap_pcode").value; } catch(e) {}
        document.getElementById("login_email").value = "";
        
        try { document.getElementById("HIDETRADESELECT").style.display = "none"; } catch(e) {}
        if ((currON == "FAP" && searchedFAP == 1) || (currON == "CMO" && searchedCMO == 1))  {
            document.getElementById("disableMAINContent").style.height = "3140px";
        } else {
            document.getElementById("disableMAINContent").style.height = "977px";
        }
        document.getElementById("showLOGIN").style.display = "block";
        window.scroll(0,0);
        document.getElementById("login_email").focus();
        loginOPEN = 1;
    } else {  // log user out
        setCookie("HOMEPRO_LOGIN","");
        document.getElementById("URARNTLOGGEDIN").style.display = "block";
        document.getElementById("URLOGGEDIN").style.display = "none";    
        document.getElementById("LOGINNAME").innerHTML = "";
        loginOPEN = 0;
    }
}

// actually log user in
function dsProcessLoginNFO() {    
    var email = document.getElementById("login_email").value;
    var pcode = document.getElementById("login_pcode").value;
    if ((email != "" || email.length >= 5) && (pcode != "" || pcode.length >= 5)) {
        index.dsProcessLoginNFO(email, pcode, callback_dsProcessLoginNFO);
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginproc.gif";   
    } else { // show errors
        if (email == "" || email.length < 5) {
            document.getElementById("login_email").style.borderColor = "RED";
        } else {
            document.getElementById("login_email").style.borderColor = "BLACK";
        }
        if (pcode == "" || pcode.length < 5) {
            document.getElementById("login_pcode").style.borderColor = "RED";
        } else {
            document.getElementById("login_pcode").style.borderColor = "BLACK";
        }
    }
}

function callback_dsProcessLoginNFO(res) {  
    // check for login failure    
    if (res.value == "NaN" || res.value == null) { 
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginfail.gif";   
        document.getElementById("login_pcode").focus();
    } else { 
        // revert form from diabled state
        try {document.getElementById("HIDETRADESELECT").style.display = "block";} catch(e) {}
        //document.getElementById("HIDETRADESELECT").style.display = "block";
        try {document.getElementById("HIDETRADESELECT").style.display = "block";} catch(e) {}
        document.getElementById("disableMAINContent").style.display = "none";
        document.getElementById("showLOGIN").style.display = "none";
    
        // save to cookies
        setCookie("HOMEPRO_LOGIN",res.value);
        setCookie("HOMEPRO_ID",document.getElementById("login_email").value);
        setCookie("HOMEPRO_PCODE",document.getElementById("login_pcode").value);
        
        // show user logged in
        document.getElementById("LOGINNAME").innerHTML = "<b>" + splitMe(res.value,11) + "</b>";
        document.getElementById("URARNTLOGGEDIN").style.display = "none";
        document.getElementById("URLOGGEDIN").style.display = "block";   
        
        // continue previous action
        if (openWhich != -1) {
            dsShowMoreDetailFAP(openWhich, openDir);
        } 
        loginOPEN = 0;
    }
}

// cancel login
function cancel_login() {
    if (document.getElementById("login_newuser").style.display == "block" && editOPEN == 0) {        
        document.getElementById("login_newuser").style.display = "none";        
        document.getElementById("login_main").style.display = "block";        
    } else {
        try {document.getElementById("HIDETRADESELECT").style.display = "block";} catch(e) {}
        document.getElementById("disableMAINContent").style.display = "none";
        document.getElementById("showLOGIN").style.display = "none";
    }
    document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_login.gif";
    editOPEN = 0;
    loginOPEN = 0;
}

// setup edit user, same form as signup
function dsEditAccount() {    
    index.dsEditAccount(getCookie("HOMEPRO_ID"), callback_dsEditAccount);
}

function callback_dsEditAccount(res) {  
    var ds = res.value;

    if (ds != null && typeof(ds) == "object" && ds.Tables != null)  {
        // fill in the account fields
        document.getElementById("signup_title").value = ds.Tables[0].Rows[0].title;
        document.getElementById("signup_fname").value = ds.Tables[0].Rows[0].contactFName;
        document.getElementById("signup_lname").value = ds.Tables[0].Rows[0].contactLName;
        document.getElementById("signup_email").value = ds.Tables[0].Rows[0].email;
        document.getElementById("signup_pcode").value = ds.Tables[0].Rows[0].pcode;
        document.getElementById("signup_house").value = ds.Tables[0].Rows[0].address;
        document.getElementById("signup_newsletter").value = ds.Tables[0].Rows[0].subscribe;
        document.getElementById("signup_privacy2").value = ds.Tables[0].Rows[0].privacy2;
        document.getElementById("signup_privacy1").value = ds.Tables[0].Rows[0].privacy1;
        document.getElementById("signup_terms").checked = true;

        // show the edit acc form (or modified signup screen
        document.getElementById("HIDETRADESELECT").style.display = "none";
        document.getElementById("login_newuser").style.display = "block";
        document.getElementById("login_lostpass").style.display = "none";
        document.getElementById("login_main").style.display = "none";        
        document.getElementById("disableMAINContent").style.display = "block";
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginedit.gif";
        document.getElementById("SIGNUP_NEWUSER").style.display = "none";
        document.getElementById("SIGNUP_EDIT").style.display = "block";
        document.getElementById("showLOGIN").style.display = "block";
        window.scroll(0,0);
        editOPEN = 1;
        document.getElementById("showLoginTicks").style.display = "block";
        document.getElementById("signup_email").focus();
    } else {
        alert("Unable to Edit your Account at this time, please RETRY later..");
    }
}

// setup new user form
function signup_newuser() {
    document.getElementById("login_newuser").style.display = "block";
    document.getElementById("login_main").style.display = "none";
    document.getElementById("showLoginTicks").style.display = "none";
    document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginsign.gif";
    
    if (document.getElementById("login_pcode").value != "") {
        document.getElementById("signup_pcode").value = document.getElementById("login_pcode").value;
    }
    if (document.getElementById("login_email").value != "") {
        document.getElementById("signup_email").value = document.getElementById("login_email").value;
    }
}

// actually signup new usr
function dsSignUpNewUser() {    
    var title = document.getElementById("signup_title").value;
    var fname = document.getElementById("signup_fname").value;
    var lname = document.getElementById("signup_lname").value;
    var email = document.getElementById("signup_email").value;
    var pcode = document.getElementById("signup_pcode").value;
    var house = document.getElementById("signup_house").value;
    var phone = document.getElementById("signup_phone").value;
    var news = document.getElementById("signup_newsletter").checked;
    var privacy2 = document.getElementById("signup_privacy2").checked;
    var privacy1 = document.getElementById("signup_privacy1").checked;
    var terms = document.getElementById("signup_terms").checked; 
        
    if ((email != "" || email.length >= 5) && (pcode != "" || pcode.length >= 5) && (terms == true)) { 
        index.dsSignUpNewUser(title, fname, lname, house, pcode, phone, email, news, privacy2, privacy1, callback_dsSignUpNewUser);
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginproc.gif";   
    } else { // show errors
        if (email == "" || email.length < 5) {
            document.getElementById("signup_email").style.borderColor = "RED";
        } else {
            document.getElementById("signup_email").style.borderColor = "";
        }
        if (pcode == "" || pcode.length < 5) {
            document.getElementById("signup_pcode").style.borderColor = "RED";
        } else {
            document.getElementById("signup_pcode").style.borderColor = "";
        }
        if (terms != true) {
            document.getElementById("signup_termsHERE").style.backgroundColor = "RED";
        } else {
            document.getElementById("signup_termsHERE").style.backgroundColor = "#eaeaef";
        }
    }
}

function callback_dsSignUpNewUser(res) {  
    if (res.value != "OK") {
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginsign.gif";  
        alert("New User SignUp FAILED, Please Retry Later..");
        document.getElementById("HIDETRADESELECT").style.display = "block";
        document.getElementById("disableMAINContent").style.display = "none";
        document.getElementById("showLOGIN").style.display = "none";
    } else {
        document.getElementById("login_pcode").value = document.getElementById("signup_pcode").value;
        document.getElementById("login_email").value = document.getElementById("signup_email").value;
        document.getElementById("login_newuser").style.display = "none";
        document.getElementById("login_main").style.display = "block";   
        dsProcessLoginNFO();
    }
}

// show the lost password screen
function showPassRecovery() {
    document.getElementById("login_main").style.display = "none";  
    document.getElementById("login_lostpass").style.display = "block";
    document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginpass.gif";    
    document.getElementById("lostpass_email").focus();
}

// cancel the pass recover
function cancelPssRecovery() {
    document.getElementById("login_main").style.display = "block";  
    document.getElementById("login_lostpass").style.display = "none"; 
    document.getElementById("login_lostpass_result").style.display = "none";  
    document.getElementById("login_lostpass_resultfail").style.display = "none";  
    document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_login.gif";  
    document.getElementById("login_email").focus();
}

// back 2 pass recover
function back2PssRecovery() {
    document.getElementById("login_lostpass").style.display = "block";  
    document.getElementById("login_lostpass_result").style.display = "none";  
    document.getElementById("login_lostpass_resultfail").style.display = "none"; 
    document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginpass.gif";  
    document.getElementById("lostpass_email").focus(); 
}

// actually recover password
function dsRecoverPss() {    
    var email = document.getElementById("lostpass_email").value;   
    if (email != "" || email.length >= 5) { 
        index.dsRecoverPss(email, callback_dsRecoverPss);
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginproc.gif";   
    } else { // show errors
        document.getElementById("lostpass_email").style.borderColor = "RED";
        document.getElementById("lostpass_email").focus();
    }
}

function callback_dsRecoverPss(res) {  
    if (res.value != "NaN") {
        document.getElementById("login_pcode").value = res.value;
        document.getElementById("login_email").value = document.getElementById("lostpass_email").value;
        document.getElementById("login_lostpass").style.display = "none";

        document.getElementById("login_lostpass_resultEmail").innerHTML = document.getElementById("lostpass_email").value;
        document.getElementById("login_lostpass_resultPCode").innerHTML = res.value;

        document.getElementById("login_lostpass_result").style.display = "block";
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginpok.gif";   
    } else {  // show not found
        document.getElementById("login_lostpass").style.display = "none";
        document.getElementById("login_lostpass_resultfail").style.display = "block";
        document.getElementById("LOGIN_HEADER").src = "pixx/box_form_toolbox_loginpfail.gif";   
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////
// EMAIL WRAPPER FUNX
////////////////////////////////////////////////////////////////////////////////////////////////
function dsEmailContractor(bid) {  
    var loginName = getCookie("HOMEPRO_LOGIN");
    if (loginName != null && loginName != "") {
        var id=getCookie("HOMEPRO_ID");
        var pcode=getCookie("HOMEPRO_PCODE");
        var name=getCookie("HOMEPRO_LOGIN");
        index.dsEmailContractor(bid, id, name, pcode, callback_dsEmailContractor);
    } else { //show login
        logInOut("IN");
    }
}

function callback_dsEmailContractor(res) { 
    if (res.value == "NOTOK" || res.value == null) { 
        alert("There is a problem with Our Email system, please retry later..");
    } else { 
        alert("Contact Detail for " + res.value + " has been sent to your Address..");
    }
}

function dsSendProjectFeedback() {  
    var title = document.getElementById("feedback_title").value;    
    var surname = document.getElementById("feedback_surname").value;
    var house = document.getElementById("feedback_house").value;
    var postcode = document.getElementById("feedback_postcode").value;
    var email = document.getElementById("feedback_email").value;
    var feedback = document.getElementById("feedback_feedback").value;
    
    if (title != "" && surname != "" && house != "" && postcode != "" && email != "" && feedback != "") {        
        index.dsSendProjectFeedback(title, surname, house, postcode, email, feedback, callback_dsSendProjectFeedback);
    } else {
        alert("Please Fill in ALL required Fields..");
    }
}

function callback_dsSendProjectFeedback(res) { 
    if (res.value == "NOTOK" || res.value == null) { 
        alert("There is a problem with Our Email system, please retry later..");
        document.getElementById("feedback_title").focus();
    } else { 
        alert("Your Project Feebback has been Received by HomePro..");
        document.getElementById("feedback_title").value = "";
        document.getElementById("feedback_surname").value = "";
        document.getElementById("feedback_house").value = "";
        postcode = document.getElementById("feedback_postcode").value = "";
        email = document.getElementById("feedback_email").value = "";
        feedback = document.getElementById("feedback_feedback").value = "";
        document.getElementById("feedback_title").focus();
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////
// COOKIE FUNX
////////////////////////////////////////////////////////////////////////////////////////////////

// setCookieEx wrapper 
function setCookie(name, value) {
	var now = new Date();
	//fixDate(now);	// fix the bug in Navigator 2.0, Macintosh

	/*	cookie expires in one year (actually, 365 days)
	365 days in a year
	24 hours in a day
	60 minutes in an hour
	60 seconds in a minute
	1000 milliseconds in a second	*/

	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookieEx(name, value, now);
}

// write cookie
function setCookieEx(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// get cookie value
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// delete cookie
//function deleteCookie(name, path, domain) {
//  if (getCookie(name)) {
//    document.cookie = name + "=" +
//    ((path) ? "; path=" + path : "") +
//    ((domain) ? "; domain=" + domain : "") +
//    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
//  }
//}

// fix date issues
//function fixDate(date) {
//  var base = new Date(0);
//  var skew = base.getTime();
//  if (skew > 0)
//    date.setTime(date.getTime() - skew);
//}

////////////////////////////////////////////////////////////////////////////////////////////////
// POPUP WINDOW
////////////////////////////////////////////////////////////////////////////////////////////////
function NewWindow(mypage,myname,w,h,scroll){
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/4 : 0;
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',menubar=yes,toolbar=yes,status=yes,location=yes,resizable=yes'
    win = window.open(mypage,myname,settings)
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=530,height=300,left = 400,top = 362');");
}

////////////////////////////////////////////////////////////////////////////////////////////////
// STARTUP
////////////////////////////////////////////////////////////////////////////////////////////////
function startupp(whichPage) {
    if (whichPage != "") {
        currTAB = whichPage;
    }
    if ((whichPage == "") || (whichPage == "FINDAPRO") || (whichPage == "CHECKMEOUT")) {
        //dsGetTradeList();
        preLoadImages();
    }
    checkForLogin();
    
    // check for startup params
	var showThis="";
	var searchME = new String(document.location)
	var inn=searchME.indexOf("?");
	if (inn > 0) {
		var tobesplit = searchME.substring(inn + 1);
		var splitME = tobesplit.split("&");
		showThis = splitME[0].slice(3);
		if (showThis == "FINDAPRO" || showThis == "AtoZ" || showThis == "CHECKMEOUT" ) {
		    document.getElementById("showFindAProMenu").style.display = "block";
		    document.getElementById("FAPpage_content").style.display = "block";
            document.getElementById("frontpage_content").style.display = "none";
		}
	}
}

//debugger;


///////////////////////////////////
// ACTIVE CONTENT
///////////////////////////////////
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//gets/returns querystring, pass in the variable name
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  variable = ""; //returns blank if the variable is not found
}
