/*
 *THIS IS FOR THE CART ON THE HOME PAGE
 */

//var xmlHttp;


//
//Adds products to cart
//from home page
function doCart(action, product_id, qty) {
      
    //var xmlHttp;

    //for local host
    //var tmp_rootpath_div = "http://localhost/lcmukorg/";
    
    //for internet
    var tmp_rootpath_div = "http://www.lcmuk.org/";
    
    //var xmlHttp;
    
    var qty_sel = qty;
        
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return
    }
    
    var url = tmp_rootpath_div + 'cart.php?action=' + action + '&pid=' + product_id + '&qty=' + qty_sel;

    xmlHttp.onreadystatechange = doCartstateChanged
    xmlHttp.open('GET', url, true)
    xmlHttp.send(null);
        
}

//for home page basketInformation -basket_container
function doCartstateChanged()
{
   
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        var objDetails = xmlHttp.responseText;
        document.getElementById('basket_container').innerHTML = objDetails;
        var alert_msg = "The item has been added to your basket.";
        putIF('bubble_div', alert_msg);
        window.scrollTo(0, 0);

    }
}

//
//Deletes products to cart
//from home page
function delChurchCart(product_id) {
    
    //var xmlHttp;

    // for locahost
    //var tmp_rootpath = "http://localhost/lcmukorg/";
     var tmp_rootpath = "http://www.lcmuk.org/";
    
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request");
        return
    }

    var url = tmp_rootpath + 'cart.php?action=remove_item&pid=' + product_id ;

    //xmlHttp.onreadystatechange = delChurchCartstateChanged
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
        {
            //alert('na delete i dey sooo');
            var objDetails = xmlHttp.responseText;
            //alert("see am "+objDetails);
            document.getElementById('basket_container').innerHTML = objDetails;
            var alert_msg = "The item has been deleted from your basket.";
            putIF('bubble_div', alert_msg);
            window.scrollTo(0, 0);
        }
    }
    xmlHttp.open('GET', url, true);
    xmlHttp.send(null);

}

//
//
//
//For home page - Delete item
/*
function delChurchCartstateChanged() {
    
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        alert('na delete i dey sooo');
        var objDetails = xmlHttp.responseText;
        alert("see am "+objDetails);
        document.getElementById('basket_container').innerHTML = objDetails;
        var alert_msg = "The item has been deleted from your basket.";
        putIF('bubble_div', alert_msg);
        window.scrollTo(0, 0);
    }
}
*/

/*function GetXmlHttpObject()
{
    //var objXMLHttp = null
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest()
    }
    else if (window.ActiveXObject) {
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp;
}

*/

function GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}




//var IE = document.all ? true : false
//if (!IE) {
//    document.captureEvents(Event.MOUSEMOVE)
//}

