// JavaScript Document
// ONLINE-SHOP.js

	//*************************
	//swapImage(imagea,imageb)
	//Functions to Swap Images - online shop
	function swapImage(imagea,imageb){
		//alert("swapImage: " + imagea + " with " + imageb);
		var urlA = $(imagea).src;
		var urlB = $(imageb).src;
		
		var altA = $(imagea).alt;
		var altB = $(imageb).alt;
		
		var thumbHeightA = $(imagea + 'ThumbHeight').value;
		var thumbHeightB = $(imagea + 'ThumbHeight').value;

		var miniHeightA  = $(imagea + 'MiniHeight').value;
		var miniHeightB  = $(imagea + 'MiniHeight').value;


		//update file location
		urlA = urlA.replace(/mini/,"thumbs");
		urlB = urlB.replace(/thumbs/,"mini");
	
		//put the thumbs image in place
		$(imagea).src = urlB;
		
		//put the mini image in place
		$(imageb).src = urlA;
		
		//swap the alts & titles!
		$(imagea).alt 	= altB;
		$(imagea).title = altB;
		
		$(imageb).alt 	= altA;
		$(imageb).title = altA;
		
		//swap image width/height
		$(imagea).width 	= '80';
		$(imagea).height 	= miniHeightB;

		$(imageb).width 	= '180';
		$(imageb).height	= thumbHeightA;
		
		//swap hidden values
		$(imagea + 'ThumbHeight').value	 = thumbHeightB;
		$(imagea + 'MiniHeight').value	 = miniHeightB;
		
		$(imageb + 'ThumbHeight').value	 = thumbHeightA;
		$(imageb + 'MiniHeight').value	 = miniHeightA;
		
	}
	//*************************


	//*************************
	//validateAddForm()
	//This form calidates add to basket form (quantity/size)
	function validateAddForm(){
		
		errorCount = 0;
		errorList  = new String();
		
		if($('Size')){
			if($F('Size') == ''){
				errorCount++;
				errorList += '\n- You must select your size    '
			}			
		}
		
		if($('Colour')){
			if($F('Colour') == ''){
				errorCount++;
				errorList += '\n- You must select your colour    '
			}			
		}
		
		if(errorCount==0){
			output = true;	
		} else if(errorCount == 1){
			output = false;
			
			errorMessage = 'The following error has occurred -   \n';
			errorMessage += errorList;
			errorMessage += '\n\nPlease make this change before clicking \'Add To Basket\'.   ';
			
		} else {
			output = false;
			
			errorMessage = 'The following errors have occurred -   \n';
			errorMessage += errorList;
			errorMessage += '\n\nPlease make these change before clicking \'Add To Basket\'.   ';
		}
		
		if(output == false){
			alert(errorMessage);	
		}
		
		return output;
	}
	//*************************
	
	
	//*************************
	//validateExtraOptions()
	//This function validates additional options before adding item to basket
	function validateExtraOptions(){
		
		//initialise the error variables
		var errorList 	 = "";
		var errorCount 	 = 0;
		var errorMessage = "";
		
		
		//LeftRightHand
		if($('LeftRightHand')){
			if(isBlank(selectValues("LeftRightHand","value"))){
				errorList 	+= "\n- You must select either Left or Right hand.     ";
				errorCount 	+= 1;
			}
		}
	
		//PersonaliseName
		if($('PersonaliseName')){
			if($('PersonaliseName').value == ''){
				errorList 	+= "\n- You must enter the name.     ";
				errorCount 	+= 1;
			}
		}
	
		//Country
		if($('Country')){
			if(isBlank(selectValues("Country","value"))){
				errorList 	+= "\n- You must select the country.     ";
			errorCount 	+= 1;
			}
		}
		
		//CountryFlag
		if($('CountryFlagNo') && $('CountryFlagYes')){
			if($('CountryFlagNo').checked == false && $('CountryFlagYes').checked == false){
				errorList 	+= "\n- You must select if you would like the country flag on item.     ";
				errorCount 	+= 1;
			}

			//PositionFlag
			if($('PositionFlag')){
				if($('CountryFlagYes').checked == true && isBlank(selectValues("PositionFlag","value"))){
					errorList 	+= "\n- You must select where you would like the flag to appear.     ";
					errorCount 	+= 1;
				}
			}
		}


		//check for errors!
		if(errorCount > 0){
			
			if(errorCount == 1){
				errorMessage = "The following error occurred whilst processing your details.     ";
				errorMessage += "\n" + errorList + "\n";
				errorMessage += "\nPlease fix this error before clicking 'Add to Basket'.     ";
			} 
			else {
				errorMessage = "The following errors occurred whilst processing your details.     ";
				errorMessage += "\n" + errorList + "\n";
				errorMessage += "\nPlease fix these errors before clicking 'Add to Basket'.     ";	
			}
			
			alert(errorMessage);
			return false;
		} 
		else {
			return true;
		}

	}
	//*************************
	
	