var http_request = false;

function makeRequest(url,func_action) 
{
	http_request = false;

	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,...
    	http_request = new XMLHttpRequest();
    	if (http_request.overrideMimeType){
        	http_request.overrideMimeType('text/xml');
    	}
	} 
	else if (window.ActiveXObject)
	{ // IE
    	try {
        	http_request = new ActiveXObject("Msxml2.XMLHTTP");
    	} 
    	catch (e) 
    	{
        	try {
            	http_request = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch (e) {}
    	}
	}
	if (!http_request){
    	alert('Giving up; Cannot create an XMLHTTP instance');
    	return false;
	}
	if(func_action!=''){
		eval ('http_request.onreadystatechange = ' + func_action);
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}
    
function loadProductDetails() 
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var xmldoc = http_request.responseXML;
			var selcontent = xmldoc.getElementsByTagName('selcontent').item(0).firstChild.data;
			var selid = xmldoc.getElementsByTagName('selid').item(0).firstChild.data;
			var stockstatus = xmldoc.getElementsByTagName('stockstatus').item(0).firstChild.data;
			var prod_box_id = xmldoc.getElementsByTagName('prod_box_id').item(0).firstChild.data;
			var offer_flag = xmldoc.getElementsByTagName('offer_flag').item(0).firstChild.data;
			
			if(xmldoc.getElementsByTagName('oldprice').item(0)){
				var oldprice = xmldoc.getElementsByTagName('oldprice').item(0).firstChild.data;
			}
			
			if(xmldoc.getElementsByTagName('curprice').item(0)){
				var curprice = xmldoc.getElementsByTagName('curprice').item(0).firstChild.data;
			}
			
			if(xmldoc.getElementsByTagName('productcode').item(0)){
				var productcode = xmldoc.getElementsByTagName('productcode').item(0).firstChild.data;
			}
			
			if(document.getElementById(selid)){
				if(selid == 'prodcolor_'+prod_box_id){
					document.getElementById('colour_id_'+prod_box_id).disabled = false;
				}
				document.getElementById(selid).innerHTML = selcontent;
				
				if(selcontent == ''){
					document.getElementById(selid).style.display = 'none';
				}else{
					document.getElementById(selid).style.display = 'block';
				}
			}
			
			if(document.getElementById('stock_status_'+prod_box_id)){
				document.getElementById('stock_status_'+prod_box_id).innerHTML = stockstatus;
				if(stockstatus == ''){
					document.getElementById('stock_status_' + prod_box_id).style.display = 'none';
				}else{
					document.getElementById('stock_status_' + prod_box_id).style.display = 'block';
				}
			}
			
			if(document.getElementById('oldprice')){
				document.getElementById('oldprice').innerHTML = oldprice;
			}
			
			if(document.getElementById('curprice') && curprice){
				document.getElementById('curprice').innerHTML = curprice;
			}
			if(document.getElementById('productcode') && productcode){
				document.getElementById('productcode').innerHTML = productcode;
			}else if(document.getElementById('productcode')){
				document.getElementById('productcode').innerHTML = '';
			}
			
			enableFormElements('fp1');
			
			if(parseInt(offer_flag) > 0){
				reCalculateDealTotals(prod_box_id);
				if(xmldoc.getElementsByTagName('imgcurprice').item(0)){
					var imgcurprice = xmldoc.getElementsByTagName('imgcurprice').item(0).firstChild.data;
					document.getElementById('img_price_'+prod_box_id).innerHTML = imgcurprice;
				}
			}
		}
	}
}

function loadSearchDetails() 
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var xmldoc = http_request.responseXML;
			var selcontent = xmldoc.getElementsByTagName('selcontent').item(0).firstChild.data;
			var selid = xmldoc.getElementsByTagName('selid').item(0).firstChild.data;					
			if(document.getElementById(selid)){
				if(selid == 'divsrchcatsel'){
					document.getElementById('schcategory').disabled = false;
				}
				if(selid == 'divsrchbrandsel'){
					document.getElementById('schbrand').disabled = false;
				}
				document.getElementById(selid).innerHTML = selcontent;
				document.getElementById('loaddiv').style.display='none';
			}
		}
	}
}

function setLoadDiv(divdestination)
{
	var loadingdiv = '<div id="loading2"><img src="images/loader2.gif" alt="" /> Loading...</div>';
	document.getElementById(divdestination).innerHTML = loadingdiv;
}

function loadShipDetailsAll() 
{
	
	if (http_request.readyState == 4) 
	{
		
		if (http_request.status == 200) 
		{
			
			var xmldoc = http_request.responseXML;
			
			
			var readonlyship = xmldoc.getElementsByTagName('readonlyship').item(0).firstChild.data;
			var shipform = xmldoc.getElementsByTagName('shipform').item(0).firstChild.data;
			var selshipmet = xmldoc.getElementsByTagName('selshipmet').item(0).firstChild.data;
			
			
			if(document.getElementById(order_readonly_ship_details)){
				document.getElementById(order_readonly_ship_details).innerHTML = readonlyship;
			}
			if(document.getElementById(order_ship_details)){
				document.getElementById(order_ship_details).innerHTML = shipform;
			}
			if(document.getElementById(shipmethods)){
				document.getElementById(shipmethods).innerHTML = selshipmet;
			}
			
		}
	}
}