// description of the arguments below
function putIF(hldr, sc_alert_msg)
{

    //alert('pop up is here');
    var holder = getElm(hldr);//document.getElementById(hldr); //wrap around div
    
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        if (navigator.appVersion.indexOf('MSIE 6.0') > 0) {
            holder.style.right = "605px";
        } else {
            holder.style.right = "695px";
        }
    } 
    else
    {
        holder.style.right = "695px";
    }
    holder.style.top = "290px";


    holder.style.visibility = 'visible';
    holder.style.visibility = 'visible';

    IF = document.createElement('div');
    
    IF.setAttribute("scrolling", 'no');
    holder.appendChild(IF); // now we add it to the div
    
    
    //holder.innerHTML = '<div id="div_tab" style="width:360px;"><div class="floatl" style="background-image:url(' + 'images/cart/Popup_Cart.gif); background-repeat:no-repeat; width:370px; height:192px;"><table width="300" border="0" cellspacing="0" cellpadding="0" id="popup" summary="" background="#00000;" align="left"><tr><td width="12" valign="top" >&nbsp;</td><td width="279" valign="top"><div align="right" class="text11grey padt8"><a href="javascript:closeIF();" class="botlink">Close</a><img src="' + 'images/tspacer.gif" height="1" width="3"/><a href="javascript:closeIF();"><img src="' + 'images/cart/icon_close.gif" alt="Close" width="13" height="12" hspace="2" border="0" align="absmiddle" /></a></div><div align="center"></div><br/><br/><div align="center" class="text12 padt30">' + sc_alert_msg + '</div><div align="center" class="padt10"><img src="' + 'images/cart/check_out.gif" alt="Checkout"  hspace="2" vspace="5" border="0" style="cursor:pointer;"  onclick="javascript:window.location.href="http://wwww.lcmuk.org/store/index.php?p=checkout";" /><img src="' + 'images/tspacer.gif" height="1" width="5"/><img src="' + 'images/cart/continue_shopping.gif" alt="Continue Shopping" hspace="2" vspace="5" border="0" style="cursor:pointer;" onclick="closeIF()" /></div></td><td width="9" align="right" valign="top" >&nbsp;</td></tr><tr><td colspan="3"  height="11">&nbsp;</td></tr> </table></div></div>';
    //holder.innerHTML = '<div id=\"div_tab\" style=\"width:360px;\"><div class=\"floatl\" style=\"background-image:url(' + 'images/cart/Popup_Cart.gif); background-repeat:no-repeat; width:370px; height:192px;\"><table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\"popup\" summary=\"\" background=\"#00000;\" align=\"left\"><tr><td width=\"12\" valign=\"top\" >&nbsp;</td><td width=\"279\" valign=\"top\"><div align=\"right\" class=\"text11grey padt8\"><a href=\"javascript:closeIF();\" class=\"botlink\">Close</a><img src=\"' + 'images/tspacer.gif\" height=\"1\" width=\"3\"/><a href=\"javascript:closeIF();\"><img src=\"' + 'images/cart/icon_close.gif\" alt=\"Close\" width=\"13\" height=\"12\" hspace=\"2\" border=\"0\" align=\"absmiddle\" /></a></div><div align=\"center\"></div><br/><br/><div align=\"center\" class=\"text12 padt30\">' + sc_alert_msg + '</div><div align=\"center\" class=\"padt10\"><img src=\"' + 'images/cart/check_out.gif\" alt=\"Checkout\"  hspace=\"2\" vspace=\"5\" border=\"0\" style=\"cursor:pointer;\"  onclick=\"javascript:window.location.href=\"http://localhost/lcmukorg/store/index.php?p=checkout\";\" /><img src=\"' + 'images/tspacer.gif\" height=\"1\" width=\"5\"/><img src=\"' + 'images/cart/continue_shopping.gif\" alt=\"Continue Shopping\" hspace=\"2\" vspace=\"5\" border=\"0\" style=\"cursor:pointer;\" onclick=\"javascript:window.location.href=\"http://localhost/lcmukorg/store/\" /></div></td><td width=\"9\" align=\"right\" valign=\"top\" >&nbsp;</td></tr><tr><td colspan=\"3\"  height=\"11\">&nbsp;</td></tr> </table></div></div>';
    holder.innerHTML = '<div id="div_tab" style="width:360px;"><div class="floatl" style="background-image:url(' + 'images/cart/Popup_Cart.gif); background-repeat:no-repeat; width:370px; height:192px;"><table width="300" border="0" cellspacing="0" cellpadding="0" id="popup" summary="" background="#00000;" align="left"><tr><td width="12" valign="top" >&nbsp;</td><td width="279" valign="top"><div align="right" class="text11grey padt8"><a href="javascript:closeIF();" class="botlink">Close</a><img src="' + 'images/tspacer.gif" height="1" width="3"/><a href="javascript:closeIF();"><img src="' + 'images/cart/icon_close.gif" alt="Close" width="13" height="12" hspace="2" border="0" align="absmiddle" /></a></div><div align="center"></div><br/><br/><div align="center" class="text12 padt30">' + sc_alert_msg + '</div><div align="center" class="padt10"><img src="' + 'images/cart/check_out.gif" alt="Checkout"  hspace="2" vspace="5" border="0" style="cursor:pointer;"  onclick="javascript:checkout();" /><img src="images/tspacer.gif" height="1" width="5"/><img src="images/cart/continue_shopping.gif" alt="Continue Shopping" hspace="2" vspace="5" border="0" style="cursor:pointer;" onclick="javascript:contshopping();" /></div></td><td width="9" align="right" valign="top" >&nbsp;</td></tr><tr><td colspan="3"  height="11">&nbsp;</td></tr> </table></div></div>';

}
function checkout(){
    window.location.href="http://localhost/lcmukorg/church_store/index.php?p=checkout"
}
function contshopping(){
    //window.location.href="http://localhost/lcmukorg";
    closeIF();
    window.scrollTo(1800,600);
}
function closeIF() // the close is simple we just clear out the div
{
    
    var obj = getElm('bubble_div');//document.getElementById('bubble_div');
    obj.innerHTML = '';
//obj.style.display = 'none';
}

function getElm(id) {
    if (document.layers) return document.layers[id];
    else if (document.all) return document.all[id];
    else return document.getElementById(id);
}
function closeCO() // the close is simple we just clear out the div
{
    alert('closeCO');
    //if (tmp_rootpath.indexOf('registration') > 0) {
    //    var tmp_rootpath_div = tmp_rootpath.replace("registration/", "");
    //    PageFrom = tmp_rootpath_div + "shopping_cart.php";
    //}
    //else {
    //    PageFrom = tmp_rootpath + "shopping_cart.php";
    // }

    var obj =  getElm('bubble_div')//document.getElementById('bubble_div');
    obj.innerHTML = '';
//obj.style.display = 'none';
//document.location.href = PageFrom;
}

