﻿// JScript File

function loadF() {
    SetCaptcha();
    document.getElementById("form1").attributes["action"].value = document.getElementById("form1").attributes["action"].ownerDocument.URL; //document.getElementById("form1").attributes["action"].baseURI;        
    //window.scrollTo(0,0) ;
    return false;
}
function NewWindow(url, vHeight, vWidth) {
    winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
    winDef = winDef.concat('top=').concat((screen.height - vHeight) / 2).concat(',');
    winDef = winDef.concat('left=').concat((screen.width - vWidth) / 2);
    newWin = window.open(url, '_blank', winDef);
    newWin.focus();
}
function Counter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit.value) {
        field.value = field.value.substring(0, maxlimit.value);
    }
    else {
        countfield.value = maxlimit.value - field.value.length;
    }
}
function ToggleDisplay(id) {
    var elem = document.getElementById(id);

    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}
function CleanFrom() {
    document.getElementById("form1").reset();
    return false;
}


function PrintSubject() {
    w = open();
    w.document.writeln('<html>');
    w.document.writeln('<head>');
    w.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
    w.document.writeln('<link rel="stylesheet" href="./App_Themes/Default/Default.css" type="text/css">');
    w.document.writeln('</head>');
    w.document.writeln('<body topmargin=3 leftmargin=0 marginheight=3 marginwidth=0>');
    w.document.writeln('<table cellspacing=0 cellpadding=0 border=0 width=600 align=center>');
    w.document.writeln('<tr>');
    w.document.writeln('<td colspan="2" >');
    w.document.writeln(document.getElementById('Banner').innerHTML);
    w.document.writeln('</td>');
    w.document.writeln('</tr>');
    w.document.writeln('<tr>');
    w.document.writeln('<td  >');
    w.document.writeln(document.getElementById('Content').outerHTML);
    w.document.writeln('<a onclick="javascript:window.print();" style=" cursor:pointer" class="VNVN_17_UC_FOOTER_Print">');
    w.document.writeln('<img src="../Images/icon_printthispage.jpg" />');
    w.document.writeln('  Print this page');
    w.document.writeln('</a></td>');
    w.document.writeln('<td  style="padding-left:15px;" class="VNVN_17_UC_PRODUCT_DETAIL_Text">');
    w.document.writeln(document.getElementById('Content1').outerHTML);
    w.document.writeln('</td>');
    w.document.writeln('</tr>');
    w.document.writeln('<tr>');
    w.document.writeln('<td colspan="2">');
    w.document.writeln(document.getElementById('Footer').outerHTML);
    w.document.writeln('</td>');
    w.document.writeln('</tr>');
    w.document.writeln('</table>');
    w.document.writeln('</body>');
    w.document.writeln('</html>');
    w.document.title = document.title;
    w.document.close();
}


PositionX = 100;
PositionY = 15;
// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth = 100;
defaultHeight = 100;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
    var isNN = (navigator.appName == "Netscape") ? 1 : 0;
    var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
}
var optNN = 'resizable=yes,scrollbars=yes,width=' + defaultWidth + ',height=' + defaultHeight + ',left=' + PositionX + ',top=' + PositionY;
var optIE = 'resizable=yes,scrollbars=yes,width=300,height=250,left=' + PositionX + ',top=' + PositionY;
function popImage(imageURL, imageTitle, smallimage) {
    if (imageTitle == '') imageTitle = 'Popup Image';
    imgWin = open();
    //    if (isNN){imgWin=window.open('about:blank','',optNN);}
    //    if (isIE){imgWin=window.open('about:blank','',optIE);}
    imgWin.document.writeln('<html>');
    imgWin.document.writeln('<head>');
    imgWin.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>');
    imgWin.document.writeln('<title>Loading...</title><style>body{margin:0px;} img{padding:5px;cursor:pointer;display: block;}</style>');
    imgWin.document.writeln('<sc' + 'ript type="text/javascript">');
    imgWin.document.writeln('function DisplayImage(stringid,sPath,sPath2){');
    imgWin.document.writeln('var s_Image=document.getElementById("img_Product");');
    imgWin.document.writeln('if(s_Image!=null){s_Image.src=sPath2; sPath2=sPath2.replace("../","");s_Image.width= sPath2.split(".")[0].split("_")[sPath2.split(".")[0].split("_").length - 1].split("x")[0]; s_Image.height= sPath2.split(".")[0].split("_")[sPath2.split(".")[0].split("_").length - 1].split("x")[1]; }');
    imgWin.document.writeln('}</sc' + 'ript>');
    imgWin.document.writeln('</head>');
    imgWin.document.writeln('<body ><center>');
    imgWin.document.writeln('<div id="Zone" style="position:fixed; top:0px; left:0px; visibility:hidden; width:100%; height:100%"></div><table>');
    imgWin.document.writeln('<tr><td style = "padding-right:20px;vertical-align:top;">');
    imgWin.document.writeln('<input type="button" id="Close" border="0" value="Close" onclick="javascript:self.close();"/><br/>');
    imgWin.document.writeln(document.getElementById("Product_pnl_Image").innerHTML);
    imageURL = imageURL.replace('../', '');
    imgWin.document.writeln('</td><td>');
    imgWin.document.writeln('<img id="img_Product" border="0" alt="' + imageTitle + '" src="../' + imageURL + '" width="' + imageURL.split('.')[0].split('_')[imageURL.split('.')[0].split('_').length - 1].split('x')[0] + '" height="' + imageURL.split('.')[0].split('_')[imageURL.split('.')[0].split('_').length - 1].split('x')[1] + '" /></td></tr></table>');
    //writeln('<div style="text-align:center;margin-bottom:20px 0px;background-color:#d2d7d0;font-family:tahoma;font-size:11px">' + document.getElementById("BoxFooter2").innerHTML + "</div>" );
    imgWin.document.writeln('</center></body>');
    imgWin.document.writeln('</html>');
    imgWin.document.close();

}


