/*    ****************************************************************************
    *
    *  Permission to use, copy, modify, distribute and sell this software (or
    *  code file) and its documentation for any purpose is STRICTLY PROHIBITED.
    *  This file is provided "as is" without expressed or implied warranty.
    *
    * **************************************************************************
    *
    *  Copyright(c) 2010 Compunix, LLC.
    *  Please visit http://www.compunix.us for licensing information.
    *
    *  THE ABOVE NOTICE MUST REMAIN INTACT.
    *
    * ************************************************************************** */       

function fillQuickViewBox(productID)
{  
    var xmlHttp;
    
    // create XMLHttpRequest object
    // if IE6 or IE5, create ActiveXObject
    
    // XMLHttpRequest
    if (window.XMLHttpRequest)
        {
            xmlHttp=new XMLHttpRequest();
        }
    // ActiveXObject
    else if (window.ActiveXObject)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    // No browser support
    else
        {
            alert("Your browser does not support XMLHttpRequest or ActiveXObject"); 
        }        
        
    xmlHttp.onreadystatechange=function()
    {      
                
//        if(xmlHttp.readyState==1)
//        {
//            document.getElementById('Section' + sectionID).innerHTML = "Loading...";   
//        }   
//        if(xmlHttp.readyState==2)
//        {
//            document.getElementById('Section' + sectionID).innerHTML = "Loading...";    
//        }   
//        if(xmlHttp.readyState==3)
//        {
//            document.getElementById('Section' + sectionID).innerHTML = "Loading...";            
//        }   
   
        // if request is complete
        if(xmlHttp.readyState==4)
        {
            // document.getElementById('AwaitingSectionContent').style.display = 'none'; 
            // document.getElementById('SectionsContent').style.display = 'block';    
                        
            var startTag = 'Section_BeginContent';
            var endTag = 'Section_EndContent';
            
            var str = xmlHttp.responseText;

            // alert(str);                        
                        
            var starting = str.indexOf(startTag);
            var ending= str.indexOf(endTag);
            
            var innerHtmlString = str.substring(starting + startTag.length, ending);              
            innerHtmlString = innerHtmlString.replace('class="AddToCartButton"', 'class="AddToCartButton" id="AddToCartButton"').replace('class="AddToWishButton"', 'class="AddToWishButton" id="AddToWishButton"');
                                  
            document.getElementById('quickview-popup').style.display = "block";
            document.getElementById('quickview-popup').innerHTML = innerHtmlString;
          
            //document.getElementById('AJAXATC').innerHTML = newhtml;
        EvalJSBlocks(innerHtmlString);
        //alert(document.getElementById('AddToCartButton').onclick.toString());
        document.getElementById('AddToCartButton').onclick = function() { document.getElementById('AddToCartButton').parentNode.submit(); };
        if (document.getElementById('AddToWishButton')) document.getElementById('AddToWishButton').onclick = function() { document.getElementById('IsWishList').value = '1'; document.getElementById('AddToWishButton').parentNode.submit(); };
        //alert(document.getElementById('AddToCartButton').onclick.toString());
        
             
             
            // Initiate tabs
             $(function() {
                $('#container-1').tabs();
            });
            
            // document.getElementById("section" + sectionID +"ProductID").value = productID;
            
        }    
    }      

    // SERVER REQUEST
    // Post, server side script, asynchronously
    var url = "quickproductview.aspx";    
    var params = "prodID=" + productID;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);   

}


function showQuickViewBtn(productID)
{
    document.getElementById('quickviewbtn'+productID).style.display = "block";
}

function hideQuickViewBtn(productID)
{
    document.getElementById('quickviewbtn'+productID).style.display = "none";
}

function hideQuickViewPopUp()
{
    document.getElementById('quickview-popup').style.display = "none";
}

function EvalJSBlocks(gen_html) {
    var stripped_html = gen_html;
    var js_start = 0;
    do {
        js_start = stripped_html.toLowerCase().indexOf('<' + 'script', 0);
        if (js_start > -1) {
            var js_start2 = stripped_html.indexOf('>', js_start) + 1;
            var js_end = stripped_html.toLowerCase().indexOf('<' + '/' + 'script' + '>', js_start);
            var js_end2 = stripped_html.indexOf('>', js_end) + 1;
            var gen_js = stripped_html.substring(js_start2, js_end);
            stripped_html = stripped_html.substring(0, js_start) + stripped_html.substring(js_end2, stripped_html.length);
            gen_js = gen_js.replace('<' + '!--', '');
            gen_js = gen_js.replace('/' + '/--' + '>', '');
            eval(gen_js);
        }
    }
    while (js_start > -1);

    return stripped_html;
}


