////////////////////////////////////////////////////////////////////////////////////////////////
// CAPTURE THE ENTER PRESS
////////////////////////////////////////////////////////////////////////////////////////////////
var currTAB = "CHECKMEOUT";
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 = "CMO";
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";
        }
    }
}


function GetRadWindow() {

    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
} 


////////////////////////////////////////////////////////////////////////////////////////////////
// EMAIL WRAPPER FUNX
////////////////////////////////////////////////////////////////////////////////////////////////

function dsRequestCallBack() {  
    var title = document.getElementById("enqire_title").value;    
    var surname = document.getElementById("enqire_surname").value;
    var house = document.getElementById("enqire_house").value;
    var postcode = document.getElementById("enqire_postcode").value;
    var email = document.getElementById("enqire_email").value;
    var detail = document.getElementById("enqire_detail").value;
    
    if (title != "" && surname != "" && house != "" && postcode != "" && email != "" && detail != "") {        
        index.dsRequestCallBack(title, surname, house, postcode, email, detail, callback_dsRequestCallBack);
    } else {
        alert("Please Fill in ALL required Fields..");
    }
}

function callback_dsRequestCallBack(res) { 
    if (res.value == "NOTOK" || res.value == null) { 
        alert("There is a problem with Our Email system, please retry later...");
        document.getElementById("enqire_title").focus();
    } else { 
        alert("Your Information Request has been received by IPWFI");
        document.getElementById("enqire_title").value = "";
        document.getElementById("enqire_surname").value = "";
        document.getElementById("enqire_house").value = "";
        postcode = document.getElementById("enqire_postcode").value = "";
        email = document.getElementById("enqire_email").value = "";
        feedback = document.getElementById("enqire_detail").value = "";
        document.getElementById("enqire_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);
//}


///////////////////////////////////
// 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
}



////////////////////////////////////////////////////////////////////////////////////////////////
// IBG REFERENCE
////////////////////////////////////////////////////////////////////////////////////////////////
function getText(id) {
    var x=document.getElementById(id);
    return x.options[x.selectedIndex].text;
}
function dsIBGReference()  {
    whichBID = -1;
    var policyId = stripToInt(document.getElementById("IBG_POLICYID").value);
    var pcode = document.getElementById("IBG_PCODE").value;
    var email = document.getElementById("IBG_EMAIL").value;
    var homeproemail = document.getElementById("IBG_HOMEPROMAIL").value;
    var conemail = document.getElementById("IBG_CONMAIL").value;
    var quality = getText("IBG_QUALITY");
    var time = getText("IBG_TIME");
    var courtesy = getText("IBG_COURTESY");
    var value = getText("IBG_VALUE");
    //var contractvalue = stripToFloat(document.getElementById("IBG_CONTRACTVALUE").value);
     var contractvalue = document.getElementById("IBG_CONTRACTVALUE").value;
    var recommend = getText("IBG_RECOMMENDED");
    var testimonial = document.getElementById("IBG_TESTIMONIAL").value;
    var enddate = getText("IBG_DAY") + "/" + getText("IBG_MONTH") + "/" + getText("IBG_YEAR");
    var valdate = getText("IBG_MONTH") + "/" + getText("IBG_DAY") + "/" + getText("IBG_YEAR");

    if (policyId.length >= 6) {
        if (pcode.length >= 2) {
            if (email.length > 0) { 
                if (IsDecimal(contractvalue)) {         
                        if (isValidDate(valdate,"MM/DD/YYYY")) { 
                            showHide("IBGRef_LOADING","IBGRef_STEP1");
                            window.scroll(0,0);
                            index.dsIBGReference(policyId, pcode, contractvalue, email, homeproemail, conemail, quality, time, courtesy, value, recommend, testimonial, enddate, callback_dsIBGReference);  
                        } else {
                            alert("Please ensure you have entered a valid project completion date.");
                        }
                } else {
                    alert("Please ensure you have entered the contract value in full e.g 515.00");
                }
            } else {
                alert("Please ensure you have entered the return email in full.");
            }
        } else {
            alert("Please ensure you have entered the postcode in full.");
        }
    } else {
        alert("Please ensure you have entered the policy number in full.");
    } 
}

function callback_dsIBGReference(res) {//alert(res.value);
    showHide("IBGRef_DONE","IBGRef_LOADING");
    switch (res.value) {
    case "OK":
        document.getElementById("IBG_Result").innerHTML = "Thank you, your reference has been received and your IBG Policy is now active, this will be confirmed by email, please keep this for your records.";
    break;
    case "DuplicateRef":
        document.getElementById("IBG_Result").innerHTML = "Thank you, your reference has been received but has been rejected as this IBG Policy has had a reference created already.  If this is in error please click <a href=index.aspx?GO=CONTACT class=defaultLink>here</a> to contact Homepro Insurance for further information. <BR /><BR />Alternativly, click <a href=index.aspx?GO=IBGREF class=defaultLink>here</a> to retry.";
    break;
    case "PolicyNotFound":
        document.getElementById("IBG_Result").innerHTML = "Sorry, we are unable to find an IBG Policy matching the certificate number and post code.  If this is in error please click <a href=index.aspx?GO=CONTACT class=defaultLink>here</a> to contact Homepro Insurance for further information. <BR /><BR />Alternativly, click <a href=index.aspx?GO=IBGREF class=defaultLink>here</a> to retry.";
    break;    
    case "30DAYLIMIT":
        document.getElementById("IBG_Result").innerHTML = "Sorry, but the IBG Reference MUST be submitted within 30days of taking out the Policy, see Terms & Conditions.  If this is in error please click <a href=index.aspx?GO=CONTACT class=defaultLink>here</a> to contact Homepro Insurance for further information. <BR /><BR />Alternativly, click <a href=index.aspx?GO=IBGREF class=defaultLink>here</a> to retry.";
    break; 
    case "EmailIssue":
        document.getElementById("IBG_Result").innerHTML = "Although your policy is now confirmed, we were unable to send you an email confirmation at this time.  If you require more information please click <a href=index.aspx?GO=CONTACT class=defaultLink>here</a> to contact Homepro Insurance. <BR /><BR />";
    break; 
    case "":
        document.getElementById("IBG_Result").innerHTML = "Sorry, we are unable to process your Reference at this time, please try again later.  <BR /><BR />Click <a href=index.aspx?GO=IBGREF class=defaultLink>here</a> to retry.";
    break;    
    }   
}


function isEMailAddr(str) {
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Verify the e-mail address format.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}

function stripToInt(val) {
    var ret="";
    for (j=0;j<val.length;j++)
    {
        c=val.charAt(j);
        if(c>=0 && c<=9)
        {
        ret+=c;
        }
    } 
    
    return ret;
} 

function stripToFloat(val) {
    var ret="";
    for (j=0;j<val.length;j++)
    {
        c=val.charAt(j);
        if ((c>=0 && c<=9) || (c == 46))
        {
            ret+=c;
        }
    } 
    
    return ret;
} 

function IsDecimal(str)
{
	mystring = str;
	if (mystring.match(/^\d+\.\d{2}$/ ) ) {
		return true;
	}
	else
	{
	return false;
	}
}

// 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";
	}
}

