﻿
function ClearEO() {
    try {
        var allDiv = document.getElementsByTagName("div");
        for (var i = 0; i < allDiv.length; i++) {
            if (allDiv[i].id.indexOf("trial") >= 0) {
                allDiv[i].style.display = "None";
            }
        }
    }
    catch (e) {
    }
}

function ShowContentByAjax(url, divContent)
{
     var myDate = new Date();
     var req = new RequestObj("GET");
     var randomnumber = Math.floor(Math.random() * 100);
     //req.URL = url + "?t=" + myDate.getMilliseconds() + randomnumber;
     req.URL = url;
     req.AddParam("t", myDate.getMilliseconds().toString() + randomnumber.toString());
	 var ajax = new AjaxObj(req,divContent);
	 ajax.Call();
}

function ConvertStringToXML(sXMLData) {
    try {
        if (sXMLData == "") return null;
        
        if (window.ActiveXObject) {
            //for IE
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(sXMLData);
            return xmlDoc;
        } else if (document.implementation && document.implementation.createDocument) {
            //for Mozila
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(sXMLData, "text/xml");
            return xmlDoc;
        } else {
            //alert('Your browser can\'t handle this script');
            return null;
        }
    } catch (Error) {
        return null;
    }
}

function addCommas(nStr) {
    nStr = replaceComma(nStr, ",");
    nStr += '';
    x = nStr.split(',');
    x1 = x[0];
    x2 = x.length > 1 ? ',' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function replaceComma(nStr, ch) {
    while (nStr.indexOf(ch, 0) > 0) {
        nStr = nStr.replace(ch, "");
    }
    return nStr;
}

function GetValueFromNode(obj, field) {
    return obj.getElementsByTagName(field)[0].firstChild.nodeValue;
}

function SetValue(clientID, value) {
    YAHOO.util.Dom.get(clientID).innerHTML = value;
}

function SetNumberValue(clientID, value) {
    YAHOO.util.Dom.get(clientID).innerHTML = addCommas(value.toString());
}

function ChangeObjColor(clientID, myColor) {
    YAHOO.util.Dom.get(clientID).style.color = myColor;
}

function ChangeObjClass(clientID, className) {
    YAHOO.util.Dom.get(clientID).className = className;
}

function ChangeBackground(clientID, color) {
    YAHOO.util.Dom.get(clientID).style.background = color;
}

function SetNewValue(clientID, value) {
    SetValue(clientID, value);
    ChangeBackground(clientID, '');
}

function ChangeBackgroundAndValue(clientID, color, value) {
    YAHOO.util.Dom.get(clientID).style.background = color;
    setTimeout("SetNewValue('" + clientID + "', '" + value + "')", 2000);
}

function SetValueHightLight(clientID, value) {
    var obj = YAHOO.util.Dom.get(clientID);
    var valueOld = obj.innerHTML;
    
    if (valueOld != null && valueOld != value) {        
        ChangeBackground(clientID, '#faeea6');
        setTimeout("ChangeBackground('" + clientID + "', '')", 2000);
        obj.innerHTML = value;
    }
}

function SetValueNumberHightLight(clientID, value) {
    var obj = YAHOO.util.Dom.get(clientID);
    var valueOld = obj.innerHTML;
    var valueNew = addCommas(value.toString());

    if (valueOld != null && valueOld != valueNew) {
        ChangeBackground(clientID, '#faeea6');
        setTimeout("ChangeBackground('" + clientID + "', '')", 2000);
        obj.innerHTML = valueNew;
        //ChangeBackgroundAndValue(clientID, '#faeea6', valueNew);
    }
}

function ChangePriceCSS(price1, price2) {
    if (price2 == 0) return " refcolor ";
    else if (price2 < price1) return " redcolor ";
    else if (price2 == price1) return " refcolor ";
    else return " greencolor ";
}

function GetPriceColor(price1, price2) {
    if (price2 == 0) return "#000000";
    else if (price2 < price1) return "#ca0102";
    else if (price2 == price1) return "#000000";
    else return "#066606";
}

function HightLightLink24K(id) {
    var obj = YAHOO.util.Dom.get(id);
    ChangeBackground(id, '#faeea6');
    setTimeout("ChangeBackground('" + id + "', '')", 3000);
    var valueOld = obj.innerHTML;
}

function replaceChar(nStr, ch) {
    while (nStr.indexOf(ch, 0) > 0) {
        nStr = nStr.replace(ch, "");
    }
    return nStr;
}
