// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) 
       return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
       return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}

// Implement business logic    
function doWork(){    
    httpObject = getHTTPObject();
    if (httpObject != null) {
		var comboValue; 
		
		var selIndex = document.product_form.FirstColour.selectedIndex; 
		
		comboValue = document.product_form.FirstColour.options[selIndex].value; 
		var url="http://www.maryclaris.com/change_price.php?option="+comboValue+"&default_price="+default_price;
        httpObject.open("GET", url, true);
        httpObject.send(null); 
        httpObject.onreadystatechange = setOutput;
    }else
	{
		alert("no object here");
	}
}

// Change the value of the outputText field
function setOutput(){
    if(httpObject.readyState == 4){
	   document.getElementById('price_item').childNodes[0].nodeValue 
            = httpObject.responseText;
      // document.getElementById('final_price').value= httpObject.responseText;
    }
 
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > str.length)
	    return str;
	else
	    return str.substring(0,n);
}

function show_second_image(){
		
	var comboValue;
	var myRegExp = '(:';
	var selIndex = document.product_form.SecondColour.selectedIndex;
	comboValue = document.product_form.SecondColour.options[selIndex].value;
    var img = document.createElement('img');

	var matchPos1 = comboValue.indexOf(myRegExp);
	
	if(matchPos1 != -1)
		comboValue =Left(comboValue,matchPos1);
	
	img.onload = function (evt) {
        document.getElementById('img_scolor').src=this.src;
        document.getElementById('img_scolor').width=this.width;
        document.getElementById('img_scolor').height=this.height;
    }
	url='http://www.maryclaris.com/images/color_chart/'+comboValue+'.jpg';
	img.src = url;
    return false;
}
function checkcolours(){

	var selIndex1 = document.product_form.FirstColour.selectedIndex;
	var selIndex2 = document.product_form.SecondColour.selectedIndex;
	if(document.product_form.FirstColour.options[selIndex1].value==document.product_form.SecondColour.options[selIndex2].value)
	{
		alert("Please select a different second colour");
		return false;
	}
}
function show_image(){
	
	var comboValue;
	var myRegExp = '(:';

	
	var selIndex = document.product_form.FirstColour.selectedIndex;

	comboValue = document.product_form.FirstColour.options[selIndex].value;
	
	var matchPos1 = comboValue.indexOf(myRegExp);
	
	if(matchPos1 != -1)
		comboValue =Left(comboValue,matchPos1);
	
    var img = document.createElement('img');
    img.onload = function (evt) {
        document.getElementById('img_fcolor').src=this.src;
        document.getElementById('img_fcolor').width=this.width;
        document.getElementById('img_fcolor').height=this.height;
    }
	url='http://www.maryclaris.com/images/color_chart/'+comboValue+'.jpg';
		
    img.src = url;
    return false;
}

function CheckElement(element,string)
{
if ( typeof(element) != "undefined")
			{
				 if (element.value == "-1") 
				 {
						 if(string=="")
				        alert('Please enter your '+ element.name ); 
						else
						alert(string);
						element.focus();
					     return false;
				  }
			}	
			return true;
}
function checkform(form)
{ 


	if(!CheckElement(form.quantity,"Please choose the quantity of products you need"))return false;
	if(!CheckElement(form.length,"Please choose the length of your product"))return false;
	if(!CheckElement(form.FirstColour,"Please choose your first colour"))return false;
	if(!CheckElement(form.SecondColour,"Please choose your second colour"))return false;
	return true;
}

function submitForm(form)
{
	window.location.href = "http://www.maryclaris.com/wishlist.php?quantity=" + form.quantity.value + "&firstcolour=" + form.FirstColour.value + "&SecondColour=" + form.SecondColour.value+"&p="+form.p.value+"&product_page="+form.product_page.value+"&action=add&pd_price="+form.pd_price.value;
	
}


