// JavaScript Document

// Begining of script - to update the total quantity box
function updateQuantity(){

	rightQuantity = document.getElementById('attrib-1').options[document.getElementById('attrib-1').selectedIndex].text;
	leftQuantity = document.getElementById('attrib-2').options[document.getElementById('attrib-2').selectedIndex].text;
	total = parseInt(rightQuantity) + parseInt(leftQuantity);
	document.cart_quantity.cart_quantity.value=(total);
	
}

/**
 * TC  added 17 July 2011
 * Add to cart script
 * Checks if sph power is set where a quanity is not zero
 * checks when clicking add to cart
 * 
 * (Get the attrib- info from the view source)
 */
function addToCartChecks(){
	updateQuantity();
	
	alertmessages = '';
	
	rightQuantity = document.getElementById('attrib-1').options[document.getElementById('attrib-1').selectedIndex].text;
	leftQuantity = document.getElementById('attrib-2').options[document.getElementById('attrib-2').selectedIndex].text;
	
	rightSphere = document.getElementById('attrib-3').options[document.getElementById('attrib-3').selectedIndex].text;
	leftSphere = document.getElementById('attrib-4').options[document.getElementById('attrib-4').selectedIndex].text;
	
	returnStatus  = true;
	
	if (!rightSphere && rightQuantity != '0'){
		alertmessages = 'You have not selected a right eye sphere power.\n';
		returnStatus = false;
	}
	
	if (!leftSphere && leftQuantity != '0'){
		alertmessages += 'You have not selected a left eye sphere power.\n';
		returnStatus = false;	
	}
	
	//check for RE cyl powers
	rightCylElement = document.getElementById('attrib-5');//check html source to find correct attr numbers
	if (rightCylElement){//check if there is a cyl power first
		rightCyl = rightCylElement.options[document.getElementById('attrib-5').selectedIndex].text;
		if (!rightCyl && rightQuantity != '0'){
			alertmessages += 'You have not selected a right eye cyl power.\n';
			returnStatus = false;	
		}
	}
	
	//check for LE cyl powers
	leftCylElement = document.getElementById('attrib-6');
	if (leftCylElement){//check if there is a cyl power first
		leftCyl = leftCylElement.options[document.getElementById('attrib-6').selectedIndex].text;
		if (!leftCyl && leftQuantity != '0'){
			alertmessages += 'You have not selected a left eye cyl power.\n';
			returnStatus = false;	
		}
	}
	
	//check for RE axis
	rightAxisElement = document.getElementById('attrib-13');
	if (rightAxisElement){//check if there is an axis first
		rightAxis = rightAxisElement.options[document.getElementById('attrib-13').selectedIndex].text;
		if (!rightAxis && rightQuantity != '0'){
			alertmessages += 'You have not selected a right cyl axis.\n';
			returnStatus = false;	
		}
	}
	
	//check for LE axis
	leftAxisElement = document.getElementById('attrib-14');
	if (leftAxisElement){//check if there is an axis first
		leftAxis = leftAxisElement.options[document.getElementById('attrib-14').selectedIndex].text;
		if (!leftAxis && leftQuantity != '0'){
			alertmessages += 'You have not selected a left cyl Axis.';
			returnStatus = false;	
		}
	}
	
	if (alertmessages)
		alert(alertmessages);
	
	alertmessages = '';
	
	return returnStatus;
}