function popProduct(imageDesignURL, imageFrameUrl, imageTitle) {
    if (imageTitle == '') imageTitle = 'Popup Image';
    if (isNN) { imgWin = window.open('about:blank', '', optNN); }
    if (isIE) { imgWin = window.open('about:blank', '', optIE); }
    with (imgWin.document) {
        writeln('<html><head><title>Loading...</title><link href="../App_Themes/default/Default.css" rel="stylesheet" type="text/css" /><link href="App_Themes/default/Default.css" rel="stylesheet" type="text/css" /><style>body{margin:0px;}</style>'); writeln('<sc' + 'ript>');
        writeln('var isNN,isIE;'); writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
        writeln('isNN=(navigator.appName=="Netscape")?1:0;'); writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
        writeln('function reSizeToImage(){'); writeln('if (isIE){'); writeln('window.resizeTo(100,100);');
        writeln('width=(document.images[0].width-document.body.clientWidth)+100;');
        writeln('height=(document.images[0].height-document.body.clientHeight)+100;');
        writeln('window.resizeBy(width,height);}'); writeln('if (isNN){');
        writeln('window.innerWidth=document.images["George"].width+100;'); writeln('window.innerHeight=document.images["George"].height+100;}}');
        writeln('function doTitle(){document.title="' + imageTitle + '";}');
        writeln('function innitFrame(){if(document.forms[0]["George"].width>document.images["George"].height){document.forms[0]["Frame"].width=document.forms[0]["George"].width+10;document.forms[0]["Frame"].height=document.images["George"].height+5;}else{document.forms[0]["Frame"].width=document.forms[0]["George"].width+10;document.forms[0]["Frame"].height=document.images["George"].height+8;}}');
        writeln('</sc' + 'ript>');
        if (!AutoClose) writeln('</head><body bgcolor=#fff0e7 scroll="no" onload="reSizeToImage();doTitle();self.focus();innitFrame();">')
        else writeln('</head><body bgcolor=#fff0e7 scroll="no" onload="reSizeToImage();doTitle();self.focus();innitFrame();" >');
        writeln('<form id="form1" runat="server">');
        writeln('<table cellspacing="20px;" width="100%" border="0"><tr style="width:100%"><td style="width:10px;"></td><td style="width:100%">');
        writeln('<div id="examplematScript" >');
        writeln('<img id="George" name="George" src=' + imageDesignURL + ' alt="" />');
        writeln('</div>');
        writeln('<div id="exampleframe">');
        writeln('<img id="Frame" name="Frame" src=' + imageFrameUrl + ' alt="' + imageTitle + '" width="javascript:document.images[0].width" height="javascript:document.images[0].height" />');
        writeln('</div>');


        writeln('</br>');
        writeln('<div onclick="javascript:self.close();" style="text-align:center"><a href="#">Close</a></div>');
        writeln('</td><td style="width:10px;"></td></tr></table>');
        writeln('</form>');
        writeln('</body></html>');
        close();
    }
}

