// Konqueror and safari minor then 2.0 have problems with some javascripts used in these pages 
var buggedKHTML = false;
if (isKHTML && isMinSafari2==false ) buggedKHTML = true;
//alert(buggedKHTML);

var blurTextboxes = function(element, defValue) {
	//textfield.value = '';
	if (element.value.match(/^ *$/)) {
		if (element.id == 'password') {
			if (!buggedKHTML) {
				element.hide();
				$('txtpassword').show();
			}
		} else if(element.id == 'confirm_password') {
			if (!buggedKHTML) {
				element.hide();
				$('txtconfirm_password').show();
			}
		} else {
			element.value=defValue;
			$(element).addClassName('blank');
		}
	};
}

var focusTextboxes = function(element, defValue) {
	if (element.value == defValue) {
		if (element.id == 'txtpassword') {
			if (!buggedKHTML) {
				element.hide();
				$('password').clear();
				$('password').removeClassName('blank');
				$('password').show();
				$('password').focus();
			}
		} else if(element.id == 'txtconfirm_password') {
			if (!buggedKHTML) {
				element.hide();
				$('confirm_password').clear();
				$('confirm_password').removeClassName('blank');
				$('confirm_password').show();
				$('confirm_password').focus();
			}
		} else {
			element.value='';
			$(element).removeClassName('blank');
		}
	};
}


var removeBlankClass = function(form, hashInputValues) {
	
	subscription_form = $(form);
	aFormInputsform = subscription_form.getElements();
	aFormInputsform.each(function(field) {
		var sFieldValue = field.value;
		var sFieldName = field.name;
		//alert(sFieldValue + ': ' + eval('hashInputValues.get(\'' + sFieldName + '\')'));
		if (sFieldValue != eval('hashInputValues.get(\'' + sFieldName + '\')')) {
			if (sFieldName!='submit') {
				$(sFieldName).removeClassName('blank');
			}
		}
		
		if (sFieldValue == '') {
			//If middle_name, credits, password, confirm_password, video we empty it
			if(sFieldName!='password' && sFieldName!='confirm_password' && sFieldName!='submit') {
				$(sFieldName).value = eval('hashInputValues.get(\'' + sFieldName + '\')');
				$(sFieldName).addClassName('blank');
			}
		}
		//alert(eval('hashInputValues.' + sFieldName));
	});
}


// Add some validations to default validation.js validations
Validation.addAllThese([
	['validate-zip', 'Please enter a valid postal code in this field.', function(v) {
		return Validation.get('IsEmpty').test(v) || /^((\d{5}-\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$/.test(v);
	}],
	['validate-phone-us', 'Please enter a valid phone number in this field.', function(v) {
		return Validation.get('IsEmpty').test(v) || /^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/.test(v);
	}],
	['validate-year', 'Please enter a valid year in this field.', function(v) {
		return Validation.get('IsEmpty').test(v) || (!isNaN(v) && v.length == 4);
	}],
	['validate-month', 'Please enter a valid month number (1-12) in this field.', function(v) {
		return Validation.get('IsEmpty').test(v) || (!isNaN(v) && v >= 1 && v <= 12);
	}],
	['validate-date-us', 'Please use this date format: mm/dd/yyyy. For example 03/17/2006 for the 17th of March, 2006.', function(v) {
		if(Validation.get('IsEmpty').test(v)) return true;
		var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
		if(!regex.test(v)) return false;
		var d = new Date(v.replace(regex, '$1/$2/$3'));
		return ( parseInt(RegExp.$1, 10) == (1+d.getMonth()) ) &&
					(parseInt(RegExp.$2, 10) == d.getDate()) &&
					(parseInt(RegExp.$3, 10) == d.getFullYear() );
	}],
	['validate-select-field', 'Please chose a value.', function(v) {
		return Validation.get('IsEmpty').test(v) || v != '-1';
	}],
	['validate-state', 'Please insert a valid state/province', {
		minLength : 2,
		maxLength : 2,
		include: ['validate-alpha']
	}],
	['validate-confirm-password', 'Confirmation password doesn\'t match', {
		equalToField : 'password'
	}]
]);
	
