﻿try {
    YAHOO.namespace("integrate");
} catch ( e) {

}

String.prototype.trim = function()
{
    return( this.replace(new RegExp("^([\\s]+)|([\\s]+)$", "gm"), "") );
}

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string)).replace(/\+/gi, "%2B");
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    }

};

function setClass(d, c) {
    var divB = YAHOO.util.Dom.get(d);
    if (divB.className == c) return;
    divB.setAttribute("className", c);
    divB.setAttribute("class", c);
}

var gUserID = 0;

//////////////////////////////////////////////////////////////////////////////////

var boxEmail = false;
var boxPassword = false;

function focusbox(e,b) {
    if (!b) {
        e.value = '';
        e.style.color = 'black'
    }
}

function blurbox(e,b,t,c) {
    if (!b) {
        e.style.color = c;
        e.value = t;
    }
}

//////////////////////////////////////////////////////////////////////////////////


 function getSingleNode(xml, node) {
     return xml.getElementsByTagName(node).item(0).firstChild.nodeValue;
 }
 

 function addEl(parent, type, atts) {
     switch (type.toLowerCase()) {
         case "hidden":
             type = document.createElement("INPUT");
             type.setAttribute("type", "hidden");
             break;
         case "textbox": case "text":
             type = document.createElement("INPUT");
             type.setAttribute("type", "text");
             break;
         case "checkbox":
             type = document.createElement("INPUT");
             type.setAttribute("type", "checkbox");
             break;
         case "button":
             type = document.createElement("INPUT");
             type.setAttribute("type", "button");
             break;
         case "submit":
             type = document.createElement("INPUT");
             type.setAttribute("type", "submit");
             break;
         case "radio":
             if (YAHOO.env.ua.ie)
                 type = document.createElement("<input type='radio' name='" + type + "'/>");
             else {
                 type = document.createElement("input");
                 type.setAttribute("type", "radio");
             }
             break;
         case "tr":
             type = parent.insertRow(parent.rows.length);
             break;
         case "td":
             type = parent.insertCell(parent.cells.length);
             break;
         default:
             type = document.createElement(type);
     }
     for (var i in atts)
         switch (i.toLowerCase()) {
         case "style":
             var s = atts[i].split(";");
             var g = '';
             for (var j = 0; j < s.length; j++) {
                 g = s[j].split(":");

                 if (g[0] == "float")
                     g[0] = document.all ? "styleFloat" : "cssFloat"
                 if (g[0].indexOf("-") > -1) {
                     g[0] = g[0].substr(0, g[0].indexOf("-")) + g[0].charAt(g[0].indexOf("-") + 1).toUpperCase() + g[0].substr(g[0].indexOf("-") + 2);
                 }
                 try { type.style[g[0]] = g[1]; }
                 catch (e) {}
             }
             break;
         case "class":
             type.className = atts[i];
             break;
         case "text":
             type[document.all ? "innerText" : "textContent"] = atts[i];
             break;
         case "for":
             type.setAttribute("for", atts[i]);
             break;
         default:
             type[i] = atts[i];
     }

     if (type.tagName != "TR" && type.tagName != "TD") {
         parent.appendChild(type);
     }

     return type
 };

 function getCookie(name) {
     var start = document.cookie.indexOf(name + "=");
     var len = start + name.length + 1;
     if ((!start) && (name != document.cookie.substring(0, name.length)))
         return null;
     if (start == -1) return null;
     var end = document.cookie.indexOf(';', len);
     if (end == -1) end = document.cookie.length;
     return unescape(document.cookie.substring(len, end));
 }

 function setCookie(name, value, expires, path, domain, secure) {
     var today = new Date();
     today.setTime(today.getTime());
     if (expires)
         expires = expires * 1000 * 60 * 60 * 24;
     var expires_date = new Date(today.getTime() + (expires));
     document.cookie = name + '=' + escape(value) +
			((path) ? ';path=' + path : '') +
			((expires) ? ';expires=' + expires_date.toGMTString() : '') +
			';domain=integrate.com' +
			((secure) ? ';secure' : '');

 }

function modalDraw(w) {
    var h = '<div id="gPanel" ><Table cellpadding=0 cellspacing=0 border=0 width=' + w + '><Tr><Td class="menu_img menu_img_pop_topleft"></td><Td class="menu_img menu_img_pop_top"></td><Td class="menu_img menu_img_pop_topright"></td></tr>'
    h += '<tr><Td class="menu_img menu_img_pop_side"></td><Td style="background:url(/images/overlay_bg2.jpg) no-repeat;background-color:#084270;width:' + (w - 20) + 'px">'

    h += '<div style="padding:10px;float:right"><a href="javascript:modalHide();"><img src="/images/x.png"></a></div><br clear="all">'
    h += '<div id="gPanelC"></div>';

    h += '</td><Td class="menu_img menu_img_pop_side"></td></tr>'
    h += '<Tr><Td class="menu_img menu_img_pop_bottomleft"></td><Td class="menu_img menu_img_pop_top"></td><Td class="menu_img menu_img_pop_bottomright"></td></tr></table></div>'

    return(h)
}