function addToCartChecksBifocal(){
	updateQuantity();
	
	alertmessages = '';
	
	rightQuantity = document.getElementById('attrib-1').options[document.getElementById('attrib-1').selectedIndex].text;
	leftQuantity = document.getElementById('attrib-2').options[document.getElementById('attrib-2').selectedIndex].text;
	
	rightSphere = document.getElementById('attrib-3').options[document.getElementById('attrib-3').selectedIndex].text;
	leftSphere = document.getElementById('attrib-4').options[document.getElementById('attrib-4').selectedIndex].text;
	
	returnStatus  = true;
	
	if (!rightSphere && rightQuantity != '0'){
		alertmessages = 'You have not selected a right eye sphere power.\n';
		returnStatus = false;
	}
	
	if (!leftSphere && leftQuantity != '0'){
		alertmessages += 'You have not selected a left eye sphere power.\n';
		returnStatus = false;	
	}
	
	//check for RE add powers
	rightCylElement = document.getElementById('attrib-7');
	if (rightCylElement){//check if there is a cyl power first
		rightCyl = rightCylElement.options[document.getElementById('attrib-7').selectedIndex].text;
		if (!rightCyl && rightQuantity != '0'){
			alertmessages += 'You have not selected a right eye add power.\n';
			returnStatus = false;	
		}
	}
	
	//check for LE add powers
	leftCylElement = document.getElementById('attrib-8');
	if (leftCylElement){//check if there is a cyl power first
		leftCyl = leftCylElement.options[document.getElementById('attrib-8').selectedIndex].text;
		if (!leftCyl && leftQuantity != '0'){
			alertmessages += 'You have not selected a left eye add power.\n';
			returnStatus = false;	
		}
	}
	
	//check for RE axis
	rightAxisElement = document.getElementById('attrib-23');
	if (rightAxisElement){//check if there is an axis first
		rightAxis = rightAxisElement.options[document.getElementById('attrib-23').selectedIndex].text;
		if (!rightAxis && rightQuantity != '0'){
			alertmessages += 'You have not selected a right lens design.\n';
			returnStatus = false;	
		}
	}
	
	//check for LE axis
	leftAxisElement = document.getElementById('attrib-24');
	if (leftAxisElement){//check if there is an axis first
		leftAxis = leftAxisElement.options[document.getElementById('attrib-24').selectedIndex].text;
		if (!leftAxis && leftQuantity != '0'){
			alertmessages += 'You have not selected a left lens design.';
			returnStatus = false;	
		}
	}
	
	if (alertmessages)
		alert(alertmessages);
	
	alertmessages = '';
	
	return returnStatus;
}


function addToCartChecksColours(){
	updateQuantity();
	
	alertmessages = '';
	
	rightQuantity = document.getElementById('attrib-1').options[document.getElementById('attrib-1').selectedIndex].text;
	leftQuantity = document.getElementById('attrib-2').options[document.getElementById('attrib-2').selectedIndex].text;
	
	rightSphere = document.getElementById('attrib-3').options[document.getElementById('attrib-3').selectedIndex].text;
	leftSphere = document.getElementById('attrib-4').options[document.getElementById('attrib-4').selectedIndex].text;
	
	returnStatus  = true;
	
	if (!rightSphere && rightQuantity != '0'){
		alertmessages = 'You have not selected a right eye sphere power.\n';
		returnStatus = false;
	}
	
	if (!leftSphere && leftQuantity != '0'){
		alertmessages += 'You have not selected a left eye sphere power.\n';
		returnStatus = false;	
	}
	
	//check for RE colours
	rightCylElement = document.getElementById('attrib-26');
	if (rightCylElement){//check if there is a cyl power first
		rightCyl = rightCylElement.options[document.getElementById('attrib-26').selectedIndex].text;
		if (!rightCyl && rightQuantity != '0'){
			alertmessages += 'You have not selected a right eye colour.\n';
			returnStatus = false;	
		}
	}
	
	//check for LE colours
	leftCylElement = document.getElementById('attrib-27');
	if (leftCylElement){//check if there is a cyl power first
		leftCyl = leftCylElement.options[document.getElementById('attrib-27').selectedIndex].text;
		if (!leftCyl && leftQuantity != '0'){
			alertmessages += 'You have not selected a left eye colour.\n';
			returnStatus = false;	
		}
	}
	
	if (alertmessages)
		alert(alertmessages);
	
	alertmessages = '';
	
	return returnStatus;
}