function getDataTotbState(id1, id2) {
    var obj = document.getElementById(id1);
    var tb = document.getElementById(id2);
    tb.value = obj.options[obj.selectedIndex].innerHTML;
}

var optionsArr = null;

function ddl_Singer_OnChange(ddl, ctrlDDL, index, voteNumber) {
    if (!ddl) ddl = document.getElementById(ctrlDDL + 0);
    if (!optionsArr) {
        optionsArr = {};
        for (var i = 0; i < ddl.options.length; i++) {
            var item = ddl.options[i];
            optionsArr[item.value] = { text: item.innerHTML, choose: false };
        }
        for (var i = 0; i < voteNumber; i++) {
            var curDDL = document.getElementById(ctrlDDL + i);
            var value = curDDL.value;
            if (optionsArr[value].choose) {
                for (var v in optionsArr)
                    if (!optionsArr[v].choose) value = v;
            }
            optionsArr[value].choose = true;
            curDDL.value = value;
            curDDL.oldValue = value;
        }
    }

    var oldValue = ddl.oldValue;
    var newValue = ddl.value;
    if (oldValue != null) optionsArr[oldValue].choose = false;
    if (newValue != null) {
        optionsArr[newValue].choose = true;
        ddl.oldValue = newValue;
    }
    for (var i = 0; i < voteNumber; i++) {
        if (i == index)
            continue;
        var curDDL = document.getElementById(ctrlDDL + i);
        var value = curDDL.value;
        curDDL.innerHTML = "";
        for (var v in optionsArr) {
            var item = optionsArr[v];
            if (!item.choose || v == value) {
                var opt = document.createElement("OPTION");
                curDDL.options.add(opt);
                opt.value = v;
                opt.innerHTML = item.text;
            }
        }
        if (value)
            curDDL.value = value;
    }
}
function DisplayDate(stringid, sPath) {
    var objArticle_Date1 = new calendar2(document.getElementById(stringid));
    objArticle_Date1.year_scroll = true;
    objArticle_Date1.time_comp = false;
    objArticle_Date1.popup("", sPath);
}

function DisplayImage(id, ddl, sPath2) {
    var s_Image = document.getElementById("Product_img_Product");
    if (s_Image != null && ddl == "") {
        s_Image.src = id;
    }
    else {
        var path = '../App_Themes/' + ddl.options[ddl.options.selectedIndex].value + '/images/Default.jpg';
        $(id).src = path;
        $(id).style.display = '';

    }
}


function PrintOrder() {
    w = open();
    w.document.writeln('<html>');
    w.document.writeln('<head>');
    w.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
    w.document.writeln('<link rel="stylesheet" href="../App_Themes/Default/Default.css" type="text/css">');
    w.document.writeln('<style>body{background-image:none;} td,span,a,a:hover {font-size:12px} #Print{ display: none;} .VNVN_20_CSS_Tracking_Value,.VNVN_20_CSS_BillingShipping_Info_Value,.ShoppingCart_Total,.VNVN_20_CSS_BillingShipping_Info_Title ,.VNVN_20_CSS_Tracking_Title {font-size:12px;} body{background-color:#fff;color:#000;font-size:11px;font-family:tahoma }.VNVN_17_UC_FOOTER_Text {color:#000}</style>  ');
    w.document.writeln('</head>');
    w.document.writeln('<body topmargin=3 leftmargin=0 marginheight=3 marginwidth=0>');
    w.document.writeln('<table cellspacing=0 cellpadding=0 border=0 width=600 align=center>');
    w.document.writeln('<tr>');
    w.document.writeln('<td colspan="2" >');
    w.document.writeln('<img src="../Images/bannerPrint.jpg"  />');
    w.document.writeln('</td>');
    w.document.writeln('</tr>');
    w.document.writeln('<tr>');
    w.document.writeln('<td  >');
    w.document.writeln(document.getElementById('dvContainFullOrder').innerHTML);
    w.document.writeln('<a onclick="javascript:window.print();" style=" cursor:pointer;" class="VNVN_17_UC_FOOTER_Print">');
    w.document.writeln('<img src="../Images/icon_printthispage.jpg" style="cursor:pointer;" />');
    w.document.writeln('  Print this page');
    w.document.writeln('</a></td>');
    w.document.writeln('</tr>');
    w.document.writeln('<tr>');
    w.document.writeln('<td colspan="2" style="padding-top:10px;">');
    w.document.writeln(document.getElementById('Footer').innerHTML);
    w.document.writeln('</td>');
    w.document.writeln('</tr>');
    w.document.writeln('</table>');
    w.document.writeln('</body>');
    w.document.writeln('</html>');
    w.document.title = document.title;
    w.document.close();
    return false;
}

