/*

	JavaScript Functions (C) 2010 Lexel 
	www.lexel.co.uk
	Author: Jason Gaved

*/

function copyAddress() {
		
		if (document.getElementById("SameAddress").checked == true) {
			document.getElementById("Delivery_Postcode").value = document.getElementById("Postcode").value;
			document.getElementById("Delivery_Address_Line_1").value = document.getElementById("Address_Line_1").value;
			document.getElementById("Delivery_Address_Line_2").value = document.getElementById("Address_Line_2").value;
			document.getElementById("Delivery_Address_Line_3").value = document.getElementById("Address_Line_3").value;
			document.getElementById("Delivery_County").value = document.getElementById("County").value;
			document.getElementById("Delivery_Town").value = document.getElementById("Town").value;
		}
		else {
			document.getElementById("Delivery_Postcode").value = '';
			document.getElementById("Delivery_Address_Line_1").value = '';
			document.getElementById("Delivery_Address_Line_2").value = '';
			document.getElementById("Delivery_Address_Line_3").value = '';
			document.getElementById("Delivery_County").value = '';
			document.getElementById("Delivery_Town").value = '';
		}
		
	}

function addToBasket(ProductID) {
	var Quantity = document.getElementById("Quantity").value;	
    
    var xmlhttp=false;
    
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	    try {
		    xmlhttp = new XMLHttpRequest();
	    } catch (e) {
		    xmlhttp=false;
	    }
    }
    if (!xmlhttp && window.createRequest) {
	    try {
		    xmlhttp = window.createRequest();
	    } catch (e) {
		    xmlhttp=false;
	    }
    }
    
    if (navigator.appName == 'Microsoft Internet Explorer') {
        window.location = '/scripts/add_to_basket_script.asp?ProductID=' + ProductID + '&Quantity=' + Quantity + '&RedirectToCheckout=1';
        return false;
    }
    
    //var xmlhttp =  new XMLHttpRequest();
    xmlhttp.open('POST', '/scripts/add_to_basket_script.asp', true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('ProductID=' + ProductID + '&Quantity=' + Quantity);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
				document.getElementById("Number_Of_Items").innerHTML = xmlhttp.responseText;
				
				//Update Hidden DIV
				document.getElementById("AddedToBasketQty").innerHTML = Quantity + 'x ';
				
				//Display Hidden DIV
				document.getElementById("AddedToBasket").style.display='block';
			}
		}
    }
}

function updateBasket(action, BasketID) {
	window.location='/scripts/update_basket_script.asp?Action=' + action + '&BasketID=' + BasketID;
}

function PAF_Popup(postCode, prefix) {
	if (postCode.length < 5) {
		alert('Please enter a Postcode');
	}
	else {
		window.open('/scripts/postcode_lookup_popup.asp?Postcode=' + postCode + '&AddressPrefix=' + prefix,'Postcode Address Finder','width=500,height=250');
	}
}

function saveDragonDetails() {
	document.getElementById("GoBack").value='1';
	document.getElementById("SaveDragonForm").submit();
}
	
function charCount() {
	document.getElementById("NoOfCharsLeft").innerHTML = document.getElementById("DragonStory").value.length;
	
	if (document.getElementById("DragonStory").value.length > 499) {
		document.getElementById("DragonStory").value = document.getElementById("DragonStory").value.substring(0, 500);
	}
	
	//Show Red Text if its getting near limit
	if (document.getElementById("DragonStory").value.length > 400) {
		document.getElementById("NoOfCharsLeft").style.color = 'red';
	} else {
		document.getElementById("NoOfCharsLeft").style.color = '#570164';	
	}
}

function changeEyeColour(varVal, varVal1) {
	document.getElementById("dragonEyeColour").src = varVal;
	document.getElementById("EyeColourID").value = varVal1;
}

function changePouchColour(varVal, varVal1) {
	document.getElementById("dragonPouchColour").src = varVal;
	document.getElementById("PouchColourID").value = varVal1;
}

function changeSkinColour(varVal, varVal1) {
	document.getElementById("dragonSkinColour").src = varVal;
	document.getElementById("DragonColourID").value = varVal1;
}	

function changePicture(elementName, pictureURL) {
	document.getElementById(elementName).src = pictureURL;
}
