/* Peppered js library */


// addLoadEvent

function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() { 
			oldonload();
			func();
		}
	}
}


// external links (jq)

$(function() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
});



/****************
 * Form class/object v0.1.3 wip
 * @author arjen
 */

function Form(id) {
	this.elementId = id;
	this.element = null;
	if (document.getElementById(id))
		this.element = document.getElementById(id);
}


// FormField child object

Form.prototype.FormField = function(id) {

	this.elementId = id;
	this.element = null;
	if (document.getElementById(id))
		this.element = document.getElementById(id);
	this.element.formObject = this; // for referencing in element events
}

Form.prototype.FormField.prototype.setDefaultValue = function(sValue) {
	var sDefaultTxt = sValue;
	this.element.value = sDefaultTxt;
	this.element.onfocus = function(){
		if (this.value == sDefaultTxt)
			this.value = '';
	};
	this.element.onblur = function(){
		if (this.value == '')
			this.value = sDefaultTxt;
	};
}

Form.prototype.FormField.prototype.onClick = function(func) {
	this.element.onclick = function() {
		eval('this.formObject.' + func);
	}
}

Form.prototype.FormField.prototype.spawnField = function(sType, sName, sLabel) {
	if (!this.element.checked && this.spawnedField) {
		this.spawnedField.parentNode.removeChild(this.spawnedField);
		return;
	}

	oParent = this.element.parentNode;
	oDivsParent = oParent.parentNode;
	
	//console.log(oParent);
	var oDiv = document.createElement('div');
	var oInput = document.createElement('input');
	var oLabel = document.createElement('label');
	var oLTxt = document.createTextNode(sLabel);
	
	oLabel.appendChild(oLTxt);
	oLabel.setAttribute('for', sName);
	
	oInput.setAttribute('type', sType);
	oInput.setAttribute('name', sName);
	
	oDiv.appendChild(oLabel);
	oDiv.appendChild(oInput);
	oNew = oDivsParent.insertBefore(oDiv, oParent.nextSibling);
	this.spawnedField = oNew;
	
	oInput.focus();
	
}

// enableImgHover (imgbutton fields)

Form.prototype.FormField.prototype.enableImgHover = function() {
	var sImg = this.element.src;
	var sExt = sImg.substring(sImg.length-3);
	var sHoverImg = sImg.substring(0, sImg.length-4) + '_over' + '.' + sExt;
	
	this.img = sImg;
	this.hoverImg = sHoverImg;
	
	var agt=navigator.userAgent.toLowerCase();
	// Note: On IE5, these return 4
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var ie_alphaImg = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1 || agt.indexOf("msie 6.") != -1));
	
	if (sExt == 'png' && is_ie && ie_alphaImg) {
		this.element.onmouseover = function() {
			//this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sHoverImg + "',sizingMethod='image')";
			this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
			this.parentNode.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sHoverImg + "',sizingMethod='image')";
		};
		this.element.onmouseout = function(){
			//this.runtimeStyle.filter = '';
			this.parentNode.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sImg + "',sizingMethod='image')";;
		};
		return;
	}

	this.element.onmouseover = this.element.onfocus = function(){this.src = this.formObject.hoverImg};
	this.element.onmouseout = this.element.onblur = function(){this.src = this.formObject.img};
}


/*
 * This script is written by Geert Van Aken
 * Please read the official documentation for more information
 * about the functions of this file.
 *
 * http://altum.be/products/emailobfuscator
 *
 * Please do not remove this information from the file and
 * report improvements that you make to this sourcecode
 *
 * Version 1.1.0
 * Date    2006/04/11
 * 
 * Adaption by Peppered
 * 
 */

var monkeyCode = 4 << 4;
var oldStatusText = "";

function EOa() {
  return String.fromCharCode(monkeyCode);
}

function EOd(pText) {
  var splitted = pText.split(",");
  var result = "";

  for (i = 0 ; i < splitted.length ; i++) {
    result += String.fromCharCode(splitted[i]);
  }
  return result;
}

function EOp() {
  var prefix = EOd('109,97,105');
  prefix += EOd('108,116');
  return prefix + EOd('111,58');
}

function EOad(pName, pdomain) {
  EOad(pName, pDomain, null);
}

function EOinitStatus(pName, pDomain) {
  oldStatusText = window.status;
  window.status = Loc(pName, pDomain);
}

function EOrestoreStatus() {
  window.status = oldStatusText;
}

function pepEObf(pName, pDomain, pSubj, pHover, pText, pClass) {

//  alert("pName = " + pName + "\npDomain = " + pDomain + "\npSubj = " + pSubj + "\npHover = " + pHover + "\npText = " + pText + "\npClass = " + pClass);

  var result = "<a href=\"JavaScript:EOad('" + pName + "','" + pDomain + "'";
  if (pSubj != null && pSubj.length > 2) {
    result += ",'" + pSubj + "'";
  }
  result += ");\"";

  if (pHover != null && pHover.length > 0) {
    result += " title=\"" + EOd(pHover) + "\"";
  }

  if (pClass != null && pClass.length > 0) {
    result += " class=\"" + pClass + "\"";
  }

  result += " onMouseOver=\"EOinitStatus('" + pName + "','" + pDomain + "');return true;\" onMouseOut=\"EOrestoreStatus();\"";

  result += ">" + EOd(pText) + "</a>";

//  alert(result);

  document.write(result);

}

function EOad(pName, pDomain, pSubj) {
  var loc = Loc(pName, pDomain);
  if (pSubj != null && pSubj.length > 0) {
    loc += "?" + EOd('115,117,98,106,101,99,116') + "=" + encodeURIComponent(EOd(pSubj));
  }

  document.location = loc;
}

function Loc(pName, pDomain) {
  var first = EOd(pName);
  var second = EOd(pDomain);
  var loc = EOp() + first + EOa() + second; 
  
  return loc;
}