var clearFormValue = {
	initialize: function () {
		this.clearInputs();
	},
	clearInputs : function(){
		if (!document.getElementsByTagName)return false;
		if (!document.getElementById) return false;
		if (!document.getElementById("tab-suppliers") && !document.getElementById("tab-courses")){
			return false;
		}
		var formA = document.getElementById("suppliersForm");
		var inputA = formA.getElementsByTagName("input");
		for(var j=0; j < inputA.length; j++){
			if(inputA[j].type=='text'){
				inputA[j].onfocus = function() {
					if(this.className.match(/txt-keyword?/) && this.value == 'KEYWORDS (Separate by commas)' ){
						this.value = '';
					}
					if(this.className.match(/txt-postcode?/) && this.value == 'ENTER POSTCODE' ){
						this.value = '';
					}
				}
				inputA[j].onblur = function() {
					if(this.className.match(/txt-keyword?/) && this.value == ''){
						this.value = 'KEYWORDS (Separate by commas)';
					}
					if(this.className.match(/txt-postcode?/) && this.value == ''){
						this.value = 'ENTER POSTCODE';
					}
				}
			}		
		}
		var formB = document.getElementById("courseForm");
		var inputB = formB.getElementsByTagName("input");
		for(var j=0; j < inputB.length; j++){
			if(inputB[j].type=='text'){
				inputB[j].onfocus = function() {
					if(this.className.match(/txt-postcode?/) && this.value == 'ENTER POSTCODE' ){
						this.value = '';
					}
				}
				inputB[j].onblur = function() {
					if(this.className.match(/txt-postcode?/) && this.value == ''){
						this.value = 'ENTER POSTCODE';
					}
				}
			}		
		}
	}
}

var submitButtonReplacement = {
	initialize: function (classname) {
		this.classname = classname;
		this.allButtons = document.getElementsByTagName('input');
		this.replaceButtons();
	},
	replaceButtons : function(){
		if(this.allButtons){
			var inputCounter = this.allButtons.length;
			for(i = 0; i < inputCounter; i++){
				if( this.allButtons[i].className == this.classname ){
					this.allButtons[i].style.display = "none";
					var theAnchor = document.createElement("a");
					var theEm = document.createElement("em");
					var theText = document.createTextNode(this.allButtons[i].value);
					theAnchor.appendChild(theEm);
					theAnchor.appendChild(theText);
					theAnchor.setAttribute('href', location.href + '#');
					theAnchor.className = this.classname;
					var insertedElement = this.allButtons[i].parentNode.insertBefore(theAnchor, this.allButtons[i]);
					insertedElement.onclick = function(){
						this.nextSibling.click();
					}
				}
			}
		}
	}
}


$(document).ready(function(){
	clearFormValue.initialize();
	submitButtonReplacement.initialize('replaceSubmit');
});