function bookmarksite(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}

function OpenWindow(Url) {
    window.open(Url);
}

function DisableControl(o, event) {
    if (Page_ClientValidate("Continue")) {
        OnPleaseWait("AdminDvWait", event);
        o.style.display = 'none';
        if ($('oneStep_txt_s_7') && $('oneStep_txt_s_7').value == '') {
            $('oneStep_txt_s_7').value = $('oneStep_cmb_s_7').options[$('oneStep_cmb_s_7').selectedIndex].text;
        }
        else {
            if ($('txt_s_7') && $('cmb_s_7') && $('txt_s_7').value == '') {
                $('txt_s_7').value = $('cmb_s_7').options[$('cmb_s_7').selectedIndex].text;
            }
        }
    }
}
function OnPleaseWait(sCtrID, event) {
    var ctrWait = document.getElementById(sCtrID); //findTheDivByID    
    if (ctrWait != null && event != null) {
        ctrWait.style.display = "block";
        var y = event.clientY + document.documentElement.scrollTop;
        if (event.clientY == 0)
            ctrWait.style.top = y + 200 + "px";
        else
            ctrWait.style.top = y + "px";
        if (event.clientX == 0)
            ctrWait.style.left = event.clientX + 300 + document.documentElement.scrollLeft + "px";
        else
            ctrWait.style.left = event.clientX + document.documentElement.scrollLeft + "px";
    }
}
//=========================================================================
// Off Please wait...
//=========================================================================
function OffPleaseWait(sCtrID) {
    var ctrWait = document.getElementById(sCtrID);
    ctrWait.style.display = "none";
}
function $(element) {
    if (arguments.length > 1) {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
            elements.push($(arguments[i]));
        return elements;
    }
    if (typeof element == 'string')
        element = document.getElementById(element);
    return Element.extend(element);
}


var ListAdvertise = {};
function ChangeBannerAdvertise(id, time) {
    var arr = ListAdvertise[id];
    var imgObj = document.getElementById(id);

    if (arr.length > 0 && imgObj) {
        var index = imgObj.curIndex;
        if (!index || index >= arr.length) index = 0;

        var curImg = arr[index++];
        if (curImg != null) {
            if (curImg[0].indexOf('<') < 0)
                imgObj.innerHTML = "<img src='" + curImg[0] + "' alt='" + curImg[2] + "'>";
            else
                imgObj.innerHTML = curImg[0];
            imgObj.lnk = curImg[1];
            imgObj.curIndex = index;
            setTimeout("ChangeBannerAdvertise('" + id + "', " + time + ")", time);
        }
    }
}


function loadProductBox(sArr, ilimit, ilimittime, listptitle, addtocart, name) {
    if (sArr.split(';').length > 0) {

        var func = function () {
            CalloadProductBox(sArr, ilimit, listptitle, addtocart, name);
        }
        func();
        ilimittime = (ilimittime == 0) ? 10000 : ilimittime; //ilimittime
        window.setInterval(func, ilimittime);
    }
}
function random_number(min, max) {

    return (Math.round((max - min) * Math.random() + min));
}

