// JavaScript Document
function getXmlHttpRequest()
{
	var httpRequest=null;
	try
	{
		httpRequest=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			httpRequest=null;
		}
	}
	if(!httpRequest&&typeof XMLHttpRequest!="undefined")
	{
		httpRequest=new XMLHttpRequest();
	}
	return httpRequest;
}


// define our global variables
var http = getXmlHttpRequest();
var innerHTMLID = "";
//var viewAllflg = false;

function updateStones(stone, current_category_id)
{	
	var parameters = "stone="+stone+"&colour="+document.goldcolourform.goldcolour.value+"&current_category_id="+current_category_id;
	// display the waiting message
	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
		
	// append all parameters
	
	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_cduck.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}



function updateCollections(collection, current_category_id, viewall)
{	
	var parameters = "collection="+collection+"&colour="+document.goldcolourform.goldcolour.value+"&current_category_id="+current_category_id+"&viewall="+viewall;
	// display the waiting message
	document.getElementById("ajaxAllProducts").innerHTML = "";
	if ( current_category_id!=8){ // to fix image not align center
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0px'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
	}else{
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 255px'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
	}
	// append all parameters
	
	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_cduck.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}






function moveNext(currentCollection, current_category_id)
{	
	var parameters = "currentToNextCollection="+currentCollection+"&colour="+document.goldcolourform.goldcolour.value+"&current_category_id="+current_category_id;
	// display the waiting message	
	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
		
	// append all parameters
	
	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_cduck.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}

function moveBack(currentCollection, current_category_id)
{	
	// append all parameters
	var parameters = "currentToBackCollection="+currentCollection+"&colour="+document.goldcolourform.goldcolour.value+"&current_category_id="+current_category_id;
	// display the waiting message	
	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
		
	
	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_cduck.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}

function updatePage(toPage, current_category_id)
{	
	// append all parameters
	var parameters = "toPage="+toPage+"&colour="+document.goldcolourform.goldcolour.value+"&current_category_id="+current_category_id;
	// display the waiting message	
	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px; '><img src='images/loading.gif' style='margin:100px 0 100px 255px;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
		

	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_cduck.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}

function updateColour(field_name,colour,field_text,block_name,field_id, current_category_id, viewAllflg)
{	

	// append all parameters
	var parameters = "colour="+colour+"&current_category_id="+current_category_id;
	document.getElementById(field_id).innerHTML = field_text;
	document.getElementById(field_name).value = colour;
	document.getElementById(block_name).style.display = "none";



// display the waiting message	
	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
		

	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;
	//if (viewAllflg == false){
//		http.open("POST", "ajax_cduck.php", true );
	//}else{
        parameters =  "colour="+colour+"&current_category_id="+current_category_id+"&showViewAll='hide'";
		http.open("POST", "ajax_viewall.php", true );
	//}

	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}


function updateProducts(product_id,collection, current_category_id)
{	
	// display the waiting message
	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
	// append all parameters
	var parameters = "product_id="+product_id+"&current_category_id="+current_category_id+"&collection="+collection;
	
	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_product.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}



function viewAll(current_category_id)
{	
	//viewAllflg = false;
	// display the waiting message
	
	document.getElementById("view-all-products").style.display = "none";
	document.getElementById("category-top-desc3").style.display = "block";
	document.getElementById("category-top-desc1").style.display = "none";
	document.getElementById("category-top-desc2").style.display = "block";

	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
	// append all parameters
	var parameters = "current_category_id="+current_category_id+"&showViewAll='hide'";
	
	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_viewall.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}



