	/*
	* BASIC javascript functions
	*
	*/

function addLoadEvent(func) {
	if (window.addEventListener) window.addEventListener("load", func, false);
	else window.attachEvent("onload", func);
}


/*
	* add's onfocus-listener too text input fields with the className "replace-default"
	* which replaces default value with "", sets background to "#fff", and borderColor to ="#1367B2"
	*/
function addFocusBlurBehav(_id, _opts){
				var elem = document.getElementById(_id);
				if(elem){
					var opts = _opts;
					var txt = elem.value;

				elem.onfocus = function(){
					var curtxt = this.value;
					if (curtxt == txt){
							this.value = '';
							this.setAttribute('style',opts['focus']);
							}
					};

				elem.onblur = function(){
					var curtxt = this.value;
					if (curtxt == ''){
							this.value = txt;
							this.setAttribute('style',opts['blur']);
							}
					};
				}
}

function addOnKeyUpBehav(_lelem,_eelem){
	var lelem = document.getElementById(_lelem);
	var eelem = document.getElementById(_eelem);
  if(lelem) {
  		lelem.onkeyup = function(){
				if (this.value.length>4) eelem.removeAttribute('disabled');
				if (this.value.length<5) eelem.setAttribute('disabled','disabled');
			}
  	}
}

function openPopup(elem) {
	if(elem && elem.nodeName === 'A')  {
		var url = elem.getAttribute('href');
		return window.open(url, '', 'width=600,height=600,menubar=no,toolbar=no,status=no,location=no,resizable=yes,scrollbars=yes');
	}
	return null;
}

var txtOpts = {
	"focus" : "color:#000;background:#fff;border:2px solid #1367B2",
	"blur" : "color:#818181;background:#fff;border:2px solid #ffd768"
};

var zipOpts = {
	"focus" : "color:#000;background:#fff;border:2px solid #1367B2",
	"blur" : "color:#818181;background:#ffe7a5;border:2px solid #ffd768"
};

function addBehaviors(){
	addFocusBlurBehav('txt-search', txtOpts);
	addFocusBlurBehav('GGMzip', zipOpts);
	addOnKeyUpBehav('GGMzip', 'GGMexec');
}

addLoadEvent(addBehaviors);