function CalloadProductBox(sArr, ilimit, listptitle, addtocart, name) {
    document.getElementById(name).innerHTML = '';
    var aArr = sArr.split(";");
    var pos;
    var aArr2 = new Array();
    var arrKeeppos = new Array();
    var temp;
    for (var i = 0; i < ilimit; i++) {
        temp = random_number(0, aArr.length - 2); //Math.ceil(Math.random() * (aArr.length-2)) ;
        var j;
        for (j = 0; j < arrKeeppos.length; j++) {
            if (temp == arrKeeppos[j]) {
                temp = random_number(0, aArr.length - 2);
                j == 0;
            }
        }
        if (j == 0 || j == arrKeeppos.length) { pos = temp; arrKeeppos[j] = temp };
        aArr2 = aArr[pos].split('|');
        var proid = aArr2[0];
        var ContainItem = document.createElement('div');
        //ContainItem.className = 'dvContainItemPBox';

        var CTIMG = document.createElement('div');
        var AImg = document.createElement('a');
        var img = document.createElement('img');
        img.src = aArr2[3];
        AImg.href = aArr2[7];
        img.className = "PBoxRightAimage";
        img.setAttribute("style", "border:0px");
        CTIMG.appendChild(AImg);
        AImg.appendChild(img);
        CTIMG.className = "VNVN_17_UC_PRODUCT_LIST_ColPicture";
        ContainItem.appendChild(CTIMG);


        var CTTitle = document.createElement('div');
        var aTitle = document.createElement('a');
        aTitle.id = 'aTitle_' + proid;
        aTitle.innerHTML = aArr2[1];
        aTitle.href = aArr2[7];
        aTitle.className = "VNVN_17_UC_PRODUCT_LIST_Title";
        CTTitle.appendChild(aTitle);
        CTTitle.className = "VNVN_17_UC_PRODUCT_LIST_Code";
        ContainItem.appendChild(CTTitle);

        var CTSPDics = document.createElement('div');
        var SPDics = document.createElement('span');
        SPDics.innerHTML = aArr2[2];
        CTSPDics.appendChild(SPDics);
        CTSPDics.className = "VNVN_17_UC_PRODUCT_LIST_Code";
        ContainItem.appendChild(CTSPDics);


        if ((aArr2[6].toString().indexOf('$0.0')) != 0) {
            var CTSLPrice = document.createElement('div');
            var SPLPrice = document.createElement('span');
            var SPTitleLPrice = document.createElement('span');
            SPTitleLPrice.innerHTML = listptitle;
            CTSLPrice.appendChild(SPTitleLPrice);
            SPLPrice.innerHTML = aArr2[6];
            SPLPrice.className = "linethrough";
            SPTitleLPrice.setAttribute("style", "color: #000; font-weight: normal;");
            CTSLPrice.appendChild(SPLPrice);
            CTSLPrice.className = "VNVN_17_UC_PRODUCT_LIST_Price";
            ContainItem.appendChild(CTSLPrice);
        }
        var CTSPrice = document.createElement('div');
        var SPPrice = document.createElement('span');
        SPPrice.innerHTML = aArr2[5];
        SPPrice.className = "VNVN_17_UC_PRODUCT_LIST_Price";
        CTSPrice.appendChild(SPPrice);
        CTSPrice.className = "AlignCenter";
        ContainItem.appendChild(CTSPrice);

        var CTAdd = document.createElement('div');
        var hp = document.createElement('a');
        hp.id = 'a_' + proid;
        var img = document.createElement('img');
        img.id = 'img_' + proid;
        img.src = addtocart;
        hp.onclick = AddtocartClientHandler.bind(hp, proid);
        CTAdd.appendChild(hp);
        CTAdd.className = "VNVN_17_UC_PRODUCT_LIST_Code";
        hp.appendChild(img);
        ContainItem.className = "VNVN21_ContentShortShopping1";
        ContainItem.appendChild(CTAdd);

        document.getElementById(name).appendChild(ContainItem);

    }
}

function AddtocartClientHandler(id) {
    BubbleEventServer(id);
}
function ReceiveServerAddtocart(arg) {
    window.location.reload(arg);
}
function addtocart3(Product_ID, min_count) {
    var id = document.getElementsByTagName("input");
    var count = 0;
    var products = "";
    for (var i = 0; i < id.length; i++) {
        if (id[i].checked == true) {
            count++;
            products += id[i].id.split('_')[1] + ";";
        }
    }
    if (count >= min_count) {
        new Ajax.Request(s_Path + "VNVN_Web/VNVN_19_Server.aspx",
            {
                method: "post", // Setup Method            
                parameters:
                {
                    cmd: 3,
                    ProductID: Product_ID,
                    list: products,
                    Qty: 1
                }, // Add Parameters
                onSuccess: function (transport) {
                    window.location = window.location;
                },
                onFailure: function () { alert("error"); return false; } // Event Failure --> do...     

            });
    }
    /*else {
    alert(" You must choose " + min_count + " product before add to cart.");
    }*/

}
function calcage(secs, num1, num2) {
    s = ((Math.floor(secs / num1)) % num2).toString();
    if (LeadingZero && s.length < 2)
        s = "0" + s;
    return "<b>" + s + "</b>";
}