function isValidDate(dateStr, format)
{

//check if 2nd parameter contains valid value or not
//if not valid then set default format = “MDY”
if (format == null) { format = "MDY" }
format = format.toUpperCase();
if (format.length != 3) { format = "MDY" }
if ( (format.indexOf("M") == -1) ||
(format.indexOf("D") == -1) ||
(format.indexOf("Y") == -1)
)
{ format = "MDY" }

if (format.substring(0, 1) == "Y")
{ // If the year is first
var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
}
else if (format.substring(1, 2) == "Y")
{ // If the year is second
var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
}
else
{ // The year must be third
var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
}

// If it doesn’t conform to the right format
//(with either a 2 digit year or 4 digit year), fail
if ( (reg1.test(dateStr) == false) &&
(reg2.test(dateStr) == false)
)
{ return false; }

// Split into 3 parts based on what the divider was
var parts = dateStr.split(RegExp.$1);

// Check to see if the 3 parts end up making a valid date
//extract month part
if (format.substring(0, 1) == "M") { var mm = parts[0]; }
else if (format.substring(1, 2) == "M") { var mm = parts[1]; }
else { var mm = parts[2]; }

//extract day part
if (format.substring(0, 1) == "D") { var dd = parts[0]; }
else if (format.substring(1, 2) == "D") { var dd = parts[1]; }
else { var dd = parts[2]; }

//extract Year part
if (format.substring(0, 1) == "Y") { var yy = parts[0]; }
else if (format.substring(1, 2) == "Y") { var yy = parts[1]; }
else { var yy = parts[2]; }

//if year is in 2 digit
//00-49 are assumed to be 21st century and 50-99 are assumed to be 20th century
if (parseFloat(yy) <= 50)
{ yy = (parseFloat(yy) + 2000).toString(); }
if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }

var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);

if (parseFloat(dd) != dt.getDate()) { return false; }

if (parseFloat(mm)-1 != dt.getMonth()) { return false; }

return true;

}



////////////////////////////////////////////////////////////////////////////////////////////////
// PURCHASE IBG FUNX
////////////////////////////////////////////////////////////////////////////////////////////////
// grab detail of IBG policy
var purchaseStep = "";
var newpolicy_BID = "-1";

function dsPurchaseIBG() {
    // check enter wasnt ment for login
    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 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

            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 = "";
                }
            }
            index.dsPurchaseIBG_FillTradeList(policyId, callback_dsPurchaseIBG_FillTradeList);
        } //got records
    }
    else {
        alert("Record not found, please check your details.");
    }
}

function submit_Step1() {
    //gets the price ready for SecPay
        //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(newpolicy_BID, 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("Missing required fields :\n" + failReason);
        }
    
}

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");
            document.getElementById("IBG_POLICYID").value = ds.Tables[0].Rows[0].proposalid;

            // 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
                var sQtr
                //sQtr = "https://www.homepro.com/secure.aspx?"
                //                sQtr = "http://localhost:2125/homepro.net3.5/secure.aspx?"
//                sQtr += "PAYADD1=" + document.getElementById("bil_addr_1").value;
//                sQtr += "&PAYADD2=" + document.getElementById("bil_addr_2").value;
//                sQtr += "&PAYCITY=" + document.getElementById("bil_city").value;
//                sQtr += "&PAYPOSTCODE=" + document.getElementById("bil_post_code").value;
//                sQtr += "&PAYPHONE=" + document.getElementById("bil_tel").value;
//                sQtr += "&PAYEMAIL=" + document.getElementById("bil_email").value;
//                sQtr += "&TOTALAMOUNT=" + ds.Tables[0].Rows[0].retailPrice.substr(1, (ds.Tables[0].Rows[0].retailPrice.length - 1));
//                sQtr += "&PAYORDER=" + document.getElementById("IBG_POLICYID").value;
//                sQtr += "&PAYID=" + document.getElementById("IBG_POLICYID").value;
//                sQtr += "&PAYNAME=" + document.getElementById("bil_name").value;

                                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;

                switchReadOnly(false); //switch inputs back on so form can function
               // document.location.href = sQtr

                // ***OLD CODE***
                // no document.getElementById("digest").value = str_md5(document.getElementById("trans_id").value + document.getElementById("amount").value + "gBhjf3F\k")
                // no alert(document.getElementById("digest").value)';
                                document.frmIndex.action = "https://www.secpay.com/java-bin/ValCard";    
                                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 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 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 0:

            break;
        case 1:
            dsPurchaseIBG();
            break;
        case 2:
            submit_Step1();
            break;
        case 3:
            dsPurchaseIBG();
            break;
        default:
            //dsPurchaseIBG();
            break;
    }
    return false;
}

function submit_NewPolicy() {
    whichBID = -1;
    purchaseStep = "0";
    showHide("PurchaseIBG_STEP0", "PurchaseIBG_STEP1a");
}

function submit_NewPolicySearch() {
    // check enter wasnt ment for login
    whichBID = -1;
    var bid = document.getElementById("IBG_NEWPOL_BID").value;
    var cname = document.getElementById("IBG_NEWPOL_CNAME").value;
    var pcode = document.getElementById("IBG_NEWPOL_PCODE").value;
    var town = document.getElementById("IBG_NEWPOL_TOWN").value;
    var tel = document.getElementById("IBG_NEWPOL_TEL").value;

    if ((bid.length >= 3) || (cname.length >= 3)) {
        purchaseStep = "1";
        showHide("PurchaseIBG_LOADING", "PurchaseIBG_STEP0");
        index.dsNewPolicySearch(bid, cname, pcode, town, tel, callback_submit_NewPolicySearch);
    } else {
        alert("Please ensure you have entered Company ID or partial Company Name.");
    }
}

