jQuery.noConflict();
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
     var request_type;
     var browser = navigator.appName;
     if(browser == "Microsoft Internet Explorer"){
           request_type = new ActiveXObject("Microsoft.XMLHTTP");
     }
     else 
     {
        request_type = new XMLHttpRequest();
     }
     return request_type;
}
var http = createObject();
var nocache = 0;
function genSubCat() {
     nocache = Math.random();
     var cid = encodeURI(document.getElementById('subid').value);
     http.open('get', 'lib/ajaxSubCategory.php?id='+cid + '&nocache = '+nocache);
     http.onreadystatechange = insertReply;
     http.send(null);
}
function genSubCatEdit(gid,subid) {
     //document.getElementById('insert_response').innerHTML = "Just a second..."
     nocache = Math.random();
     var pag ='';
     var cid = encodeURI(document.getElementById(gid).value);
     http.open('get', 'lib/ajaxSubCategory.php?id='+cid + '&nocache = '+nocache +'&p='+pag);
     http.onreadystatechange = editReply;
     http.send(null);
}
function editReply() {
	
	if(http.readyState == 1){
	
	}
     if(http.readyState == 4){
     var response = http.responseText;   
     document.getElementById('subid').innerHTML = ''+response;
     document.categoryform.submit();
}
}
var specialspop;
function couponopen(url)
{
	specialspop=window.open(url,'name','height=400,width=500,left=300,top=100,scrollbars=1');
	
}
function print_this(element_id) {
    var divs = document.getElementsByTagName("DIV");
    for (i=0; i<divs.length; i++) {
        if (divs[i].id != element_id && divs[i].className ==
        "hide_for_print") {
            divs[i].style.display = "none";
        }
    }
    window.print();
}
function couponCart(couponid) {

	query_string = 'id=' + couponid ;
	//alert(query_string);
	jQuery.ajax({
		type: "POST",
		url: "ajax/couponcart.php",
		data: query_string,
		success: function(data){
			
				jQuery("#coupadded").html(data);
			
		}
	});
	return false;
	
};
function getLoginForm() {

	query_string = 'getlogin=1' ;
	//alert(query_string);
	jQuery.ajax({
		type: "POST",
		url: "ajax/getLogin.php",
		data: query_string,
		success: function(data){
			
				jQuery("#cartsinc").html(data);
			
		}
	});
	return false;
	
};
function getPassForm() {

	query_string = 'getlogin=1' ;
	//alert(query_string);
	jQuery.ajax({
		type: "POST",
		url: "ajax/passwordform.php",
		data: query_string,
		success: function(data){
			
				jQuery("#cartsinc").html(data);
			
		}
	});
	return false;
	
};
function confirmOrder() {

	query_string = 'confirm=1' ;
	//alert(query_string);
	jQuery.ajax({
		type: "POST",
		url: "ajax/paypalsend.php",
		data: query_string,
		success: function(data){
			
				jQuery("#cartinc").html(data);
			
		}
	});
	return false;
	
};
function processLogin() {
	var email = jQuery('#email').val();
	var password = jQuery('#password').val();
	query_string = 'lgin=1&email='+ email +'&password=' + password ;
	//alert(query_string);
	jQuery.ajax({
		type: "POST",
		url: "ajax/processlogin.php",
		data: query_string,
		success: function(data){
			
				jQuery("#cartsinc").html(data);
			
		}
	});
	return false;
	
};
function retrievePass() {
	var email = jQuery('#email').val();

	query_string = 'lgin=1&email='+ email  ;
	//alert(query_string);
	jQuery.ajax({
		type: "POST",
		url: "ajax/resetpass.php",
		data: query_string,
		success: function(data){
			
				jQuery("#retriever").html(data);
			
		}
	});
	return false;
	
};
function showRestrict(id) {
	 jQuery('#restrict'+id).show();
};
function registerAccount()
{
	location.href='index.php?register';
}

function addToCart(pid,quantity) {
	var qant = document.getElementById(quantity).value;
	query_string = 'order_code=' + pid + '&order_quantity='+ qant;
	//alert(query_string);
	jQuery.ajax({
		type: "POST",
		url: "ajax/cart_action.php",
		data: query_string,
		success: function(data){
			
				jQuery('#orderadded'+ pid).html(data);
				jQuery("#shopcartup").show();
				jQuery("#cartimg").show();
			 
		}
	});
	return false;
};

jQuery(function() { 
	
	jQuery("#cart tr .remove input").click(function() {
		var orderCode = jQuery(this).val();
		jQuery.ajax({
			type: "GET",
			url: "ajax/cart_action.php",
			data: "remove[]=" + orderCode + '&update_quantity=1',  
			success: function() {
				jQuery("#cart tr .remove input[value=" + orderCode + "]").parent().parent().fadeOut(500, function() {
					jQuery(this).remove();
					calcPrice();
				});
			}
		});
	});
	
	jQuery("#cart tr .quantity select").change(function() {
		var orderCode = jQuery(this).attr("name").slice(9, -1);
		var quantity = jQuery(this).val();
		jQuery.ajax({
			type: "GET",
			url: "ajax/cart_action.php",
			data: "quantity[" + orderCode + "]=" + quantity,
			success: function(data) {
				jQuery('#subamount'+orderCode).html(data);
				calcPrice();
			}
		});
	});
});

function calcPrice() {
	
	jQuery.ajax({
		type: "GET",
		url: "ajax/calc_price.php",
		data: 'update_quantity=1',  
		success: function(data) {
		jQuery("#total_price").html(data);
		}
	});
	
	return false;
};