function loadShipDetailsShipMet() 
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var xmldoc = http_request.responseXML;
			var selshipmet = xmldoc.getElementsByTagName('selshipmet').item(0).firstChild.data;
			
			if(document.getElementById(shipmethods)){
				document.getElementById(shipmethods).innerHTML = selshipmet;
			}
		}
	}
}

function loadOfferProductDetailsMainInfo() 
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var xmldoc = http_request.responseXML;
			var main_prod_images = xmldoc.getElementsByTagName('main_prod_images').item(0).firstChild.data;
			var main_prod_title = xmldoc.getElementsByTagName('main_prod_title').item(0).firstChild.data;
			var curprice = xmldoc.getElementsByTagName('curprice').item(0).firstChild.data;
			var main_prod_tabs = xmldoc.getElementsByTagName('main_prod_tabs').item(0).firstChild.data;
			var prod_box_id = xmldoc.getElementsByTagName('prod_box_id').item(0).firstChild.data;
			var prod_id = xmldoc.getElementsByTagName('prod_id').item(0).firstChild.data;
			if(document.getElementById('main_prod_images')){
				document.getElementById('main_prod_images').innerHTML = main_prod_images;
			}
			
			if(document.getElementById('main_prod_title')){
				document.getElementById('main_prod_title').innerHTML = main_prod_title;
			}
			
			if(document.getElementById('curprice')){
				document.getElementById('curprice').innerHTML = curprice;
			}
			
			if(document.getElementById('main_prod_tabs')){
				document.getElementById('main_prod_tabs').innerHTML = main_prod_tabs;
			}
			document.getElementById('loaded_product_box_id').value = prod_box_id;
			if(parseInt(prod_id) > 0){
				document.getElementById('loaded_prod_id').value = prod_id;
			}
			document.getElementById('loaddiv4_'+prod_box_id).style.display='none';
		}
	}
}

function loadOfferProductDetailsBoxInfo() 
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var xmldoc = http_request.responseXML;
			var imgcontent = xmldoc.getElementsByTagName('imgcontent').item(0).firstChild.data;
			var prod_box_id = xmldoc.getElementsByTagName('prod_box_id').item(0).firstChild.data;
			var prod_id = xmldoc.getElementsByTagName('prod_id').item(0).firstChild.data;
			var show_click_image = xmldoc.getElementsByTagName('show_click_image').item(0).firstChild.data;
			var stockstatus = xmldoc.getElementsByTagName('stockstatus').item(0).firstChild.data;
			
			if(xmldoc.getElementsByTagName('sizeoptions').item(0)){
				var sizeoptions = xmldoc.getElementsByTagName('sizeoptions').item(0).firstChild.data;
			}
			
			if(xmldoc.getElementsByTagName('colouroptions').item(0)){
				var colouroptions = xmldoc.getElementsByTagName('colouroptions').item(0).firstChild.data;
			}
			
			if(document.getElementById('prodsize_' + prod_box_id)){
				if(sizeoptions){
					document.getElementById('prodsize_' + prod_box_id).innerHTML = sizeoptions;
					document.getElementById('prodsize_' + prod_box_id).style.display = 'block';
				}else{
					document.getElementById('prodsize_' + prod_box_id).innerHTML = '';
					document.getElementById('prodsize_' + prod_box_id).style.display = 'none';
				}
				
			}
			
			if(document.getElementById('prodcolor_' + prod_box_id)){
				if(colouroptions){
					document.getElementById('prodcolor_' + prod_box_id).innerHTML = colouroptions;
					document.getElementById('prodcolor_' + prod_box_id).style.display = 'block';
				}else{
					document.getElementById('prodcolor_' + prod_box_id).innerHTML = '';
					document.getElementById('prodcolor_' + prod_box_id).style.display = 'none';
				}
			}
			
			if(document.getElementById('stock_status_' + prod_box_id)){
				document.getElementById('stock_status_'+prod_box_id).innerHTML = stockstatus;
				if(stockstatus == ''){
					document.getElementById('stock_status_' + prod_box_id).style.display = 'none';
				}else{
					document.getElementById('stock_status_' + prod_box_id).style.display = 'block';
				}
			}
			
			if(document.getElementById('box_image_right_' + prod_box_id) && imgcontent){
				document.getElementById('box_image_right_' + prod_box_id).innerHTML = imgcontent;
			}
			
			if(parseInt(show_click_image) > 0){
				document.getElementById('click_image_id_' + prod_box_id).style.display = 'block';
				document.getElementById('no_click_image_id_' + prod_box_id).style.display = 'none';
			}else{
				document.getElementById('click_image_id_' + prod_box_id).style.display = 'none';
				document.getElementById('no_click_image_id_' + prod_box_id).style.display = 'block';
			}
			
			if(document.getElementById('prod_id_by_set_' + prod_box_id).value > 0){
				if(document.getElementById('loaded_product_box_id').value == prod_box_id){
					var prod_id = document.getElementById('prod_id_by_set_' + prod_box_id).value;
					loadMainProdInfo(prod_id,prod_box_id);
				}
			}
			
			enableFormElements('fp1');
			reCalculateDealTotals(prod_box_id);
		}
	}
}