function callback_submit_NewPolicySearch(res) {
    var ds = res.value;
    if (ds != null && typeof (ds) == "object" && ds.Tables != null) {
        var bFirst = " checked";
        var s = "<table width='100%' cellpadding=0 cellspacing=2>" +
            "<tr><td class=main_text bgcolor=#eaeaef colspan=2><b>If the company that performed your work is below then select and submit to continue, otherwise please try again with different detail.</b></td></tr>";
        if (ds.Tables[0].Rows.length > 0) {
            newpolicy_BID = ds.Tables[0].Rows[0].bid;
        } else {
            newpolicy_BID = -1;
        }
        //s += "<tr><td colspan=2></td></tr><tr><td align=right colspan=2><a href=\"javascript:submit_NewPolicyConSelected();\"><img src=pixx/btn_submit.gif border=0 class=\"domroll pixx/btn_submit_up.gif\" /></a></td></tr>";

        for (var i = 0; i < ds.Tables[0].Rows.length; i++) {
            s += "<tr><td colspan='2' align='center'><hr width='85%' noshade size='2' style='color:#c23c42;'></td></tr>";
            
            s += "<tr><td><table width='100%' cellpadding=0 cellspacing=0>" +
                "<tr><td colspan=2 align='center'><b>" + ds.Tables[0].Rows[i].businessname + "</b></td></tr>" +
                "<tr><td>" + ds.Tables[0].Rows[i].PROPNAME + "</td><td align=right>" + ds.Tables[0].Rows[i].PHONE + "</td></tr>" +
                "<tr><td colspan=2>" + ds.Tables[0].Rows[i].address1 + "-" + ds.Tables[0].Rows[i].address4 + "</td></tr>" +
                "<tr><td colspan=2>" + ds.Tables[0].Rows[i].TRADEDESC + "</td></tr>" +
                "<tr><td colspan=2>&nbsp;</td></tr></table>" +
                "</td><td><input onmouseover=this.style.cursor='pointer'; title='Select this company' type=radio name=IBG_NEWPOL_WHICHBID value=" + ds.Tables[0].Rows[i].bid + bFirst + " onclick=\"newpolicy_BID = " + ds.Tables[0].Rows[i].bid + ";\"></tr>";
            bFirst = "";
        }
        s += "<tr><td align=right colspan=2><a href=\"javascript:submit_NewPolicyConSelected();\"><img src=pixx/btn_submit.gif border=0 class=\"domroll pixx/btn_submit_up.gif\" /></a></td></tr></table>";
        document.getElementById("step0Results").innerHTML = s;
        showHide("PurchaseIBG_STEP0", "PurchaseIBG_LOADING");
        domRollover();
        index.dsPurchaseIBG_FillTradeList(-1, callback_dsPurchaseIBG_FillTradeList);
    }
}

function submit_NewPolicyConSelected() {
    //newpolicy_BID = getRadioValue(document.getElementById("IBG_NEWPOL_WHICHBID"));
    //alert(newpolicy_BID);
    //alert(document.getElementById("IBG_NEWPOL_WHICHBID"));
    //alert(this.form.IBG_NEWPOL_WHICHBID);
    showHide("PurchaseIBG_STEP2", "PurchaseIBG_STEP0");
    showHide("PurchaseIBG_STEP3", "PurchaseIBG_STEP0");
}

//function getRadioValue(radioObject) {
//    var value = null;
//    for (var i = 0; i < radioObject.length; i++) {
//        if (radioObject[i].checked) {
//            value = radioObject[i].value;
//            break;
//        }
//    }
//    return value;
//}
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;
}