function modalInit(e, w) {
    YAHOO.integrate.panel1 = new YAHOO.widget.Panel("iPanel", {
         //fixedcenter: true,
         zindex: 4,
         modal: true,
         visible: false,
         draggable: false,
         underlay: false,
         close: false
     });

     YAHOO.integrate.panel1.setBody(modalDraw(w));
     YAHOO.integrate.panel1.render(document.body);
     

 }

 function modalShow() {
     YAHOO.integrate.panel1.center();
     YAHOO.integrate.panel1.show();
 }

 function modalHide() {
     YAHOO.util.Dom.get('gPanelC').innerHTML = ''
     YAHOO.integrate.panel1.hide();
 }

 function RollOvers(i) {

     if (i == 0 || i == 1 ) {
         YAHOO.util.Event.addListener("ctl00_tabHome", "mouseover", function() { document.images['ctl00_tabHome'].src = '/images/tab_home_off_RO.png' });
         YAHOO.util.Event.addListener("ctl00_tabHome", "mouseout", function() { document.images['ctl00_tabHome'].src = '/images/tab_home_off.png' });
     }

     if (i == 0 || i == 4) {
         YAHOO.util.Event.addListener("ctl00_tabBuyer", "mouseover", function() { document.images['ctl00_tabBuyer'].src = '/images/tab_buyer_off_RO.png' });
         YAHOO.util.Event.addListener("ctl00_tabBuyer", "mouseout", function() { document.images['ctl00_tabBuyer'].src = '/images/tab_buyer_off.png' });
     }

     if (i == 0 || i == 2 || i == 4) {
         YAHOO.util.Event.addListener("ctl00_tabSeller", "mouseover", function() { document.images['ctl00_tabSeller'].src = '/images/tab_seller_off_RO.png' });
         YAHOO.util.Event.addListener("ctl00_tabSeller", "mouseout", function() { document.images['ctl00_tabSeller'].src = '/images/tab_seller_off.png' });
     }

     if (i == 2) {
         YAHOO.util.Event.addListener("ctl00_tabHome", "mouseover", function() { document.images['ctl00_tabHome'].src = '/images/tab_home_buyer_RO.png?v=2' });
         YAHOO.util.Event.addListener("ctl00_tabHome", "mouseout", function() { document.images['ctl00_tabHome'].src = '/images/tab_home_buyer.png' });
     }

     if (i == 1) {
         YAHOO.util.Event.addListener("ctl00_tabBuyer", "mouseover", function() { document.images['ctl00_tabBuyer'].src = '/images/tab_buyer_seller_RO.png' });
         YAHOO.util.Event.addListener("ctl00_tabBuyer", "mouseout", function() { document.images['ctl00_tabBuyer'].src = '/images/tab_buyer_seller.png' });
     }


 }


 var oForgot = {

     handleSuccess: function(o) {
         this.processResult(o);
     },

     handleFailure: function(o) {
         ShowFError('Unable to process request. Please try again.')

     },

     processResult: function(o) {
         try {
             var ret = o.responseXML.getElementsByTagName("return")
             var result = getSingleNode(ret[0], "result");
             var error = getSingleNode(ret[0], "error");
         }

         catch (e) {
             ShowFError('Unable to process request. Please try again.');
             return
         }

         if (result == "0") {
             ShowFError(error);

         } else {
             alert('Password sent successfully.')
             modalHide();
         }

     },

     startRequest: function(e) {
         var str = "?e=" + Url.encode(e)

         YAHOO.util.Connect.asyncRequest('GET', "/api/forgot.aspx" + str, cbForgot);
     }

 };

 var cbForgot =
 {
     success: oForgot.handleSuccess,
     failure: oForgot.handleFailure,
     scope: oForgot
 };

 function CheckForgot() {
     var email = YAHOO.util.Dom.get('idfemail').value;

     if (email == '') {
         alert('Please enter your email address.')
     }
     else {
         var div = YAHOO.util.Dom.get('divWait');
         div.innerHTML = "<div style='float:left;padding-left:10px'><img src='/images/ajax-loader.gif'></div><div style='float:left;padding-left:10px;padding-top:10px' class=white>Please Wait</div><br clear=all>"
         oForgot.startRequest(email);

     }
 }
 function Forgot() {
     var div = YAHOO.util.Dom.get('gPanelC');

     var h = '<div style="float:left;padding:5px 10px 0px 10px"><img src="/images/logo_sm.png"></div>'

     h += '<div style="float:left;padding:5px 10px 20px 0px;font-size:13pt" class="white"><B style="font-size:14pt">Forgot Password?</B></div>'

     h += "<br clear='all'>"

     h += "<div style='padding:0px 15px 0px 20px' class=white>"

     h += "Please enter the email address associated with your account and click the [SUBMIT] button. Your password will be emailed to the address on record.<Br><br>"

     h += "<div style='float:left'><B>Email Address:</B> <input type=text maxlength=100 id=idfemail></div>"

     h += "<div style='float:left;margin-left:10px' id='divWait'><div class='btn blue' onclick='CheckForgot()'>Submit</div></div>"

     h += "<br clear='all'>"
     
     h += "</div>"

     h += "<Br><Br>"
     div.innerHTML = h;
     modalShow();

 }

 function ShowFError(e) {
     alert(e);

     var div = YAHOO.util.Dom.get('divWait');
     div.innerHTML = "<div class='btn blue' onclick='CheckForgot()'>Submit</div>"

 }


 YAHOO.util.Event.addListener(window, "load", modalInit, 620);

 YAHOO.util.Event.onContentReady("productsandservices", function() {


     var oMenuBar = new YAHOO.widget.MenuBar("productsandservices", {
         autosubmenudisplay: true,
         hidedelay: 750,
         lazyload: true
     });


     oMenuBar.render();

 });