/*
Sony Style core form functionality Javascript
AUTHOR: Jonathan Cheung
===================================================================================================================================================================
// !  * Core form javascript logic.
* 	PRE-CONDITIONS:
*
* 	Required JS files: prototype.js, validation.js, ss_core_omniture.js
*
// ===================================================================================================================================================================
*/
Event.observe(window, 'load', function (){
	/*******
	* Custom Input Text Prompt
	*
	*
	******/

	//Select input tags with caption attribute
	$$("input[caption]").each(function (thisElement){

		//If there isn't any value we will set the visual prompt text inside the box.
		if (thisElement.value == ""){
			//We add the captioned class so we can check for on focus action
			thisElement.addClassName('captioned');

			if (thisElement.readAttribute('type') == 'password'){
				if (!Prototype.Browser.IE){
					//If it is a password element, we set the caption and set the type to text
					thisElement.value = thisElement.readAttribute('caption');
					thisElement.setAttribute('originalType', 'password');
					thisElement.type = "text";
				}
				else{
					thisElement.writeAttribute('caption','');
				}
			}else{
				thisElement.value = thisElement.readAttribute('caption');
			}
		}

		Event.observe(thisElement, 'focus', function(e){
			//We do these things when the user clicks on the input field.
			var thisElement = Event.element(e);
			if (thisElement.hasClassName('captioned')){
				thisElement.value = '';
				thisElement.removeClassName('captioned');
			}
			//Set the fields to masked
			if (thisElement.readAttribute('originalType') == "password") thisElement.type = "password"

		});

		Event.observe(thisElement, 'blur', function(e){
			// We do these when the user exits the field.
			var thisElement = Event.element(e);

			if (thisElement.value == ''){
				if (thisElement.readAttribute('originalType') == "password") {
					thisElement.type = "text";
				}
				thisElement.value = thisElement.readAttribute('caption');
				thisElement.addClassName('captioned');

			}

		})
	});


	//This initializes the sIFR flash text for the login page.
	sIFR.replace(AvantGardeBook, {
	  selector: '.sfrLoginHeader',
	  css: ['.sIFR-root { color: #44b3e1; font-size: 32px }'],
	  wmode: 'transparent'

	});

	//This initializes the sIFR flash text for the login page.
	sIFR.replace(AvantGardeBook, {
	  selector: '.cartHeaderContainer .cartAreaHeader',
	  css: ['.sIFR-root { color: #333333; font-size: 28px;}'],
	  tuneHeight: 25,
	  offsetTop: 25,
	  forceSingleLine: true,
	  wmode: 'transparent'
	});

	//This initializes the sIFR flash text for the login page.
	sIFR.replace(AvantGardeBook, {
	  selector: '.checkoutStepOneContent .cartAreaHeader',
	  css: ['.sIFR-root { color: #44b3e1; font-size: 28px;}'],
	  tuneHeight: 25,
	  offsetTop: 25,
	  forceSingleLine: true,
	  wmode: 'transparent'
	});



	//This initializes the sIFR flash text for the login page.
	sIFR.replace(AvantGardeBook, {
	  selector: '.formPageHeader',
	  css: ['.sIFR-root { color: #333333; font-size: 20px;}'],
	  forceSingleLine: true,
	  wmode: 'transparent'
	});

});