//-------------------------------------------------------------------
// 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("FULL" + which).style.display = "block";
    document.getElementById("FULL" + which).innerHTML =
            "<table width=473px 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>";

    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 />" +
                            "Timeliness : " + ds.Tables[0].Rows[0].ref2 + "/10<BR />" +
                            "Courtesy : " + 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 += "</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>&nbsp;</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;

            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("FULL" + which).style.display = "none";
        document.getElementById("EXPAND" + which).style.height = "122px";
        document.getElementById("EXPAND" + which).style.width = "190px";

        whichBID = -1;

    } else {  // hide tha map
        showHideMap(0, whichBID);
    }
}

// expand info tabs on the left
function expandLeftTabs(bid, expand, whichText) {
    if (expand == 1) { // expand
        try { document.getElementById("FINANCE" + bid).style.display = "none"; } catch (e) { }
        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 = "90px";

        // add relevent text
        switch (whichText) {
            case 0:
                document.getElementById("TOPINFO" + bid).style.display = "block";
                break;
            case 3:
                document.getElementById("IBGINFO" + bid).style.display = "block";
                break;
            case 4:
                document.getElementById("FINANCEINFO" + bid).style.display = "block";
                break;
        }
    } else { // revert
        try { document.getElementById("DETAIL" + bid).style.display = "none"; } catch (e) { }
        try { document.getElementById("FINANCE" + bid).style.display = "block"; } catch (e) { }
        try { document.getElementById("PIBG" + bid).style.display = "block"; } catch (e) { }
        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("FINANCEINFO" + 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;
}


////////////////////////////////////////////////////////////////////////////////////////////////
// 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 > 2) {
            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++) {
          
                s += "<table border='0' align='center'><tr><td>";
                dir = 0;
           
            s +=
                "<table width=495px cellspacing=0 cellpadding=0 align=center valign='top'>" +
                "<tr><td width=50%>" +
                    "<table width=100% cellspacing=0 cellpadding=0>" +
                    "<tr><td class=box_form_top_left><img src=pixx/spacer.gif height=11px width=11px /></td>" +
                        "<td class=box_form_top_fill></td>" +
                        "<td class=box_form_top_right><img src=pixx/spacer.gif height=11px width=11px /></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=20px width=1px /></td>" + //25px
                                "<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=102px 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 + "" +
                                            "<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>"          

            s += "</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>&nbsp;</td>" + //<img src=pixx/spacer.gif height=190px width=1px />
                    "</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>";      

                s += "<table width=100% cellspacing=0 cellpadding=0 align=center id='FINANCE" + ds.Tables[0].Rows[i].bid + "'>" +
                                "<tr><td bgcolor=#eaeaef class=findapro_results>" +
                                         "<table onmouseover=this.style.color='#bc0422' onmouseout=this.style.color='black' style='cursor:pointer;' onclick='javascript:expandLeftTabs(" + ds.Tables[0].Rows[i].bid + ",1,4);return false;' 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,4);return false;'><img src='pixx/btn_expand.gif' class='domroll pixx/btn_expand_up.gif' alt='Discover more about financing your project...' border=0 /></a></div>" +
                                             "</td><td align=left width=65%>Finance my project?</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>";
           

            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;'></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><img src=pixx/logo_ipwfi.gif border=0 /></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='FINANCEINFO" + ds.Tables[0].Rows[i].bid + "' style='display:none'>" +
                                 "<table width=100% cellspacing=0 cellpadding=0><tr><td height=90px valign=top>Our HomePro Money division will source the most affordable finance option for your project.<br/><br/>Click <a href='http://www.homepromoney.co.uk/Index.aspx?GO=HOMEOWNERS'>here</a> for details." +
                                 "</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=90px valign=top class=small_expand>";

         
            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 />For more " +
                                        "information on Insurance Backed Guarantees, click <a href='index.aspx?GO=GUARANTEE' target='_blank'>here</a> for details.";
            }
       
            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=90px valign=top class=small_expand>";

         
            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=3px height=1px /></td>" +
                            "<td class=box_form_end_right width=11px></td>" +
                        "</tr></table></div>" +
                    "</td>" +
                "</tr></table></td></tr></table>";
        }

        // 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/><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/><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 /><br/>";
                    }
                    else {
                        s += "Sorry, Your Search Returned No Results";
                    }

                    break;
            }

            s +=
                    "</b></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>";
            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>";
            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];
    }
}