// JavaScript Document

// load default actions

addLoadEvent(blurLinks);
addLoadEvent(EmailUnobsfuscate);
addLoadEvent(initSearchField);
addLoadEvent(setAlternatingTableRow);
addLoadEvent(prepareContactForm);

///////////////////////////////////////////////////////////////////

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}



/* remove all focus lines from links when clicked */
function blurLinks() {
	var links = document.getElementsByTagName('a');
	for (i=0;i<links.length;i++) {
		links[i].onfocus = function() {
			this.blur();
		}
	}
}


function EmailUnobsfuscate() {
	
	// find all links in HTML
	var link = document.getElementsByTagName && document.getElementsByTagName("a");
	var email, e;
	
	// examine all links
	for (e = 0; link && e < link.length; e++) {
	
		// does the link have use a class named "email"
		if ((" "+link[e].className+" ").indexOf(" email ") >= 0) {
		
			// get the obfuscated email address
			email = link[e].firstChild.nodeValue.toLowerCase() || "";
			
			// transform into real email address
			email = email.replace(/dot/ig, ".");
			email = email.replace(/\(at\)/ig, "@");
			email = email.replace(/\s/g, "");
			
			// is email valid?
			if (/^[^@]+@[a-z0-9]+([_\.\-]{0,1}[a-z0-9]+)*([\.]{1}[a-z0-9]+)+$/.test(email)) {
			
				// change into a real mailto link
				link[e].href = "mailto:" + email;
				link[e].firstChild.nodeValue = email;
		
			}
		}
	}
}



function initSearchField() {
	$('ajaxSearch_input').onfocus = function() {
		this.className = 'txtHover';
		
		if (this.value=='Enter Keyword') {
			this.value='';
		}
	}
	
	$('ajaxSearch_input').onblur = function() {
		this.className = 'txt';	
		if (this.value=='') {
			this.value='Enter Keyword';
		}
	}
}



function setAlternatingTableRow() {
	var tableRow = $$('table tr');
	
	var rowCount = 0;
	for (i=0;i<tableRow.length;i++) {
		
		if (tableRow[i].className!='heading') {
			
			// loop through children of table row (tr)
			var row = tableRow[i].getElementsByTagName('td');

			for (j=0;j<row.length;j++) {
				if (rowCount % 2 == 0) {
					row[j].className="altrow";
				}
			}
			
		}
		
		rowCount++;
	}
}




function correctPNG(){ // correctly handle PNG transparency in Win IE 5.5 & 6.

   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}




function openPackageDetails(id) {
	new Effect.toggle(id, 'appear', { duration: 1.5 });
}




function prepareContactForm() {
	var fields = $$('.leftColumn form .txt');
	
	 for(var i=0; i<fields.length; i++) {
		 fields[i].onfocus = function() {
			this.className='txtActive'; 
		 }
		 
		 fields[i].onblur = function() {
			this.className='txt'; 
		 }
	 }
}







