$(document).ready( function() {	
	$("a[href^='http']").each(function(i) {
        var $this = $(this);

        $this.bind("click", function() {
           pageTracker._trackPageview("/outgoing/"+$this.attr('href'));
        });       
    });

	$("a[href$='pdf'],[href$='doc'],[href$='xls'],[href$='jpg'],[href$='gif'],[href$='ppt']").each(function(i) {
        var $this = $(this);
        $this.bind("click", function() {
           pageTracker._trackPageview("/downloads/"+$this.attr('href'));
        });       
    });

});


/*
 * Popup window script 
 *  
 * Example markup 
 * <a href="mypage.html" onclick="popUpWin(this.href,'console',660,520);return false;" title="Open popup window">Link text</a>
 */
var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}


function ShowSection(parentElement, selectedElement)
{
	alert(parentElement + " " + selectedElement.value);
	
	// hide all child div's inside section_area div 
	$("#" + parentElement +" > div").hide();	
	// show the element	
	$("#" + selectedElement.value).show();
	
}



/****************** EMAIL DECRYPTION *********************/
function decrypt_string(crypted_string) {

	var numbers = crypted_string.split(' ');			
	n = numbers[0];	decryption_key = numbers[1];			
	numbers[0] = ""; numbers[1] = "";				
	crypted_string = numbers.join(" ").substr(2);


	var decrypted_string = '';
	var crypted_characters = crypted_string.split(' ');
	var i;
	
	for(i = 0; i< crypted_characters.length; i++) {
		var current_character = crypted_characters[i];
		var decrypted_character = exponentialModulo(current_character,n,decryption_key);
		decrypted_string += String.fromCharCode(decrypted_character);
	}
	
	return decrypted_string;
}


// Finds base^exponent % y for large values of (base^exponent)
function exponentialModulo(base,exponent,y) {
	if (y % 2 == 0) {
		answer = 1;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	} else {
		answer = base;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	}
	return answer;
}

function sendEmail(dat)
{
    document.location.href='mailto:' + do_decrypt ( dat );
}


function do_decrypt(dat)
{ 
	return decrypt_string ( dat, 0, 0 ,'');
}



function displayError(formNode, validators) {
    var errorHTML = "";
    for (var i = 0; i < validators.length; i++) {
        errorHTML += "<li>" + validators[i].message + "</li>";
  
          
    }

    $('#errorDisplay').css('display', 'block');
    if (validators.length != 0) {
        $('#errorDisplay').html("<h4>Please correct the following problems</h4><ul style='margin-top:5px'>" + errorHTML + "</ul>");
    }

}
function resetError() {
    $('#errorDisplay').html("");
}