function viewByStone(current_category_id,colour)
{	
	//viewAllflg = true;
	// display the waiting message
	
	document.getElementById("view-all-products").style.display = "block";
	document.getElementById("category-top-desc1").style.display = "block";
	document.getElementById("category-top-desc2").style.display = "none";
	document.getElementById("category-top-desc3").style.display = "none";

	document.getElementById("ajaxAllProducts").innerHTML = "";
	document.getElementById("ajaxAllProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
	// append all parameters
	var parameters = "colour="+colour+"&current_category_id="+current_category_id+"&showViewAll=show";
	
	http = null;
	http = getXmlHttpRequest();
	http.onreadystatechange = handleHttpResponse;

// call the url 
	http.open("POST", "ajax_cduck.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}


// The server-side script 
function handleHttpResponse() {
	
	if (http.readyState == 4) {
		
		results = http.responseText;
		
		// display the content of the HTML
		document.getElementById("ajaxAllProducts").innerHTML = results;
		
		if (typeof sIFR == "function") { 
	       sIFR.replaceElement("h3.orange", named({sFlashSrc: "includes/templates/gladstone/css/trebuchet.swf", 
sColor: "#f5c071", sEmColor: "#00320e", sWmode : "transparent"}));
        }
	   if (typeof sIFR == "function") { 
	       sIFR.replaceElement("h4.gold", named({sFlashSrc: "includes/templates/gladstone/css/trebuchet.swf", 
sColor: "#e7d8a7", sEmColor: "#00320e", sWmode : "transparent",sCase : "upper"}));
        }
		
		if (typeof sIFR == "function") { 
			sIFR.replaceElement("h5", named({sFlashSrc: "includes/templates/gladstone/css/trebuchet.swf", sColor: "#e7d8a7", sEmColor: "#00320e", sWmode : "transparent"}));
			}

		if (typeof sIFR == "function") { 
			sIFR.replaceElement("h4", named({sFlashSrc: "includes/templates/gladstone/css/trebuchet.swf", 
sColor: "#f5c071", sEmColor: "#00320e", sWmode : "transparent"}));
			}


		return false;
	} 
}



function updateSpecialColour(field_name,colour,field_text,block_name,field_id)
{	

	document.getElementById(field_id).innerHTML = field_text;
	document.getElementById(field_name).value = colour;
	document.getElementById(block_name).style.display = "none";

	if (colour== "WG"){
		document.getElementById('special-gold-text').innerHTML = "<a href='javascript:void(0)' onclick=\"javascript:updateSpecialText('YG')\">Yellow Gold</a>";
		
	}else{
		document.getElementById('special-gold-text').innerHTML = "<a href='javascript:void(0)' onclick=\"javascript:updateSpecialText('WG')\">White Gold</a>";
		
	}



// display the waiting message	
	document.getElementById("ajaxSpecialProducts").innerHTML = "";
	document.getElementById("ajaxSpecialProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
		
	// append all parameters
	var parameters = "colour="+colour;

	http = null;
	http = getXmlHttpRequest(true);
	http.onreadystatechange = handleHttpResponseSpecial;

	http.open("POST", "ajax_special.php", true );
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}

function updateSpecialText(colour)
{	

	//document.getElementById(field_name).value = colour;
	

	if (colour== "WG"){
		document.getElementById('special-gold-text').innerHTML = "<a href='javascript:void(0)' onclick=\"javascript:updateSpecialText('YG')\">Yellow Gold</a>";
		document.getElementById('pull-down-gold-txt').innerHTML = "White Gold 18 ct";
		
	}else{
		document.getElementById('special-gold-text').innerHTML = "<a href='javascript:void(0)' onclick=\"javascript:updateSpecialText('WG')\">White Gold</a>";
		document.getElementById('pull-down-gold-txt').innerHTML = "Yellow Gold 18 ct";
		
	}


// display the waiting message	
	document.getElementById("ajaxSpecialProducts").innerHTML = "";
	document.getElementById("ajaxSpecialProducts").innerHTML = "<div align='center' style='height:300px;margin-bottom:20px'><img src='images/loading.gif' style='margin:100px 0 100px 0;'><br/>Please wait while we are updating the products.<br/> If the product is not updated please click <a href='javascript:document.location.reload()'>here</a> to reload this page.</div>";
		
	// append all parameters
	var parameters = "colour="+colour;

	http = null;
	http = getXmlHttpRequest(true);
	http.onreadystatechange = handleHttpResponseSpecial;


	http.open("POST", "ajax_special.php", true );
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	http.send(parameters);
	
	return false;
	
}



// The server-side script 
function handleHttpResponseSpecial() {
	
	if (http.readyState == 4) {
		
		results = http.responseText;


		// display the content of the HTML
		document.getElementById("ajaxSpecialProducts").innerHTML = results;

		if (typeof sIFR == "function") { 

	       sIFR.replaceElement("h3.orange", named({sFlashSrc: "includes/templates/gladstone/css/trebuchet.swf", 
sColor: "#f5c071", sEmColor: "#00320e", sWmode : "transparent"}));
        }
	   if (typeof sIFR == "function") { 
	       sIFR.replaceElement("h4.gold", named({sFlashSrc: "includes/templates/gladstone/css/trebuchet.swf", 
sColor: "#e7d8a7", sEmColor: "#00320e", sWmode : "transparent",sCase : "upper"}));
			}


		return false;
	} 
}