function CountBack(ID, secs) {
    if (secs < 0) {
        document.getElementById(ID).innerHTML = FinishMessage;
        return;
    }
    DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs, 86400, 100000));
    DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs, 3600, 24));
    DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs, 60, 60));
    DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs, 1, 60));

    document.getElementById(ID).innerHTML = DisplayStr;
    if (CountActive)
        setTimeout("CountBack('" + ID + "', " + (secs + CountStepper) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
    document.write("<span id='" + ID + "' style='background-color:" + backcolor +
                "; color:" + forecolor + "'></span>");
}
function DisplayPrice(e, Container, Name, Method, Value) {
    /*if (e.checked == true) {
    replace($(Name).innerHTML,'$','');
    }*/
    var id = document.getElementsByTagName("input");
    var total = 0;
    var products = "";
    var min = 0;
    var price = 0;
    for (var i = 0; i < id.length; i++) {
        if (id[i].checked == true) {
            products = id[i].id.split('_')[1];

            price = $(Name + '_' + products).innerHTML.replace('$', '') * 1.0;

            total += price;
            if (Method.toLowerCase() == 'min') {
                if (min > price || min == 0)
                    min = price;

            }
            else {
                if (Method.toLowerCase() == 'max') {
                    if (min < price)
                        min = price;
                }
                else
                    min = total;
            }
        }
    }
    $("Total").innerHTML = "$" + total.toFixed(2);
    if (Value.indexOf('%') > 0) {
        Value = (min * Value.replace('%', '') / 100) * 1.00;
    }
    else
        Value = Value * 1.00;
    $("Save").innerHTML = "$" + Value.toFixed(2);
    total = total - Value;
    $(Container).innerHTML = "$" + total.toFixed(2);
}
function ShowImage(Container, info, event, ID) {

    if (info != "" && $(Container).style.display == 'none') {
        $(Container).innerHTML = "<img src='" + info + "'/>";
        $(Container).style.display = 'block';
        toolTipMove(Container, event, ID);
    }
}
function HideImage(id) {
    $(id).style.display = 'none';
}


function toolTipMove(Container, e, ID) {

    if (!e) e = window.event;

    var tooltip = $(Container);
    var doc = document.documentElement;
    var curX = e.clientX;
    var curY = e.clientY;

    if ($(ID)) {
        curX = Position.cumulativeOffset($(ID))[0];
        curY = Position.cumulativeOffset($(ID))[1];
    }
    getMousePosition(100);
    var winwidth = doc.clientWidth;
    var winheight = doc.clientHeight;
    var rightedge = curX + tooltip.offsetWidth;
    var bottomedge = curY + tooltip.offsetHeight;
    var scroll = 0;
    if (doc.scrollTop == 0) {
        bottomedge = bottomedge - document.body.scrollTop;
        scroll = document.body.scrollTop;
    }
    else {
        bottomedge = bottomedge - doc.scrollTop;
        scroll = doc.scrollTop;

    }
    if (window.mouseXPos < curX || window.mouseXPos > curX + $(ID).offsetWidth) {
        HideImage(Container);
        clearTimeout(timer);
    }
    else {
        clearTimeout(timer);
        if ($(ID)) {
            rightedge += $(ID).offsetWidth;
        }
        if (rightedge > winwidth)
            curX -= tooltip.offsetWidth;
        else if ($(ID))
            curX += $(ID).offsetWidth;
        if (bottomedge > winheight) {
            curY = curY - bottomedge + winheight;
        }
        if (curY < scroll)
            curY = scroll;
        tooltip.style.top = curY + "px";
        tooltip.style.left = curX + "px";
    }
}
function ClosePopup() {
    window.$('MainBox').remove();
    window.$('ChildBox').remove();

}

