jQuery(function() {
	jQuery('.pullLink').removeClass('hiddenLink');
	jQuery('.hideLink').addClass('hiddenLink');
});
jQuery( document ).ready( function(){
	var theForm = document.forms[0];
	if( theForm )
		for(i=0;i<theForm.elements.length;i++)
			if((theForm.elements[i].type=="text") || (theForm.elements[i].type=="password") || (theForm.elements[i].type=="textarea")) {
				theForm.elements[i].focus();
				break;
			}
	var productArr = ["external", "new_popup", "popup"];
	jQuery.each( productArr, function(i) {
		switch (i) {
			case 0 : jQuery("a[rel='external']").click(function() {
							window.open(this.href);
							return false;
						});
						break;
			case 1 : jQuery("a[rel='new_popup']").click(function() {
							var delim = (this.href.indexOf('?') >= 0) ? '&' : '?';
							var h = parseInt(getParameterByNameFromURL('height', this.href));
							var w = parseInt(getParameterByNameFromURL('width',  this.href));
							if (!h) { h = 400; }
							if (!w) { w = 500; }
							var features = "height=" + h + ",width=" + w + ",menubar=0,status=0,location=0,toolbar=0,scrollbars=yes,resizable=yes";
							newwindow=window.open(this.href , 'newPopup', features);
							return false;
						});
						break;
			default : jQuery("a[rel=" + productArr[i] + "]").click(function() {
							var delim = (this.href.indexOf('?') >= 0) ? '&' : '?';
							var h = parseInt(getParameterByNameFromURL('height', this.href));
							var w = parseInt(getParameterByNameFromURL('width',  this.href));
							if (!h) { h = 450; }
							if (!w) { w = 500; }
							var features = "height=" + h + ",width=" + w + ",menubar=0,status=0,location=0,toolbar=0,scrollbars=yes,resizable=yes";
							newwindow=window.open(this.href + delim + 'popup=true', 'Popup', features);
							return false;
						});
		}
	});
	jQuery("a[rel='lightbox']").click(function() {
		var link = jQuery(this).attr("href")
		var h = parseInt(getParameterByNameFromURL('height', link));
		var w = parseInt(getParameterByNameFromURL('width',  link));
		if (!h) { h = 360; }
		if (!w) { w = 500; }
		if(link.indexOf("?")!=-1)
			link = link+"&popup=true&lb=true"
		else
			link = link+"?popup=true&lb=true"
		jQuery("#lightbox-border").addClass(jQuery(this).attr("title"));
		jQuery("#lightbox-border").prepend('<div class="lightbox-tl"><\/div><div class="lightbox-top"><\/div><div class="lightbox-tr"><\/div><div id="lightbox-close"><\/div><div class="clear-both"><\/div><div id="lightbox-content"><\/div>');
		jQuery("#lightbox-border").append('<div class="lightbox-bl"><\/div><div class="lightbox-bottom"><\/div><div class="lightbox-br"><\/div>');
		jQuery("#lightbox-content").addClass(jQuery(this).attr("class")).get(jQuery(this).attr("href"));
		if(jQuery(this).attr("href").indexOf("http") != "-1")
			jQuery("#lightbox-content").html("<iframe src='"+link+"' width='"+w+"' height='"+h+"' frameborder='0'><\/iframe>");
		else {
			jQuery("#lightbox-content").load(link, function(){
				jQuery("#lightbox-content a[rel='external']").each(function(){
					jQuery(this).click(function(){window.open(jQuery(this).attr('href')); return false;});
				});
			});
		}
		if( typeof utEvtTag == 'function' ) {
			utEvtTag('ev=lightbox_open&evdetail=' + escape(jQuery(this)[0].href));
		}
		jQuery("#lightbox-container").fadeIn(100);
		jQuery("#lightbox-close").hover(function(){ jQuery(this).css('cursor','pointer') });
		jQuery("div#lightbox-close").click(function() {
			lightboxClose();
		});
		return false;
	});
});
function preFillElements(theObject, flag) {
	if(flag) {
		for(i=0;i<theObject.length;i++) {
			theTarget = document.getElementById(theObject[i][0]);
			if(theTarget.value == "")
				theTarget.value = theObject[i][1];
			(flag == "prefill" && theTarget.value == theObject[i][1] ) ? eventHandlerClass('add', theTarget, flag) : clearElement(theTarget, theObject[i][1]);
		}
	}
	return true;
}
function clearElement(theObject, defaultText, refill) {
	theAction = ( refill && ( ( theObject.value == "" ) || ( theObject.value == defaultText ) ) ) ? 'add' : 'remove';
	eventHandlerClass( theAction, theObject, 'prefill' );
	if( refill && theObject.value == "" )
		theObject.value = defaultText;
	else if( theObject.value == defaultText )
		theObject.value = "";
}
function eventHandlerClass(theAction,theObj,class1,class2) {
	switch( theAction )	{
		case 'add':
			if(!eventHandlerClass('check',theObj,class1)){theObj.className+=theObj.className?' '+class1:class1;}
			break;
		case 'remove':
			var rep = theObj.className.match(' '+class1) ? ' ' + class1 : class1;
			theObj.className = theObj.className.replace(rep, '');
			break;
		case 'check':
			return new RegExp('\\b'+class1+'\\b').test(theObj.className)
			break;
	}
}
function getParameterByNameFromURL(name, url) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(url);
	if(results == null) {
		return "";
	}
	else {
		return results[1];
	}
}
function utEvtTag(sEvt) {
	try {
		ntptEventTag(sEvt);
	}catch (e) {}
}
function lightboxClose(){
		jQuery("#lightbox-container").fadeOut(100, function(){
		jQuery("#lightbox-border").removeClass().html("");
		jQuery("#lightbox-container").hide();
	});
}