function InsertDiscount(PatientDiscount, TotalMoney1, TotalMoney2, Cmd, Control_Value) {

    if ($(PatientDiscount) != null) {
        if (Cmd == 11) {
            $(TotalMoney1).innerHTML = $('oneStep_td_TotalMoney').innerHTML.replace("$", "") - ($('oneStep_lbDiscountMoney').innerHTML.replace("-$", ""));
            if (($(PatientDiscount).value).indexOf("%") > 0) {
                $('oneStep_lbl_ExDiscount').innerHTML = $(TotalMoney1).innerHTML.replace("$", "") * $(PatientDiscount).value.replace('%', '') / 100;
                $('oneStep_lbl_ExDiscount').innerHTML = (Math.round($('oneStep_lbl_ExDiscount').innerHTML * 100) / 100).toFixed(2);
            }
            else
                $('oneStep_lbl_ExDiscount').innerHTML = (Math.round($(PatientDiscount).value * 100) / 100).toFixed(2);
            $(TotalMoney2).innerHTML = $(TotalMoney1).innerHTML.replace("$", "") - $('oneStep_lbl_ExDiscount').innerHTML;

            $('oneStep_lbl_ExDiscount').innerHTML = "-$" + $('oneStep_lbl_ExDiscount').innerHTML;


        }

        new Ajax.Request(s_Path + "VNVN_Web/VNVN_19_Server.aspx",
        {
            method: "post", // Setup Method            
            parameters:
	        {
	            cmd: Cmd,
	            sData: $(PatientDiscount).value,
	            Total: $(TotalMoney2).innerHTML.replace("$", "")
	        },
            asynchronous: false,
            onSuccess: function (transport) { // Event Success --> do...
                var response = transport.responseText;
                if (response != "") {
                    if (Cmd == 11) {
                        if ($('oneStep_lbl_CouponValue').innerHTML.replace("-$", "") > 0 && response > 0) {
                            $('oneStep_lbl_CouponValue').innerHTML = "-$" + (Math.round(response * 100) / 100).toFixed(2);
                            $(TotalMoney2).innerHTML = $(TotalMoney2).innerHTML - $('oneStep_lbl_CouponValue').innerHTML.replace("-$", "");
                            $(TotalMoney2).innerHTML = "$" + (Math.round($(TotalMoney2).innerHTML * 100) / 100).toFixed(2);
                        }
                        else {
                            if ($('oneStep_lbl_CouponValue').innerHTML.replace("-$", "") > 0) {
                                $('oneStep_lbl_Coupon').innerHTML = $('oneStep_lbl_Coupon').innerHTML.split(':')[0] + ":";
                                $('oneStep_lbl_CouponValue').innerHTML = "$0.00";
                                $('oneStep_txt_Coupon').style.display = '';
                                $('oneStep_img_Coupon').style.display = '';
                                alert("Invalid Coupon number!");

                            }
                        }
                    }
                    else {
                        if (response > 0) {
                            $('oneStep_lbl_Coupon').innerHTML += "(" + $(PatientDiscount).value + ")";
                            $(PatientDiscount).style.display = 'none';
                            $('oneStep_img_Coupon').style.display = 'none';

                            $('oneStep_lbl_CouponValue').innerHTML = "-$" + (Math.round(response * 100) / 100).toFixed(2);

                            $(TotalMoney1).innerHTML = $('oneStep_td_TotalMoney').innerHTML.replace("$", "") - ($('oneStep_lbDiscountMoney').innerHTML.replace("-$", ""));

                            PatientDiscount = 'oneStep_lbl_ExDiscount';
                            if ($(PatientDiscount) && $(PatientDiscount).innerHTML != "") {
                                $(TotalMoney2).innerHTML = $(TotalMoney1).innerHTML.replace("$", "") - ($(PatientDiscount).innerHTML.replace('-$', ''));
                            }
                            $(TotalMoney2).innerHTML = $(TotalMoney2).innerHTML.replace("$", "") - response;
                            $(TotalMoney2).innerHTML = '$' + (Math.round($(TotalMoney2).innerHTML * 100) / 100).toFixed(2);
                        }
                        else {
                            alert("Invalid Coupon number!");
                        }

                    }
                }
                else
                    $(TotalMoney2).innerHTML = '$' + (Math.round($(TotalMoney2).innerHTML.replace("$", "") * 100) / 100).toFixed(2);
                if ($('oneStep_txt_s_7')) {
                    GetTax('oneStep_txt_s_7', 'oneStep_td_Tax', 'oneStep_lbl_TotalMoney2', null);
                }
                else
                    GetTax('txt_s_7', 'oneStep_td_Tax', 'oneStep_lbl_TotalMoney2', null);
                GetTotalValueInOneStepCheckOut('oneStep_lbl_TotalMoney2,oneStep_td_Tax,oneStep_td_ShippingMethod,oneStep_td_GrandTotal', 'oneStep_td_ShippingMethod,', ',', null);
            },
            onFailure: function () { alert(sError); } // Event Failure --> do...     		    
        });
    }
}
function CheckMainProduct(ID, product, container) {
    if (confirm("Is this product required?")) {
        document.getElementById(container).value += product + ';';
    }
    var option = document.getElementById("VNVN_19_UC_CardForms1_" + ID).options[document.getElementById("VNVN_19_UC_CardForms1_" + ID).selectedIndex];
    option.attributes["onclick"].value = option.attributes["onclick"].value.replace("CheckMainProduct", "RemoveProduct");
    document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@").options.add(option);
    if (document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@").options.length == 1)
        document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@@").value = "";
    document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@@").value += product + ';';
    return false;
}
function RemoveProduct(ID, product, container) {
    document.getElementById(container).value = document.getElementById(container).value.replace(document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@").value + ';', '')
    document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@@").value = document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@@").value.replace(product + ';', '')

    var option = document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@").options[document.getElementById("VNVN_19_UC_CardForms1_" + ID + "@").selectedIndex];
    option.attributes["onclick"].value = option.attributes["onclick"].value.replace("RemoveProduct", "CheckMainProduct");
    document.getElementById("VNVN_19_UC_CardForms1_" + ID).options.add(option);
    return false;


}
function DeleteProperties(Container, Update) {
    var Holder = $(Container);
    var array_id = "", array_value = "";
    var childs = Holder.getElementsBySelector('[type="checkbox"]');
    for (i = 0; i < childs.length; i++) {
        if (childs[i].checked == true) {
            array_id += childs[i].id + "^";
            if (Update == true) {
                var value = $("txt_" + childs[i].id).value;
                array_value += value + "^";
            }
        }
    }
    new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
            {
                method: "post", // Setup Method            
                parameters:
                {
                    cmd: 101,
                    ProductID: array_id,
                    sData: array_value

                }, // Add Parameters
                onSuccess: function (transport) {
                    if (transport.responseText != "0") {
                        alert("Successfully!");
                        window.location = window.location;
                    }
                },
                onFailure: function () { alert("error"); return false; } // Event Failure --> do...     

            });
}
function DeleteProperty(ID, Update) {
    var array_id = ID, array_value = "";
    if (Update == true) {
        array_value = $("txt_" + ID).value;
    }
    new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
            {
                method: "post", // Setup Method            
                parameters:
                {
                    cmd: 101,
                    ProductID: array_id,
                    sData: array_value

                }, // Add Parameters
                onSuccess: function (transport) {
                    if (transport.responseText != "0") {
                        alert("Successfully!");
                        window.location = window.location;
                    }
                },
                onFailure: function () { alert("error"); return false; } // Event Failure --> do...     

            });
}
function ChooseProducts(Container,ID) {
    var Source = $(Container);
    var Holder = $(Container+"@");
    var array_id = "", array_value = "";
    var childs = Source.getElementsBySelector('[type="checkbox"]');
    for (i = 0; i < childs.length; i++) {
        if (childs[i].checked == true) {
            childs[i].attributes["onclick"].value = "SetMainProduct(this,'" + ID + "');";
            $(Source.parentNode.id + "@@").value += childs[i].id + ";";
            new Insertion.Bottom(Container + "@", "<div style='" + childs[i].parentNode.attributes["style"].value + "'>" + childs[i].parentNode.innerHTML + "</div>");
            childs[i].parentNode.remove();
        }
    }
}
function SetMainProduct(e, ID) {
    if(e.checked)
        $(ID).value += e.id + ';';
    else
        $(ID).value =$(ID).value.replace(e.id + ';','');
}
function parse(xml) {
    var doc = null;
    if (window.ActiveXObject) {
        doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.async = "false";
        doc.loadXML(xml);
    }
    else {
        var parser = new DOMParser();
        doc = parser.parseFromString(xml, "text/xml");
    }
    return doc;
}
var FilePath = '';
function ViewXml(filepath) {
    FilePath = filepath;
    new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
    {
        method: "post", // Setup Method            
        parameters:
                {
                    cmd: 102,
                    sData: filepath

                }, // Add Parameters
                onSuccess: function (transport) {
                new Insertion.Bottom('Holder',transport.responseText);            
        },
        onFailure: function (transport) {
            alert('Failure! Status code ' + transport.status + ' (' + transport.statusText + ')');
        } 
    });
}

function Modify(ID, Content) {
    Content = Content.replace(/@/g, "'");
    var Content1 = prompt(Content, Content);
    Content = Content.replace(/</g, "&lt;").replace(/>/g, "&gt;");
    $(ID).innerHTML = Content1;
    Content1 = Content1.replace(/</g, "&lt;").replace(/>/g, "&gt;");    
    new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
    {
        method: "post", // Setup Method            
        parameters:
                {
                    cmd: 103,
                    sData: Content,
                    sData1: Content1,
                    sPath: FilePath

                }, // Add Parameters
        onSuccess: function (transport) {
            alert("Successfully!");
        },
        onFailure: function (transport) {
            alert('Failure! Status code ' + transport.status + ' (' + transport.statusText + ')');
        }
    });
}

