
if ('undefined'!=typeof(jQuery)){
jQuery.noConflict();
}

function isAvailable(date){

	var dateAsString = date.getFullYear().toString() + "-" + (date.getMonth()+1).toString() + "-" + date.getDate();
	var result = jQuery.inArray( dateAsString, bookedDays ) ==-1 ? [true] : [false];
	return result
	}

function switch_editing_mode(url,val)
	{
	var original_url = window.location.href;
	jQuery.get(url+'&task=switcheditingmode&switchmode='+val,function(data){
		window.location = original_url;
		});
	}
	
/*
Interesting proof of concept, but not ready for showtime
function switch_editing_mode(url,val)
	{
	var original_url = window.location.href;
		jQuery('div.jomres_content_area').block({
			message: '<img src="jomres/images/31.gif" />', 
			css:	{
					padding: '15px', 
					'-webkit-border-radius': '10px', 
					'-moz-border-radius': '10px'
					}
				});	
	jQuery.get(url+'&task=switcheditingmode&switchmode='+val,function(data){

		jQuery.get(original_url+"&format=raw",
			function(data){
				populateDiv('jomres_content_area',data);
				}
			);
		jQuery('div.jomres_content_area').unblock();
	});
	//window.location.reload();
	}
*/

function populateDiv(div_id,content){
	if ( jQuery("#"+div_id).length > 0 ){ 
		document.getElementById(div_id).innerHTML = content;
		jQuery(div_id).fadeIn(100);
		}
	}

function jomres_isChecked(ischecked){
	if (ischecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}

function jomres_checkAll( n ) {
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.cb' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.adminForm.boxchecked.value = n2;
	} else {
		document.adminForm.boxchecked.value = 0;
	}
}



function jomres_submitbutton(pressbutton) {
	/*
	var hid = jQuery('<input type="text" name="nohtml" value="1"/>');
	hid.prependTo("adminForm");
	var theval = jQuery("input[name=nohtml]").val();
	alert(theval);
	return;
	*/
	document.adminForm.task.value=pressbutton;
	try {
		document.adminForm.onsubmit();
		}
	catch(e){}
	document.adminForm.submit();
}

function disableSubmitButton (button) {
	if (typeof button.disabled != 'undefined')
		button.disabled = true;
	else if (!button.buttonDisabled) {
		button.oldValue = button.value;
		button.oldOnclick = button.onclick;
		button.value = 'DISABLED';
		button.onclick = cancelAction;
		button.buttonDisabled = true;
		}
	document.getElementById("submitbutton").className="";
	}
	
function enableSubmitButton (button) {
	if (typeof button.disabled != 'undefined')
		button.disabled = false;
	else if (button.buttonDisabled) {
		button.value = button.oldValue;
		button.onclick = button.oldOnclick;
		button.buttonDisabled = false;
		}
	var exists = document.getElementById("roomalert_top");
	if (exists != null) {
		document.getElementById("submitbutton").className="oktobook";
		document.getElementById("roomalert_top").className="roomalert_off";
		document.getElementById("roomalert_bottom").className="roomalert_off";
		}
	// Disabled as causes a js error in ie if the booking form is in the property details.
	//document.getElementById('submitbutton').focus();
	}

	
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 8;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari 1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	 Show hide stuff
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

function hidediv(elementName) {
	}

function showdiv($elementName) {
	}

///////////////////////////////////////
//
//	Generic onload by Brothercake
//	http://www.brothercake.com/
//
///////////////////////////////////////

//onload function
function generic(){
	if ( toload.length > 0 ){
		for (x in toload){
			eval(toload[x]);
			}
		}
	if ( document.ajaxform !=undefined ) 
		disableSubmitButton(document.ajaxform.confirmbooking);
	}
	
//setup onload function
var undefined;
var toload=new Array();
var templateVersion = 2.5;

if(typeof window.addEventListener != 'undefined'){
	//.. gecko, safari, konqueror and standard
	window.addEventListener('load', generic, false);
	}
else if(typeof document.addEventListener != 'undefined'){
	//.. opera 7
	document.addEventListener('load', generic, false);
	}
else if(typeof window.attachEvent != 'undefined'){
	//.. win/ie
	window.attachEvent('onload', generic);
	}

//** remove this condition to degrade older browsers
else {
	//.. mac/ie5 and anything else that gets this far
	//if there's an existing onload function
	if(typeof window.onload == 'function'){
		//store it
		var existing = onload;
		
		//add new onload handler
		window.onload = function(){
		//call existing onload function
		existing();
		//call generic onload function
		generic();
		};
	}
	else{
		//setup onload function
		window.onload = generic;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	 Ajax get response stuff
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getResponse_particulars(field,value) {
	HideRoomsList();
	blockInterface(field,200);
	jQuery.get(ajaxurl+'&task=handlereq',{ field: field, 'value': value },
		function(data){
			showRoomsList(data); 
			show_log(field);
			}
	);
}

function getResponse_guesttype(typeid,value) {
	HideRoomsList();
	blockInterface('guesttype',200);
	jQuery.get(ajaxurl+'&task=handlereq',{ field: 'guesttype', 'typeid': typeid ,'value': value },
		function(data){
			showRoomsList(data); 
			show_log('guesttype');
			}
		);
	}

function getResponse_rooms(field,value) {
	HideRoomsList();
	blockInterface(field,200);
	jQuery.get(ajaxurl+'&task=handlereq',{ field: field,'value': value },
		function(data){
			showRoomsList(data); 
			show_log(field);
			}
	);
}

function getResponse_multiroom_select(field,value) {
	HideRoomsList();
	blockInterface(field,200);
	jQuery.get(ajaxurl+'&task=handlereq',{ field: field,'value': value },
		function(data){
			showRoomsList(data); 
			show_log(field);
			}
	);
}

function getResponse_extras(field,value,theId) {
	blockInterface(field,200);
	jQuery.get(ajaxurl+'&task=handlereq',{ field: field,'value': value },
		function(data){
			eval(data); 
			show_log(field);
			// Thanks Dimitris
			var extra = document.getElementsByName('extras['+theId+']');
			var combo = document.getElementsByName('quantity'+theId);
			if (combo[0])
				{
				if (extra[0].checked == true)
					{
					combo[0].disabled=false;
					combo[0].selectedIndex=0;
					}
				else
					{
					combo[0].disabled=true;
					combo[0].selectedIndex=0;
					}
				}
			}
	);
}

function getResponse_extrasquantity(field,value,theId) {
	blockInterface(field,200);
	jQuery.get(ajaxurl+'&task=handlereq',{ field: field,'value': value,'theId': theId },
		function(data){
			eval(data); 
			show_log(field);
			}
	);
}


function getResponse(field,value) {
	jQuery.get(ajaxurl+'&task=handlereq',{ field: field,'value': value },
		function(data){
			eval(data); 
			show_log(field);
			}
	);
}

function getResponse_existing(field,value) {
	blockInterface(field,200);
	jQuery.get(ajaxurl+'&task=handlereq',{ field: field,'value': value },
		function(data){
			eval(data); 
			jQuery('div.block_ui_bookingform').unblock();
			//show_log(field);
			}
	);
}

function getResponse_guest() {
	var firstname 		=jQuery('#firstname').val();
	var surname 		=jQuery('#surname').val();
	var house 			=jQuery('#house').val();
	var street 			=jQuery('#street').val();
	var town 			=jQuery('#town').val();
	var region 			=jQuery('#region').val();
	var postcode 		=jQuery('#postcode').val();
	var exists = document.ajaxform.country;
	if (exists != null)
		var country 		= document.ajaxform.country[document.ajaxform.country.selectedIndex].value;
	var tel_landline 	=jQuery('#tel_landline').val();
	var tel_mobile 		=jQuery('#tel_mobile').val();
	var eemail 			=jQuery('#eemail').val();

	url = ajaxurl+'&task=handlereq';
	result =checkaddressfields();

	if (result){
		var addressString= firstname+"~"+surname+"~"+house+"~"+street+"~"+town+"~"+region+"~"+postcode+"~"+country+"~"+tel_landline+"~"+tel_mobile+"~"+eemail;
		blockInterface("guestdetails",200);
		jQuery.get(url,{ field: 'addressstring','value': addressString },
			function(data){
				eval(data);
				show_log("addressstring");
				});
				
		}
	}

function show_log(lastfield) {
	//jQuery.get(ajaxurl+'&task=handlereq',{ field: 'show_log','lastfield': lastfield },
	//	function(data){
	//		eval(data);
	//		jQuery('div.block_ui_bookingform').unblock();
	//		}
	//);
	jQuery('div.block_ui_bookingform').unblock();
}

function blockInterface(field,fadetime){
	//jQuery.extend(jQuery.blockUI.defaults.overlayCSS, { backgroundColor: '#fff', opacity: '0.5'  });
	
	jQuery.blockUI.defaults.overlayCSS.backgroundColor = '#000';
	jQuery.blockUI.defaults.overlayCSS.opacity = '0.5';
	
	jQuery.blockUI.defaults.pageMessage = "Please be patient...";
	jQuery.blockUI.defaults.fadeTime = fadetime;
	jQuery.unblockUI({ fadeOut:true });
	
	if (field == "guesttype")
		message = blockui_recheckingroomavailability;
	if (field == "arrivalDate")
		message = blockui_recheckingroomavailability;
	if (field == "arrival_period")
		message = blockui_recheckingroomavailability;
	if (field == "departureDate")
		message = blockui_recheckingroomavailability;
	if (field == "departure_period")
		message = blockui_recheckingroomavailability;
	if (field == "smoking")
		message = blockui_recheckingroomavailability;

	if (show_extras == true){
		if (field == "extras" )
			message = blockui_changingextra;
		if (field == "extrasquantity")
			message = blockui_changingextra;
		}
	if (field == "requestedRoom")
		message = blockui_changingroomselection;
	if (field == "multiroom_select")
		message = blockui_changingroomselection;
	if (field == "guestdetails")
		message = blockui_updatingaddress;
	if (field == "firstname")
		message = blockui_recheckingroomavailability;
	if (field == "surname")
		message = blockui_recheckingroomavailability;
	if (field == "house")
		message = blockui_recheckingroomavailability;
	if (field == "street")
		message = blockui_recheckingroomavailability;
	if (field == "town")
		message = blockui_recheckingroomavailability;
	if (field == "region")
		message = blockui_recheckingroomavailability;
	if (field == "postcode")
		message = blockui_recheckingroomavailability;
	if (field == "country")
		message = blockui_recheckingroomavailability;
	if (field == "tel_landline")
		message = blockui_recheckingroomavailability;
	if (field == "tel_mobile")
		message = blockui_recheckingroomavailability;
	if (field == "email")
		message = blockui_recheckingroomavailability;
		
	if (field == "addresserror")
		message = blockui_addressinputerror;
	if (field == "existingCustomers")
		message = blockui_updatingaddress;

	if (field == "")
		message = blockui_recheckingroomavailability;
	//jQuery('div.block_ui_bookingform').block('<img src="'+rel_path+'/jomres/images/31.gif" /> <h3>'+message+'</h3>',{ border:'1px solid #016191'}); 

	jQuery('div.block_ui_bookingform').block({
	message: '<img src="'+rel_path+'/jomres/images/31.gif" /> <h3>'+message+'</h3>', 
	css:	{
			padding: '15px', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px'
			}
		});
	}

	
function showRoomsList(req){
	//var rooms = req.split("~");
	//buildSelected(rooms[0]) ; 
	//buildAvailable(rooms[1]);
	eval(req);
	if (rooms_list_enabled)
		ShowRoomsList();
	return false;
	}

function HideRoomsList(){
	jQuery("div.roomsListWrapper").fadeOut("slow",1000); 
	//jQuery("div.roomsListWrapper").hide("slow"); 
	//jQuery("div.roomsListWrapper").find("div.roomsListInnerWrapper:visible").slideUp("slow"); 
	return false;
	}

function ShowRoomsList(){
	jQuery("div.roomsListWrapper").fadeIn("slow",1000); 
	//jQuery("div.roomsListWrapper").show("slow"); 
	//jQuery("div.roomsListWrapper").find("div.roomsListInnerWrapper").slideDown("slow");
	return false;
	}
	
function buildSelected(string){
	if (string != undefined){
		if ( string.length > 0 )
			populateDiv("selectedRooms",string);
			//document.getElementById("selectedRooms").innerHTML = string;
		}
	}

function buildAvailable(string)
	{	
	if (string != undefined){
		if ( string.length > 0 )
			populateDiv("availRooms",string);
			//document.getElementById("availRooms").innerHTML = string;
		}
	}
	
function checkSelectRoomMessage(){
	var exists = document.getElementById("roomalert_top");
	if (exists != null){
		if (document.getElementById("messages").innerHTML == selectroommessage ){
			if (show_extras == true)
				jQuery("#extrascontainer").fadeTo("slow", 0.2);
			jQuery("#bookingform_address").fadeTo("slow", 0.2);
			jQuery("#bookingform_footer").fadeTo("slow", 0.2);
			document.getElementById("roomalert_top").className="roomalert_on"
			document.getElementById("roomalert_bottom").className="roomalert_on"
			//showdiv("roomalert_top");
			//showdiv("roomalert_bottom");
			//jQuery("#roomalert_top").Highlight(500, '#fc0000');               // Causes error with jquery 1.2 as interface library does not appear compatible with this version of jquery
			//jQuery("#roomalert_bottom").Highlight(500, '#fc0000');               // Causes error with jquery 1.2 as interface library does not appear compatible with this version of jquery
			}
		else{
			if (show_extras == true)
				document.getElementById("extrascontainer").className="roomalert_off";
			document.getElementById("roomalert_top").className="roomalert_off";
			document.getElementById("roomalert_bottom").className="roomalert_off";
			//hidediv("roomalert_top");
			//hidediv("roomalert_bottom");
			if (show_extras == true)
				jQuery("#extrascontainer").fadeTo("slow", 1);
			jQuery("#bookingform_address").fadeTo("slow", 1);
			jQuery("#bookingform_footer").fadeTo("slow", 1);
			}
		}
	}

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);


function SRPcheckShowGuestDeetsNow() {
	if (isSRP){
		if (show_extras == true)
			showdiv("extrascontainer");
		showdiv("guestdeets");
		}
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	 Departure date adjustment stuff
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ajaxADate(arrivalDate,dformat){
	var currentDepartureDateText = jQuery(document.ajaxform.departureDate).val();
	var currentDepartureDatesplit_dates = jomres_split_date(currentDepartureDateText,dformat)
	currentDepartureDateday = currentDepartureDatesplit_dates[0];
	currentDepartureDatemon = currentDepartureDatesplit_dates[1];
	currentDepartureDateyear = currentDepartureDatesplit_dates[2];
	var currentDepartureDated = new Date(currentDepartureDateyear,currentDepartureDatemon-1,currentDepartureDateday); 
	
	var day=0
	var mon=0
	var year=0
	var split_dates = jomres_split_date(arrivalDate,dformat)
	day = split_dates[0];
	mon = split_dates[1];
	year = split_dates[2];
	
	var d = new Date(year,mon-1,day); with (d) setDate(getDate()+mininterval);

	sday=String(d.getDate());
	smonth=String(d.getMonth()+1);
	if (sday.length == 1)
		fday="0"+sday;
	else
		fday=sday;
	if (smonth.length == 1)
		fmonth="0"+smonth;
	else
		fmonth=smonth;

	if (dformat=="%d/%m/%Y"){
		dd=fday+"/"+fmonth+"/"+String(d.getFullYear())
		}
	if (dformat=="%Y/%m/%d"){
		dd= String(d.getFullYear())+"/"+fmonth+"/"+fday
		}
	if (dformat=="%m/%d/%Y"){
		dd=fmonth+"/"+ fday+"/"+String(d.getFullYear())
		}
	if (dformat=="%d-%m-%Y"){
		dd=fday+"-"+fmonth+"-"+String(d.getFullYear())
		}
	if (dformat=="%Y-%m-%d"){
		dd= String(d.getFullYear())+"-"+fmonth+"-"+fday
		}
	if (dformat=="%m-%d-%Y"){
		dd=fmonth+"-"+ fday+"-"+String(d.getFullYear())
		}


	var one_day=1000*60*60*24;
	var difference = Math.ceil((d.getTime()-currentDepartureDated.getTime())/(one_day))+mininterval;
	if (difference > mininterval)
		document.ajaxform.departureDate.value=dd;
	}	

function jomres_split_date(date,dformat)
	{
	if (dformat=="%d/%m/%Y"){
		dateArray=date.split("/")
			day=dateArray[0]
			mon=dateArray[1]
			year=dateArray[2]
			}
	if (dformat=="%Y/%m/%d"){
		dateArray=date.split("/")
		day=dateArray[2]
		mon=dateArray[1]
		year=dateArray[0]
		}
	if (dformat=="%m/%d/%Y"){
		dateArray=date.split("/")
		day=dateArray[1]
		mon=dateArray[0]
		year=dateArray[2]
		}
	if (dformat=="%d-%m-%Y"){
		dateArray=date.split("-")
		day=dateArray[0]
		mon=dateArray[1]
		year=dateArray[2]
		}
	if (dformat=="%Y-%m-%d"){
		dateArray=date.split("-")
		day=dateArray[2]
		mon=dateArray[1]
		year=dateArray[0]
		}
	if (dformat=="%m-%d-%Y"){
		dateArray=date.split("-")
		day=dateArray[1]
		mon=dateArray[0]
		year=dateArray[2]
		}
	if (dformat=="%d.%m.%Y"){
		dateArray=date.split(".")
		day=dateArray[0]
		mon=dateArray[1]
		year=dateArray[2]
		}
	return  [ day, mon , year ];
	}
///////////////////////////////////////
//
//	Validate the form input
//
///////////////////////////////////////

function checkaddressfields(){
	var firstname 		=jQuery.trim(jQuery('#firstname').val());
	var surname 		=jQuery.trim(jQuery('#surname').val());
	var house 			=jQuery.trim(jQuery('#house').val());
	var street 			=jQuery.trim(jQuery('#street').val());
	var town 			=jQuery.trim(jQuery('#town').val());
	var region 			=jQuery.trim(jQuery('#region').val());
	var postcode 		=jQuery.trim(jQuery('#postcode').val());
	var exists = document.ajaxform.country;
	if (exists != null)
		var country 	= document.ajaxform.country[document.ajaxform.country.selectedIndex].value;
	var tel_landline 	=jQuery.trim(jQuery('#tel_landline').val());
	var tel_mobile 		=jQuery.trim(jQuery('#tel_mobile').val());
	var eemail 			=jQuery.trim(jQuery('#eemail').val());

	setInputFillToOkColour('#firstname');
	setInputFillToOkColour('#surname');
	setInputFillToOkColour('#house');
	setInputFillToOkColour('#street');
	setInputFillToOkColour('#town');
	setInputFillToOkColour('#region');
	setInputFillToOkColour('#postcode');
	setInputFillToOkColour('#tel_landline');
	setInputFillToOkColour('#tel_mobile');
	setInputFillToOkColour('#eemail');
	
	var pass			= true;
	
	if (validation_firstname && firstname.length == 0 ){
		setInputFillToErrorColour("#firstname");
		pass = false;
		}
	if (validation_surname && surname.length == 0 ){
		setInputFillToErrorColour("#surname");
		pass = false;
		}
	if (validation_houseno && house.length == 0 ){
		setInputFillToErrorColour("#house");
		pass = false;
		}
	if (validation_street && street.length == 0 ){
		setInputFillToErrorColour("#street");
		pass = false;
		}
	if (validation_town && town.length == 0 ){
		setInputFillToErrorColour("#town");
		pass = false;
		}
	if (validation_region && region.length == 0 ){
		setInputFillToErrorColour("#region");
		pass = false;
		}
	if (validation_postcode && postcode.length == 0 ){
		setInputFillToErrorColour("#postcode");
		pass = false;
		}
	if (validation_country && country.length == 0 ){
		setInputFillToErrorColour("#country");
		pass = false;
		}
	if (validation_landline && tel_landline.length == 0 ){
		setInputFillToErrorColour("#tel_landline");
		pass = false;
		}
	if (validation_cellmobile && tel_mobile.length == 0 ){
		setInputFillToErrorColour("#tel_mobile");
		pass = false;
		}
	if (validation_email && eemail.length == 0 ){
		setInputFillToErrorColour("#eemail");
		pass = false;
		}

	if (validation_email && !echeck(eemail)){
		setInputFillToErrorColour("#eemail");
		pass = false;
		}
	
	if (pass)
		pass = checkCustomFields();
	
	if (!pass){
		jQuery('div.recheckaddress').show(); 
		blockInterface("addresserror",2500);
		jQuery('div.block_ui_bookingform').unblock();
		//disableSubmitButton(document.ajaxform.confirmbooking);
		return false;
		}
	else{
		enableSubmitButton(document.ajaxform.confirmbooking);
		return true;
		}
	}
	
function validate(){
	if (checkaddressfields()){
		getResponse_guest();
		setTimeout('submitBooking()', 1000);
		}
	}

function submitBooking(){
	document.ajaxform.action = livesite+"&task=confirmbooking"
	document.ajaxform.submit();
	}
	
function setInputFillToOkColour(field){
	jQuery(field).removeClass("errorbackground");
	}
	
function setInputFillToErrorColour(field){
	jQuery(field).addClass("errorbackground");
	}
	
function submitenter(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (!document.ajaxform.confirmbooking.disabled){
		if (keycode == 13) {
			 document.ajaxform.submit();
			 return false;
			 }
		else
			return true;
		}
	else
		return true;
	}	

/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function echeck(str) {
	var strlen = str.length
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (strlen==0){
		return false
		}	
	if (str.indexOf(at)==-1){
		//alert("Invalid E-mail ID")
		return false
		}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			//alert("Invalid E-mail ID");
		return false;
		}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.indexOf(at,(lat+1))!=-1){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.indexOf(dot,(lat+2))==-1){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.indexOf(" ")!=-1){
			//alert("Invalid E-mail ID")
			return false
		}
	return true
	}
	
function showdiv(event,caracteristicas,div)
{  
   var carac = new Array();
   var total ="";  
	//determina un margen de pixels del div al raton
	margin=5;

	//La variable IE determina si estamos utilizando IE
	var IE = document.all?true:false;
	//Si no utilizamos IE capturamos el evento del mouse
	if (!IE) document.captureEvents(Event.MOUSEMOVE)

	var tempX = 0;
	var tempY = 0;

	if(IE)
	{ //para IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}else{ //para netscape
		tempX = event.pageX;
		tempY = event.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}

	//modificamos el valor del id posicion para indicar la posicion del mouse
	//document.getElementById('posicion').innerHTML="PosX = "+tempX+" | PosY = "+tempY;
  // alert("posY" + tempY);
//   alert("posX" + tempX);
	//document.getElementById('toolTipBox').style.top = (tempY + margin) +"px";
	//document.getElementById('toolTipBox').style.left = (tempX + margin) + "px";
   carac = caracteristicas.split(';'); 
   for (var i=0;i<carac.length-1;i++){
	total = total + '-' + carac[i] + '<br>';
   }
    if (carac[0].length!=0)
	{	document.getElementById(div).innerHTML = total;	
    	document.getElementById(div).style.display = 'block';
	}
}

	
 function visualizarDiv(imagen)
 {document.getElementById('div_imagen').src = imagen;	
  document.getElementById('reserva').style.display = 'block';
  document.getElementById('f_reserva').style.display = 'block';
}

function hidediv(div)
{ 
 if (div.indexOf('toolTipBox')!=-1)
 { 
  document.getElementById(div).style.display='none';
 }
}

/********************************************************************************************************************
* PopBox.js, v2.7a Copyright (c) 2009, C6 Software, Inc. (http://www.c6software.com/)
* PopBox is released under the Creative Commons GNU GPL license (http://creativecommons.org/licenses/GPL/2.0/)
* and is free to use in both commercial and non-commercial work, provided this header remains at the top.
* The latest version and documentation can be found at http://www.c6software.com/products/popbox/default.aspx.
* Questions and suggestions can be sent to john.reid@c6software.com. Please put "PopBox" somewhere in the
* email subject so I can easily filter. Send me your URL and I may post it!
* PopBox relies on many methods from Danny Goodman's (www.dannyg.com) javascript library DHTMLAPI.js
* and his books, without which scores of web developers would be totally lost. Thanks Danny.
********************************************************************************************************************/

// Seek nested NN4 layer from string name
function SeekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = SeekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference into a valid element object reference
function GetRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
		var isCSS = (document.body && document.body.style) ? true : false;
        if (isCSS && document.getElementById) {
            theObj = document.getElementById(obj);
        } else if (isCSS && document.all) {
            theObj = document.all(obj);
        } else if (document.layers) {
            theObj = SeekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Return the available content width and height space in browser window
function GetInsideWindowSize() {
	 if (window.innerWidth) {
		  return {x:window.innerWidth, y:window.innerHeight};
    }
    else
    {
		 var baseArray = document.getElementsByTagName("base");
		 if (baseArray.length == 0)
		 {
			 if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
				  return {x:document.body.parentNode.clientWidth, y:document.body.parentNode.clientHeight};
			 } else if (document.body && document.body.clientWidth) {
				  return {x:document.body.clientWidth, y:document.body.clientHeight};
			 }
		 }
		 else
		 {
			 if (document.body && document.body.clientWidth) {
				  return {x:document.body.clientWidth, y:document.body.clientHeight};
			 } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
				  return {x:document.body.parentNode.clientWidth, y:document.body.parentNode.clientHeight};
			 }
		 }
    }
    return {x:0, y:0};
}

// Retrieve the padding around an object
function GetObjectPadding(obj) {
	var elem = GetRawObject(obj);

	var l = 0;
	var r = 0;
	var t = 0;
	var b = 0;
	if (elem.currentStyle)
	{
		if (elem.currentStyle.paddingLeft)
			l = parseInt(elem.currentStyle.paddingLeft, 10);
		if (elem.currentStyle.paddingRight)
			r = parseInt(elem.currentStyle.paddingRight, 10);
		if (elem.currentStyle.paddingTop)
			t = parseInt(elem.currentStyle.paddingTop, 10);
		if (elem.currentStyle.paddingBottom)
			b = parseInt(elem.currentStyle.paddingBottom, 10);
	}
	else if (window.getComputedStyle)
	{
		l = parseInt(window.getComputedStyle(elem,null).paddingLeft, 10);
		r = parseInt(window.getComputedStyle(elem,null).paddingRight, 10);
		t = parseInt(window.getComputedStyle(elem,null).paddingTop, 10);
		b = parseInt(window.getComputedStyle(elem,null).paddingBottom, 10);
	}
	if (isNaN(l) == true) l = 0;
	if (isNaN(r) == true) r = 0;
	if (isNaN(t) == true) t = 0;
	if (isNaN(b) == true) b = 0;

	return {l:(l),r:(r),t:(t),b:(b)};
}

// Retrieve the rendered size of an element
function GetObjectSize(obj)  {
    var elem = GetRawObject(obj);
    var w = 0;
    var h = 0;
    if (elem.offsetWidth) {
			w = elem.offsetWidth; h = elem.offsetHeight;
    } else if (elem.clip && elem.clip.width) {
			w = elem.clip.width; h = elem.clip.height;
    } else if (elem.style && elem.style.pixelWidth) {
			w = elem.style.pixelWidth; h = elem.style.pixelHeight;
    }
    
    w = parseInt(w, 10);
    h = parseInt(h, 10);
    
   // remove any original element padding
   var padding = GetObjectPadding(elem);
   w -= (padding.l + padding.r);
   h -= (padding.t + padding.b);

   return {w:(w), h:(h)};
}

// Return the element position in the page, not it's parent container
function GetElementPosition(obj)
{
	var elem = GetRawObject(obj);
	var left = 0;
	var top = 0;

	// add any original element padding
	var elemPadding = GetObjectPadding(elem);
	left = elemPadding.l;
	top = elemPadding.t;

	if (elem.offsetParent)
	{
		left += elem.offsetLeft;
		top += elem.offsetTop;
		var parent = elem.offsetParent;
		while (parent)
		{
			left += parent.offsetLeft;
			top += parent.offsetTop;

			if (parent.style && parent.style.overflow && parent.style.overflow != "")
			{
				left -= parent.scrollLeft;
				top -= parent.scrollTop;
			}

			var parentTagName = parent.tagName.toLowerCase();
			if (parentTagName != "table" &&
				parentTagName != "body" && 
				parentTagName != "html" && 
				parentTagName != "div" && 
				parent.clientTop && 
				parent.clientLeft)
			{
				left += parent.clientLeft;
				top += parent.clientTop;
			}

			parent = parent.offsetParent;
		}
	}
	else if (elem.left && elem.top)
	{
		left = elem.left;
		top = elem.top;
	}
	else
	{
		if (elem.x)
			left = elem.x;
		if (elem.y)
			top = elem.y;
	}
	return {x:left, y:top};
}

// return the number of pixels the scrollbar has moved the visible window
function GetScrollOffset()
{
    if (window.pageYOffset) {
        return {x:window.pageXOffset, y:window.pageYOffset};
    } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
        return {x:document.documentElement.scrollLeft, y:document.documentElement.scrollTop};
    } else if (document.body && document.body.clientWidth) {
        return {x:document.body.scrollLeft, y:document.body.scrollTop};
    }
    return {x:0, y:0};
}

function CreateRandomId()
{
	var randomNum = 0.0;
	while (randomNum == 0.0)
		randomNum = Math.random();
	var random = randomNum + "";
	return "id" + random.substr(2);
}

function MouseMoveRevert(e)
{
	if (pbMouseMoveRevert != null && pbMouseMoveRevert.length != 0)
	{
		var evt = (e) ? e : window.event;
		var mouse = {x:0, y:0};
		if (evt.pageX || evt.pageY)
		{
			mouse.x = evt.pageX;
			mouse.y = evt.pageY;
		}
		else if (evt.clientX || evt.clientY)
		{
			var scroll = GetScrollOffset();
			mouse.x = evt.clientX + scroll.x;
			mouse.y = evt.clientY + scroll.y;
		}
		
		for (var x = 0; x < pbMouseMoveRevert.length;)
		{
			if (pbMouseMoveRevert[x] != null)
			{
				var id = pbMouseMoveRevert[x].id;
				if (typeof popBox[id] != "undefined" && popBox[id] != null && popBox[id].hTarg != 0)
				{
					// if the mouse is outside the box then call revert
					if (mouse.x < popBox[id].xTarg || mouse.x > (popBox[id].xTarg + popBox[id].wTarg) || mouse.y < popBox[id].yTarg || mouse.y > (popBox[id].yTarg + popBox[id].hTarg))
					{
						var className = pbMouseMoveRevert[x].className;
						pbMouseMoveRevert.splice(x, 1);
						Revert(id, null, className);
						continue;
					}
				}				
			}
			
			x++;
		}
	}
}

// holds numerous properties related to position, size and motion
var popBox = new Array();
var popBoxIds = new Array();
// holds positioning value for the z axis
var popBoxZ = 100;
// holds the popped image for each <img> tag with a pbsrc attribute
var pbSrc = new Array();
// holds the popbar function for each <img> tag with a pbShowPopBar attribute
var pbPopBarFunc = new Array();
// holds the array of image ids for onmousemove Revert calls
var pbMouseMoveRevert = null;

// add initialization to window.onload
if (typeof window.onload == 'function')
{
	var func = window.onload;
	window.onload = function(){func();InitPbSrc();InitPbPopBar();};
}
else
{
	window.onload = function(){InitPbSrc();InitPbPopBar();};
}

// loads all the popped src images
function InitPbSrc()
{
	var images = null;
	if (document.body)
	{
		if (document.body.getElementsByTagName)
			images = document.body.getElementsByTagName("img");
		else if (document.body.all)
			images = document.body.all.tags("img");
	}

	if (images != null)
	{
		for (var x = 0; x < images.length; x++)
		{
			var poppedSrc = images[x].getAttribute('pbSrc');
			if (poppedSrc != null)
			{
				if (images[x].id == "")
					images[x].id = CreateRandomId();
					
				if (pbSrc[images[x].id] == null)
				{
					pbSrc[images[x].id] = new Image();
					pbSrc[images[x].id].src = poppedSrc;
				}
			}
		}
	}
}

// adds PopBar to images
function InitPbPopBar()
{
	var images = null;
	if (document.body)
	{
		if (document.body.getElementsByTagName)
			images = document.body.getElementsByTagName("img");
		else if (document.body.all)
			images = document.body.all.tags("img");
	}

	if (images != null)
	{
		var imgArray = new Array();
		for (var x = 0; x < images.length; x++)
		{
			if (images[x].id == "")
				images[x].id = CreateRandomId();
			
			imgArray[x] = images[x];
		}

		for (var x = 0; x < imgArray.length; x++)
			CreatePopBar(imgArray[x]);
	}
}

// initialize default popbox object
function InitPopBox(obj)
{
	obj = GetRawObject(obj);
	if (typeof popBox[obj.id] != "undefined" && popBox[obj.id] != null)
		return obj;
		
	var parent = document.body;
	if (obj.id == "")
		obj.id = CreateRandomId();

	var elem = obj;
	var startPos = GetElementPosition(elem);
	var initSize = GetObjectSize(elem);

	if (elem.style.position == "absolute" || elem.style.position == "relative")
	{
		parent = elem.parentNode;
		startPos.x = parseInt(elem.style.left, 10);
		startPos.y = parseInt(elem.style.top, 10);
	}

	// if there is a pbsrc then create that, else if it's not absolute or relative then create a copy
	if (pbSrc[elem.id] != null || (elem.style.position != "absolute" && elem.style.position != "relative"))
	{
		var strSrc = (pbSrc[elem.id] != null) ? pbSrc[elem.id].src : elem.src;
		var img = null;
		try{img = document.createElement("<img src='" + strSrc + "' />");}
		catch(ex){img = document.createElement("img"); img.src = strSrc;}
		// copy image properties
		img.border = elem.border;
		img.className = elem.className;
		img.height = elem.height;
		img.id = "popcopy" + elem.id;
		img.alt = elem.alt;
		img.title = elem.title;
		img.width = elem.width;
		img.onclick = elem.onclick;
		img.ondblclick = elem.ondblclick;
		img.onmouseout = elem.onmouseout;

		// remove event so the object doesn't jump
		elem.onmouseout = null;

		img.style.width = initSize.w;
		img.style.height = initSize.h;
		img.style.position = "absolute";
		img.style.left = startPos.x + "px";
		img.style.top = startPos.y + "px";
		img.style.cursor = elem.style.cursor;
		
		parent.appendChild(img);
		elem.style.visibility = "hidden";
		elem = img;
	}

	popBoxIds.push(elem.id);	
	popBox[elem.id] = {	elemId:elem.id,
							xCurr:0.0,
							yCurr:0.0,
							xTarg:0.0,
							yTarg:0.0,
							wCurr:0.0,
							hCurr:0.0,
							wTarg:0.0,
							hTarg:0.0,
							xStep:0.0,
							yStep:0.0,
							wStep:0.0,
							hStep:0.0,
							xDelta:0.0,
							yDelta:0.0,
							wDelta:0.0,
							hDelta:0.0,
							xTravel:0.0,
							yTravel:0.0,
							wTravel:0.0,
							hTravel:0.0,
							velM:1.0,
							velS:1.0,
							interval:null,
							isAnimating:false,
							xOriginal:startPos.x,
							yOriginal:startPos.y,
							wOriginal:parseFloat(initSize.w),
							hOriginal:parseFloat(initSize.h),
							isPopped:false,
							fnClick:null,
							fnDone:null,
							fnPre:null,
							originalId:null,
							cursor:""
							};
							
	if (typeof obj.onclick == "function")
	{
		popBox[elem.id].fnClick = elem.onclick;
		
		if (popBoxAutoClose == true && (typeof obj.ondblclick != "function" || obj.ondblclick == null) && typeof obj.onmouseover != "function")
			elem.ondblclick = function(){Revert(elem.id, null, elem.className);};
	}

	if (popBoxAutoClose == true && typeof obj.onmouseover == "function" && (typeof obj.onmouseout != "function" || obj.onmouseout == null))
	{
		if (popBoxMouseMoveRevert == true)
		{
			if (pbMouseMoveRevert == null)
			{
				pbMouseMoveRevert = new Array();
				if (typeof document.onmousemove == 'function')
				{
					var func = document.onmousemove;
					document.onmousemove = function(e){func(e);MouseMoveRevert(e);};
				}
				else
				{
					document.onmousemove = MouseMoveRevert;
				}
			}
			
			pbMouseMoveRevert.push({id:elem.id, className:elem.className});
		}
		else
		{
			elem.onmouseout = function(){Revert(elem.id, null, elem.className);};
		}
	}

	if (obj.id != elem.id)
		popBox[elem.id].originalId = obj.id;
		
	return elem;
}

// calculate next steps and assign to style properties
function DoPopBox(elem)
{
	if (typeof elem == "string") elem = GetRawObject(elem);
	try
	{
		var bMDone = false;
		var bSDone = false;
		if ((popBox[elem.id].xTravel + Math.abs(popBox[elem.id].xStep)) < popBox[elem.id].xDelta)
		{
			var x = popBox[elem.id].xCurr + popBox[elem.id].xStep;
			elem.style.left = parseInt(x, 10) + "px";
			popBox[elem.id].xTravel += Math.abs(popBox[elem.id].xStep);
			popBox[elem.id].xCurr = x;
		} else {
			popBox[elem.id].xTravel += Math.abs(popBox[elem.id].xStep);
			elem.style.left = parseInt(popBox[elem.id].xTarg, 10) + "px";
			bMDone = true;
		}
		if ((popBox[elem.id].yTravel + Math.abs(popBox[elem.id].yStep)) < popBox[elem.id].yDelta)
		{
			var y = popBox[elem.id].yCurr + popBox[elem.id].yStep;
			elem.style.top = parseInt(y, 10) + "px";
			popBox[elem.id].yTravel += Math.abs(popBox[elem.id].yStep);
			popBox[elem.id].yCurr = y;
			bMDone = false;
		} else {
			popBox[elem.id].yTravel += Math.abs(popBox[elem.id].yStep);
			elem.style.top = parseInt(popBox[elem.id].yTarg, 10) + "px";
		}
		if ((popBox[elem.id].wTravel + Math.abs(popBox[elem.id].wStep)) < popBox[elem.id].wDelta)
		{
			var w = popBox[elem.id].wCurr + popBox[elem.id].wStep;
			elem.style.width = parseInt(w, 10) + "px";
			popBox[elem.id].wTravel += Math.abs(popBox[elem.id].wStep);
			popBox[elem.id].wCurr = w;
		} else {
			popBox[elem.id].wTravel += Math.abs(popBox[elem.id].wStep);
			elem.style.width = parseInt(popBox[elem.id].wTarg, 10) + "px";
			bSDone = true;
		}
		if ((popBox[elem.id].hTravel + Math.abs(popBox[elem.id].hStep)) < popBox[elem.id].hDelta)
		{
			var h = popBox[elem.id].hCurr + popBox[elem.id].hStep;
			elem.style.height = parseInt(h, 10) + "px";
			popBox[elem.id].hTravel += Math.abs(popBox[elem.id].hStep);
			popBox[elem.id].hCurr = h;
			bSDone = false;
		} else {
			popBox[elem.id].hTravel += Math.abs(popBox[elem.id].hStep);
			elem.style.height = parseInt(popBox[elem.id].hTarg, 10) + "px";
		}

		var obj = elem;
		
		if (bMDone == true && bSDone == true)
		{
			clearInterval(popBox[elem.id].interval);
			
			elem.style.cursor = popBox[elem.id].cursor;

			var func = null;
			if (popBox[elem.id].fnDone != null && typeof popBox[elem.id].fnDone == "function")
				func = popBox[elem.id].fnDone;
			
			if (popBox[elem.id].isPopped == true)
			{
				elem.style.zIndex = "";
	
				if (popBox[elem.id].originalId != null)
				{
					obj = GetRawObject(popBox[elem.id].originalId);
					obj.onmouseout = elem.onmouseout; // copy method back to original
					obj.style.visibility = "visible";
					
					// remove the copied object from the body and the array
					elem.parentNode.removeChild(elem);
				}
				else
				{
					elem.style.width = parseInt(popBox[elem.id].wOriginal, 10) + "px";
					elem.style.height = parseInt(popBox[elem.id].hOriginal, 10) + "px";
				
					if (typeof popBox[elem.id].fnClick == "function")
						elem.onclick = popBox[elem.id].fnClick;
				}

				delete popBox[elem.id];
				popBox[elem.id] = null;
				CreatePopBar(obj);
			}
			else
			{
				popBox[elem.id].isPopped = true;
				popBox[elem.id].isAnimating = false;
				CreateRevertBar(elem);
			}
				
			if (func != null && typeof func == "function")
				func(obj);
		}
	}
	catch(ex){}
}

function HasRevertBar(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	
	var elem = obj;
	if (popBox[elem.id] != null && popBox[elem.id].originalId != null)
		elem = GetRawObject(popBox[elem.id].originalId);

	var pbShowBar = elem.getAttribute('pbShowRevertBar');
	var pbShowText = elem.getAttribute('pbShowRevertText');
	var pbShowImage = elem.getAttribute('pbShowRevertImage');
	pbShowBar = (pbShowBar != null) ? (pbShowBar == "true" || pbShowBar == true) : popBoxShowRevertBar;
	pbShowText = (pbShowText != null) ? (pbShowText == "true" || pbShowText == true) : popBoxShowRevertText;
	pbShowImage = (pbShowImage != null) ? (pbShowImage == "true" || pbShowImage == true) : popBoxShowRevertImage;
	
	return (pbShowBar || pbShowText || pbShowImage);
}

function HasCaption(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	var elem = obj;
	if (popBox[elem.id] != null && popBox[elem.id].originalId != null)
		elem = GetRawObject(popBox[elem.id].originalId);

	var pbShowCaption = elem.getAttribute('pbShowCaption');
	pbShowCaption = (pbShowCaption != null) ? (pbShowCaption == "true" || pbShowCaption == true) : popBoxShowCaption;
	var pbCaption = null;
	if (pbShowCaption == true)
	{
		pbCaption = elem.getAttribute('pbCaption');
		if (pbCaption == null && elem.title != "") pbCaption = elem.title;
	}

	return (pbCaption != null && pbCaption != "");
}

function CreateRevertBar(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	
	var elem = obj;
	if (popBox[elem.id] != null && popBox[elem.id].originalId != null)
		elem = GetRawObject(popBox[elem.id].originalId);

	var pbShowBar = elem.getAttribute('pbShowRevertBar');
	var pbShowText = elem.getAttribute('pbShowRevertText');
	var pbShowImage = elem.getAttribute('pbShowRevertImage');
	var pbText = elem.getAttribute('pbRevertText');
	var pbImage = elem.getAttribute('pbRevertImage');
	pbShowBar = (pbShowBar != null) ? (pbShowBar == "true" || pbShowBar == true) : popBoxShowRevertBar;
	pbShowText = (pbShowText != null) ? (pbShowText == "true" || pbShowText == true) : popBoxShowRevertText;
	pbShowImage = (pbShowImage != null) ? (pbShowImage == "true" || pbShowImage == true) : popBoxShowRevertImage;
	if (pbText == null) pbText = popBoxRevertText;
	if (pbImage == null) pbImage = popBoxRevertImage;

	var pbShowCaption = elem.getAttribute('pbShowCaption');
	pbShowCaption = (pbShowCaption != null) ? (pbShowCaption == "true" || pbShowCaption == true) : popBoxShowCaption;
	var pbCaption = null;
	if (pbShowCaption == true)
	{
		pbCaption = elem.getAttribute('pbCaption');
		if (pbCaption == null && elem.title != "") pbCaption = elem.title;
	}

	CreatePbBar(obj, pbShowBar, pbShowText, pbShowImage, pbText, pbImage, popBoxRevertBarAbove, true, pbCaption)
}

function CreatePopBar(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	if (typeof pbPopBarFunc[obj.id] != 'undefined' && pbPopBarFunc[obj.id] != null) return;
	var pbShowBar = obj.getAttribute('pbShowPopBar');
	if (pbShowBar != null)
	{
		var pbShowText = obj.getAttribute('pbShowPopText');
		var pbShowImage = obj.getAttribute('pbShowPopImage');
		var pbText = obj.getAttribute('pbPopText');
		var pbImage = obj.getAttribute('pbPopImage');
		pbShowBar = (pbShowBar == "true" || pbShowBar == true);
		pbShowText = (pbShowText != null) ? (pbShowText == "true" || pbShowText == true) : popBoxShowPopText;
		pbShowImage = (pbShowImage != null) ? (pbShowImage == "true" || pbShowImage == true) : popBoxShowPopImage;
		if (pbText == null) pbText = popBoxPopText;
		if (pbImage == null) pbImage = popBoxPopImage;

		CreatePbBar(obj, pbShowBar, pbShowText, pbShowImage, pbText, pbImage, popBoxPopBarAbove, false, null)
	}
}

function CreatePbBar(obj, pbShowBar, pbShowText, pbShowImage, pbText, pbImage, pbBarAbove, isRevert, pbCaption)
{
	if (pbShowBar == false && pbShowText == false && pbShowImage == false && pbCaption == null) return;
	if (typeof obj == "string") obj = GetRawObject(obj);

	var objCursor = "hand";
	if (obj.currentStyle)
		objCursor = obj.currentStyle.cursor;
	else if (window.getComputedStyle)
		objCursor = window.getComputedStyle(obj,null).cursor;

	var fnClick = function(){if (typeof obj.onclick == 'function') obj.onclick();};
	var fnMouseOut = function(){if (typeof obj.onmouseout == 'function') obj.onmouseout();};
	var fnMouseOver = function(){if (typeof obj.onmouseover == 'function') obj.onmouseover();};
	var fnRemove = new Array();

	var isPositioned = (obj.style.position == "absolute" || obj.style.position == "relative");
	var left = 0;
	var top = 0;
	var parentNode = obj.parentNode;
	var objSpan = null;
	if (isPositioned == true)
	{
		left = parseInt(obj.style.left, 10);
		top = parseInt(obj.style.top, 10);
		var padding = GetObjectPadding(obj);
		left += padding.l;
		top += padding.t;	
	}
	else
	{
		objSpan = document.createElement("span");
		objSpan = (obj.nextSibling != null) ? parentNode.insertBefore(objSpan, obj.nextSibling) : parentNode.appendChild(objSpan);
		objSpan.style.position = "relative";
		objSpan.style.left = "0px";
		objSpan.style.top = "0px";
		var floatValue = "";
		if (obj.align == "left") floatValue = "left";
		else if (obj.align == "right") floatValue = "right";
		floatValue = (obj.style.styleFloat && obj.style.styleFloat != "") ? obj.style.styleFloat : (obj.style.cssFloat && obj.style.cssFloat != "") ? obj.style.cssFloat : floatValue;
		if (typeof obj.style.styleFloat != "undefined") objSpan.style.styleFloat = floatValue;
		else if (typeof obj.style.cssFloat != "undefined") objSpan.style.cssFloat = floatValue;
		
		var imgPos = GetElementPosition(obj);
		var spanPos = GetElementPosition(objSpan);
		objSpan.style.left = (imgPos.x - spanPos.x) + "px";
		objSpan.style.top = (floatValue != "") ? "1px" : (imgPos.y - spanPos.y) + "px";
		
		parentNode = objSpan;
	}

	var width = parseInt(obj.style.width, 10);
	var height = parseInt(obj.style.height, 10);
	var size = GetObjectSize(obj);
	if (isNaN(width) == true)
		width = size.w;
	else if (size.w > width)
		left += ((size.w - width) / 2);
	if (isNaN(height) == true)
		height = size.h;
	else if (size.h > height)
		top += ((size.h - height) / 2);

	if (pbBarAbove == true) top -= 20;
	var z = obj.style.zIndex + 1;

	if (pbShowBar == true)
	{
		var divTrans = document.createElement("div");
		divTrans.id = "popBoxDivTrans" + z;
		divTrans.style.width = width + "px";
		divTrans.style.height = "20px";
		divTrans.style.borderStyle = "none";
		divTrans.style.padding = "0px";
		divTrans.style.margin = "0px";
		divTrans.style.position = "absolute";
		divTrans.style.left = left + "px";
		divTrans.style.top = top + "px";
		divTrans.style.backgroundColor = "#000000";
		divTrans.style.cursor = objCursor;
		divTrans.style.zIndex = z;
		if (pbBarAbove == false)
		{
			if (typeof divTrans.style.filter != 'undefined')
				divTrans.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=20)";
			if (typeof divTrans.style.opacity != 'undefined')
				divTrans.style.opacity = "0.2";
		}
		divTrans.onclick = fnClick;
		if (isRevert == true)
			divTrans.onmouseout = fnMouseOut;
		else
			divTrans.onmouseover = fnMouseOver;
		parentNode.appendChild(divTrans);
		
		fnRemove.push(function(){divTrans.parentNode.removeChild(divTrans);});
	}

	if (pbShowText == true)
	{
		var divText = document.createElement("div");
		divText.id = "popBoxDivText" + z;
		divText.style.width = width + "px";
		divText.style.height = "20px";
		divText.style.borderStyle = "none";
		divText.style.padding = "0px";
		divText.style.margin = "0px";
		divText.style.position = "absolute";
		divText.style.left = left + "px";
		divText.style.top = top + "px";
		divText.style.cursor = objCursor;
		divText.style.textAlign = "center";
		divText.style.fontFamily = "Arial, Verdana, Sans-Serif";
		divText.style.fontSize = "10pt";
		divText.style.backgroundColor = "Transparent";
		divText.style.color = "#ffffff";
		divText.style.zIndex = z;
		divText.innerHTML = pbText;
		divText.onclick = fnClick;
		if (isRevert == true)
			divText.onmouseout = fnMouseOut;
		else
			divText.onmouseover = fnMouseOver;
		parentNode.appendChild(divText);

		fnRemove.push(function(){divText.parentNode.removeChild(divText);});
	}
	
	if (pbShowImage == true)
	{
		var imgPopped = null;
		try{imgPopped = document.createElement("<img src='" + pbImage + "' />");}
		catch(ex){imgPopped = document.createElement("img"); imgPopped.src = pbImage;}
		imgPopped.id = "popBoxImgPopped" + z;
		imgPopped.style.width = "20px";
		imgPopped.style.height = "20px";
		imgPopped.style.borderStyle = "none";
		imgPopped.style.padding = "0px";
		imgPopped.style.margin = "0px";
		imgPopped.style.position = "absolute";
		imgPopped.style.left = (left + width - 20) + "px";
		imgPopped.style.top = top + "px";
		imgPopped.style.cursor = objCursor;
		imgPopped.style.zIndex = z;
		imgPopped.onclick = fnClick;
		if (isRevert == true)
			imgPopped.onmouseout = fnMouseOut;
		else
			imgPopped.onmouseover = fnMouseOver;
		parentNode.appendChild(imgPopped);

		fnRemove.push(function(){imgPopped.parentNode.removeChild(imgPopped);});
	}
	
	if (pbCaption != null && pbCaption != "")
	{
		top += (height - 20);
		if (pbBarAbove == true) top += 20;
		if (popBoxCaptionBelow == true)  top += 20;

		var divCapTrans = document.createElement("div");
		divCapTrans.id = "popBoxDivCapTrans" + z;
		divCapTrans.style.width = width - 2 + "px";
		divCapTrans.style.height = "20px";
		divCapTrans.style.borderStyle = "solid";
		divCapTrans.style.borderWidth = "1px";
		divCapTrans.style.borderColor = "#999999";
		divCapTrans.style.padding = "0px";
		divCapTrans.style.margin = "0px";
		divCapTrans.style.position = "absolute";
		divCapTrans.style.left = left + "px";
		divCapTrans.style.top = top - 1 + "px";
		divCapTrans.style.backgroundColor = "#ffffdd";
		divCapTrans.style.zIndex = z;
		if (popBoxCaptionBelow == false)
		{
			if (typeof divCapTrans.style.filter != 'undefined')
				divCapTrans.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
			if (typeof divCapTrans.style.opacity != 'undefined')
				divCapTrans.style.opacity = "0.7";
		}
		parentNode.appendChild(divCapTrans);
		fnRemove.push(function(){divCapTrans.parentNode.removeChild(divCapTrans);});

		var divCapText = document.createElement("div");
		divCapText.id = "popBoxDivCapText" + z;
		divCapText.style.width = width - 20 + "px";
		divCapText.style.height = "20px";
		divCapText.style.borderStyle = "none";
		divCapText.style.padding = "0px";
		divCapText.style.margin = "0px";
		divCapText.style.position = "absolute";
		divCapText.style.left = left + 10 + "px";
		divCapText.style.top = top + "px";
		divCapText.style.textAlign = "center";
		divCapText.style.fontFamily = "Arial, Verdana, Sans-Serif";
		divCapText.style.fontSize = "10pt";
		divCapText.style.overflowY = "hidden";
		divCapText.style.backgroundColor = "Transparent";
		divCapText.style.color = "#000000";
		divCapText.style.zIndex = z;
		parentNode.appendChild(divCapText);
		fnRemove.push(function(){divCapText.parentNode.removeChild(divCapText);});

		AddCaptionText(divCapTrans, divCapText, pbCaption);
		
		if (popBoxExpandCaptions == true && divCapText.hasChildNodes() == true)
		{
			var spanMore = divCapText.lastChild;
			if (spanMore && spanMore.onclick)
			{
				spanMore.id = CreateRandomId();
				setTimeout(new Function("", "var spanMore = GetRawObject('" + spanMore.id + "'); if (spanMore != null && spanMore.onclick) { spanMore.onclick(); }"), 10);
			}
		}
	}

	if (fnRemove.length != 0)
	{
		if (objSpan != null)
			fnRemove.push(function(){objSpan.parentNode.removeChild(objSpan);});
		
		if (isRevert == true)
		{
			if(popBox[obj.id].fnPre != null && typeof(popBox[obj.id].fnPre) == 'function')
				fnRemove.push(popBox[obj.id].fnPre);
		
			popBox[obj.id].fnPre = function(){for(var x = 0; x < fnRemove.length; x++){fnRemove[x]();}};
		}
		else
		{
			pbPopBarFunc[obj.id] = function(){for(var x = 0; x < fnRemove.length; x++){fnRemove[x]();}};
		}
	}
}

function AddCaptionText(divCapTrans, divCapText, caption)
{
	var width = parseInt(divCapText.style.width, 10);
	var divSizer = document.createElement("div");
	divSizer.style.position = "absolute";
	divSizer.style.width = width + "px";
	divSizer.style.margin = "0px";
	divSizer.style.fontFamily = divCapText.style.fontFamily;
	divSizer.style.fontSize = divCapText.style.fontSize;
	divSizer.style.visibility = "hidden";
	divSizer.innerHTML = caption;
	document.body.appendChild(divSizer);
	var newSize = GetObjectSize(divSizer);
	if (newSize.h > 20)
	{
		divSizer.innerHTML = caption + "..." + popBoxCaptionLessText;

		newSize = GetObjectSize(divSizer);

		var fullCaption = caption;
		var charCount = parseInt(width * 0.14, 10) - 5; // safe estimate
		divCapText.innerHTML = caption.substr(0, charCount) + "...";
		
		var spanMore = document.createElement("span");
		spanMore.style.color = "#0000ff";
		spanMore.style.textDecoration = "underline";
		spanMore.style.cursor = "pointer";
		spanMore.onclick = function(){spanMore.parentNode.removeChild(spanMore);ResizeCaption(divCapTrans.id,divCapText.id,newSize.h,fullCaption);};
		spanMore.innerHTML = popBoxCaptionMoreText;
		divCapText.appendChild(spanMore);
	}
	else
		divCapText.innerHTML = caption;

	document.body.removeChild(divSizer);
}

function ResizeCaption(divCapTrans, divCapText, height, caption)
{
	if (typeof divCapTrans == "string") divCapTrans = GetRawObject(divCapTrans);
	if (typeof divCapText == "string") divCapText = GetRawObject(divCapText);

	var h = parseInt(divCapText.style.height, 10);
	var top = parseInt(divCapText.style.top, 10);
	
	if (h < height)
	{
		if (h == 20)
		{
			height += 10;
			divCapText.style.paddingTop = "5px";
			divCapText.innerHTML = caption + "...";
			
			var spanLess = document.createElement("span");
			spanLess.style.color = "#0000ff";
			spanLess.style.textDecoration = "underline";
			spanLess.style.cursor = "pointer";
			spanLess.onclick = function(){spanLess.parentNode.removeChild(spanLess);divCapText.innerHTML = caption;ResizeCaption(divCapTrans.id,divCapText.id,20,caption);};
			spanLess.innerHTML = popBoxCaptionLessText;
			divCapText.appendChild(spanLess);
			
			if (popBoxCaptionBelow == false)
			{
				if (typeof divCapTrans.style.filter != 'undefined')
					divCapTrans.style.filter = "";
				if (typeof divCapTrans.style.opacity != 'undefined')
					divCapTrans.style.opacity = "1.0";
			}
		}
		
		if ((h + 10) >= height)
		{
			if (popBoxExpandCaptionsBelow == false)
				top -= (height - h);
			h = height;
		}
		else
		{
			if (popBoxExpandCaptionsBelow == false)
				top -= 10;
			h += 10;
		}
		
		divCapTrans.style.height = h + "px";
		divCapText.style.height = h + "px";
		divCapTrans.style.top = (top - 1) + "px";
		divCapText.style.top = top + "px";

		if (h != height)
			setTimeout("ResizeCaption(\"" + divCapTrans.id + "\",\"" + divCapText.id + "\"," + height + ",\"" + caption + "\")", 10);
	}
	else
	{
		if ((h - 10) <= height)
		{
			if (popBoxExpandCaptionsBelow == false)
				top += (h - height);
			h = height;
		}
		else
		{
			if (popBoxExpandCaptionsBelow == false)
				top += 10;
			h -= 10;
		}
		
		divCapTrans.style.height = h + "px";
		divCapText.style.height = h + "px";
		divCapTrans.style.top = (top - 1) + "px";
		divCapText.style.top = top + "px";
		divCapText.style.paddingTop = "0px";

		if (h == height)
		{
			if (popBoxCaptionBelow == false)
			{
				if (typeof divCapTrans.style.filter != 'undefined')
					divCapTrans.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
				if (typeof divCapTrans.style.opacity != 'undefined')
					divCapTrans.style.opacity = "0.7";
			}

			AddCaptionText(divCapTrans, divCapText, caption);
		}
		else
		{
			setTimeout("ResizeCaption(\"" + divCapTrans.id + "\",\"" + divCapText.id + "\"," + height + ",\"" + caption + "\")", 10);
		}
	}
}

function CreateWaitImage(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);

	var newId = "popBoxImgWait" + obj.id;
	var imgWait = GetRawObject(newId);
	if (imgWait != null)
		return imgWait;

	var left = 0;
	var top = 0;
	if (obj.style.position == "absolute" || obj.style.position == "relative")
	{
		left = parseInt(obj.style.left, 10);
		top = parseInt(obj.style.top, 10);
	}
	else
	{
		var xy = GetElementPosition(obj);
		left = xy.x;
		top = xy.y;
		var padding = GetObjectPadding(obj);
		left -= padding.l;
		top -= padding.t;
	}

	var width = parseInt(obj.style.width, 10);
	var height = parseInt(obj.style.height, 10);
	var size = GetObjectSize(obj);
	if (isNaN(width) == true)
		width = size.w;
	else if (size.w > width)
		left += ((size.w - width) / 2);
	if (isNaN(height) == true)
		height = size.h;
	else if (size.h > height)
		top += ((size.h - height) / 2);

	var parentNode = obj.parentNode;

	try{imgWait = document.createElement("<img src='" + popBoxWaitImage.src + "' />");}
	catch(ex){imgWait = document.createElement("img"); imgWait.src = popBoxWaitImage.src;}
	imgWait.id = newId;
	imgWait.style.position = "absolute";
	imgWait.style.left = (left + (width / 2) - (popBoxWaitImage.width / 2)) + "px";
	imgWait.style.top = (top + (height / 2) - (popBoxWaitImage.height / 2)) + "px";
	imgWait.style.cursor = obj.style.cursor;
	imgWait.style.zIndex = obj.style.zIndex + 1;
	parentNode.appendChild(imgWait);

	return imgWait;
}

// encapsulates the Popped image sizing logic
function CalculateImageDimensions(newWidth, newHeight, fullWidth, fullHeight, windowSize)
{
	if (newWidth == null)
	{
		if (newHeight == null)
		{
			newWidth = fullWidth;
			newHeight = fullHeight;
		}
		else if (newHeight == 0)
		{
			newHeight = Math.min(windowSize.y, fullHeight);
			var scale = parseFloat(newHeight) / parseFloat(fullHeight);
			newWidth = parseInt(fullWidth * scale);
		}
		else
		{
			var scale = parseFloat(newHeight) / parseFloat(fullHeight);
			newWidth = parseInt(fullWidth * scale);
		}
	}
	else if (newWidth == 0)
	{
		if (newHeight == null)
		{
			newWidth = Math.min(windowSize.x, fullWidth);
			var scale = parseFloat(newWidth) / parseFloat(fullWidth);
			newHeight = parseInt(fullHeight * scale);
		}
		else if (newHeight == 0)
		{
			if (windowSize.x < fullWidth || windowSize.y < fullHeight)
			{
				var scale = Math.min(parseFloat(windowSize.x) / parseFloat(fullWidth), parseFloat(windowSize.y) / parseFloat(fullHeight));
				newWidth = parseInt(fullWidth * scale);
				newHeight = parseInt(fullHeight * scale);
			}
			else
			{
				newWidth = fullWidth;
				newHeight = fullHeight;
			}
		}
		else
		{
			var scale = parseFloat(newHeight) / parseFloat(fullHeight);
			newWidth = Math.min(windowSize.x, parseInt(fullWidth * scale));
		}
	}
	else
	{
		if (newHeight == null)
		{
			var scale = parseFloat(newWidth) / parseFloat(fullWidth);
			newHeight = parseInt(fullHeight * scale);
		}
		else if (newHeight == 0)
		{
			var scale = parseFloat(newWidth) / parseFloat(fullWidth);
			newHeight = Math.min(windowSize.y, parseInt(fullHeight * scale));
		}
	}
	
	return {x:newWidth, y:newHeight};
}

function GetObjectToPop(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	if (obj.id == "")
		obj.id = CreateRandomId();

	var poppedSrc = obj.getAttribute('pbSrcNL');
	if (poppedSrc == null && pbSrc[obj.id] == null)
		poppedSrc = obj.getAttribute('pbSrc');

	if (poppedSrc != null && pbSrc[obj.id] == null)
	{
		var poppedImg = new Image();
		poppedImg.src = poppedSrc;
		
		if (pbSrc[obj.id] != null)
			delete pbSrc[obj.id];
			
		pbSrc[obj.id] = poppedImg;
	}
	
	return (pbSrc[obj.id] != null) ? pbSrc[obj.id] : obj;
}

function GetPoppedImageSize(obj)
{
	var size = {x:0, y:0};
	if (obj != null && typeof obj.id != 'undefined')
	{
		if (pbSrc[obj.id] != null)
		{
			size.x = pbSrc[obj.id].width;
			size.y = pbSrc[obj.id].height;
		}
		else if (obj.naturalWidth && obj.naturalHeight)
		{
			size.x = obj.naturalWidth;
			size.y = obj.naturalHeight;
		}
		else
		{
			var img = new Image();
			img.src = obj.src;
			size.x = img.width;
			size.y = img.height;
			delete img;
		}
	}
	return size;
}

/***************************************************************************************************
* This is where the user-callable section starts.
* Function signatures above this line are subject to change.
***************************************************************************************************/

// Globals you can assign
var popBoxAutoClose = true;
var popBoxMouseMoveRevert = true;
var popBoxWaitImage = new Image();
popBoxWaitImage.src = "/jomres/images/spinner40.gif";

var popBoxShowRevertBar = true;
var popBoxShowRevertText = true;
var popBoxShowRevertImage = true;
var popBoxRevertText = "Click sobre la imagen para minimizar.";
var popBoxRevertImage = "/jomres/images/magminus.gif";
var popBoxRevertBarAbove = false;

// there is no popBoxShowPopBar global, but instead the pbShowPopBar attribute must be
// set on the img for the PopBar funtionality to work (can be true or false)
var popBoxShowPopText = true;
var popBoxShowPopImage = true;
var popBoxPopText = "Click para expandir.";
var popBoxPopImage = "/jomres/images/magplus.gif";
var popBoxPopBarAbove = false;

var popBoxShowCaption = true;
var popBoxCaptionBelow = false;
var popBoxCaptionMoreText = "more";
var popBoxCaptionLessText = "less";
var popBoxExpandCaptions = false;
var popBoxExpandCaptionsBelow = false;

// these custom attributes on the <img> element will override the globals above
// pbShowRevertBar, pbShowRevertText, pbShowRevertImage, pbRevertText, pbRevertImage
// pbShowPopBar, pbShowPopText, pbShowPopImage, pbPopText, pbPopImage, pbShowCaption

// Advanced method to begin moves and resizes. (Use Pop/PopEx and Revert where possible instead.)
// X and Y postfixes refer to the top left pixel. W and H postfixes refer to the width and height
// speedM and speedS are the speeds of the move and size respectively
// className denotes the CSS class to apply to the object that is being moved and/or sized
// fnDone denotes the script method to run when the move/resize is complete. It must have a single
// parameter that holds the object itself.
function PopBox(obj, startX, startY, endX, endY, startW, startH, endW, endH, speedM, speedS, className, fnDone)
{
	
var navegador = navigator.appName
if (navegador == "Microsoft Internet Explorer"){ 
//		startY = startY -600;
		endY = endY -600;
}
 
	if (typeof obj == "string") obj = GetRawObject(obj);
	if (obj == null || typeof obj != "object" || isNaN(startX) || isNaN(startY) || isNaN(endX) || isNaN(endY) || isNaN(startW) || isNaN(startH) || isNaN(endW) || isNaN(endH) || isNaN(speedM) || isNaN(speedS))
		return;
	var elem = InitPopBox(obj);

	if (popBox[elem.id].isAnimating == true)
	{
		var str = "PopBox('" + elem.id + "'," + startX + "," + startY + "," + endX + "," + endY + "," + startW + "," + startH + "," + endW + "," + endH + "," + speedM + "," + speedS + ",'" + className + "');";
		setTimeout(str, 10);
	}
	else
	{
		popBox[elem.id].isAnimating = true;
		popBox[elem.id].xCurr = parseFloat(startX);
		popBox[elem.id].yCurr = parseFloat(startY);
		popBox[elem.id].wCurr = parseFloat(startW);
		popBox[elem.id].hCurr = parseFloat(startH);
		popBox[elem.id].xTarg = parseFloat(endX);
		popBox[elem.id].yTarg = parseFloat(endY);
		popBox[elem.id].wTarg = parseFloat(endW);
		popBox[elem.id].hTarg = parseFloat(endH);
		popBox[elem.id].xDelta = Math.abs(parseFloat(endX) - parseFloat(startX));
		popBox[elem.id].yDelta = Math.abs(parseFloat(endY) - parseFloat(startY));
		popBox[elem.id].wDelta = Math.abs(parseFloat(endW) - parseFloat(startW));
		popBox[elem.id].hDelta = Math.abs(parseFloat(endH) - parseFloat(startH));
		popBox[elem.id].velM = (speedM) ? Math.abs(parseFloat(speedM)) : 1.0;
		popBox[elem.id].velS = (speedS) ? Math.abs(parseFloat(speedS)) : 1.0;
		popBox[elem.id].xTravel = 0.0;
		popBox[elem.id].yTravel = 0.0;
		popBox[elem.id].wTravel = 0.0;
		popBox[elem.id].hTravel = 0.0;
		// set element's start position
		elem.style.position = "absolute";
		elem.style.left = startX + "px";
		elem.style.top = startY + "px";
		// set element's start size
		elem.style.width = startW + "px";
		elem.style.height = startH + "px";
		elem.style.display = "inline";

		// the length of the line between start and end points
		var lenMove = Math.sqrt((Math.pow((startX - endX), 2)) + (Math.pow((startY - endY), 2)));
		var lenSize = Math.sqrt((Math.pow((startW - endW), 2)) + (Math.pow((startH - endH), 2)));
		// if the speeds are the same then they should be in sync
		if (popBox[elem.id].velM == popBox[elem.id].velS)
			lenMove = lenSize = Math.sqrt(Math.pow(lenMove, 2) + Math.pow(lenSize, 2));

		// how big the pixel steps are along each axis
		popBox[elem.id].xStep = ((popBox[elem.id].xTarg - popBox[elem.id].xCurr) / lenMove) * popBox[elem.id].velM;
		popBox[elem.id].yStep = ((popBox[elem.id].yTarg - popBox[elem.id].yCurr) / lenMove) * popBox[elem.id].velM;

		// how big the pixel steps are for each resize
		popBox[elem.id].wStep = ((popBox[elem.id].wTarg - popBox[elem.id].wCurr) / lenSize) * popBox[elem.id].velS;
		popBox[elem.id].hStep = ((popBox[elem.id].hTarg - popBox[elem.id].hCurr) / lenSize) * popBox[elem.id].velS;
		
		popBox[elem.id].fnDone = fnDone;
		if (className != null)
			elem.className = className;

		popBox[elem.id].cursor = elem.style.cursor;
		elem.style.cursor = "default";

		if (popBox[elem.id].isPopped == false)
			elem.style.zIndex = ++popBoxZ;

		var id = elem.id;
		if (popBox[elem.id].originalId != null) id = popBox[elem.id].originalId;
		if (pbPopBarFunc[id] != null)
		{
			pbPopBarFunc[id]();
			pbPopBarFunc[id] = null;
		}
			
		if (popBox[elem.id].fnPre != null && typeof popBox[elem.id].fnPre == 'function')
			popBox[elem.id].fnPre();

		// start the repeated invocation of the animation
		popBox[elem.id].interval = setInterval("DoPopBox('" + elem.id + "')", 10);
	}
}

/***************************************************************************************************
* Helper functions. Use these! They are much easier. Call Pop/PopEx and then Revert, or set the
* popBoxAutoClose global to true and Revert will be called for you.
***************************************************************************************************/

// this basic method centers the image in the browser and displays it at its full resolution, subject to window size.
function Pop(obj, speed, className)
{
	PopEx(obj, null, null, 0, 0, speed, className);
}

// If newLeft is null then the image is centered horizontally in the browser. Ditto for newTop (vertically).
// End newLeft and/or newTop with "A" for an absolute position, otherwise it is treated as a relative position.
// Ex: a newLeft of 20 would move right 20 pixels, "20A" would position 20 pixels from the left of it's containing element.
// If newWidth is 0 then the full image width is used, subject to scaling and window size. Ditto for newHeight.
// If newWidth is null the full width is used, regardless of window size, but still subject to scaling. Ditto for newHeight.
function PopEx(obj, newLeft, newTop, newWidth, newHeight, speed, className)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	var objToPop = GetObjectToPop(obj);
	var isReady = (typeof objToPop.readyState != 'undefined') ? (objToPop.readyState == "complete") : ((typeof objToPop.complete != 'undefined') ? (objToPop.complete == true) : true);
	if (isReady == false)
	{
		var imgWait = CreateWaitImage(obj);
		var str = "var imgWait = GetRawObject('" + imgWait.id + "'); if (imgWait != null) { imgWait.parentNode.removeChild(imgWait); } PopEx('" + obj.id + "',";
		if (newLeft == null)
			str += newLeft + ",";
		else
			str += "'" + newLeft + "',";
		if (newTop == null)
			str += newTop + ",";
		else
			str += "'" + newTop + "',";
		str += newWidth + "," + newHeight + "," + speed + ",'" + className + "');";
		objToPop.onload = new Function("", str);
		return;
	}

	var elem = InitPopBox(obj);

	if (popBox[elem.id].isPopped == true) return;

	if (typeof elem.ondblclick == "function")
		elem.onclick = elem.ondblclick;

	var startX = parseInt(elem.style.left);
	var startY = parseInt(elem.style.top);

	// figure out the max window size
	var windowSize = GetInsideWindowSize();
	var hasRevertBar = HasRevertBar(obj);
	var hasCaption = HasCaption(obj);
	if (hasRevertBar == true && popBoxRevertBarAbove == true) windowSize.y -= 20;
	if (hasCaption == true && popBoxCaptionBelow == true) windowSize.y -= 20;

	var fullSize = {x:newWidth, y:newHeight};
	if (newWidth == 0 || newHeight == 0 || newWidth == null || newHeight == null)
	{
		fullSize = GetPoppedImageSize(elem);
		
		// some browsers have a race condition where it still doesn't get set so just fill the window
		if (fullSize.x == 0 || fullSize.y == 0)
		{
			var scale = Math.min(parseFloat(windowSize.x) / parseFloat(elem.width), parseFloat(windowSize.y) / parseFloat(elem.height));
			fullSize.x = parseInt(elem.width * scale);
			fullSize.y = parseInt(elem.height * scale);
		}
	}

	// adjust window size variables for new image boundaries
	if (newLeft != null)
	{
		if (typeof newLeft == "string" && newLeft.indexOf("A") == (newLeft.length - 1))
			newLeft = parseInt(newLeft, 10);
		else
			newLeft = popBox[elem.id].xOriginal + parseInt(newLeft, 10);
			
		windowSize.x -= newLeft;
	}

	if (newTop != null)
	{
		if (typeof newTop == "string" && newTop.indexOf("A") == (newTop.length - 1))
			newTop = parseInt(newTop, 10);
		else
			newTop = popBox[elem.id].yOriginal + parseInt(newTop, 10);
			
		windowSize.y -= newTop;
	}

	// adjust for scrollbars that might appear (quick compromise for browser incompatibilities)
	if (newWidth == null && newHeight == 0 && fullSize.x > (windowSize.x - 20))
		windowSize.y -= 20;
	else if (newWidth == 0 && newHeight == null && fullSize.y > (windowSize.y - 4))
		windowSize.x -= 4;

	var newSize = CalculateImageDimensions(newWidth, newHeight, fullSize.x, fullSize.y, windowSize);

	// width and height are now set, so position it
	if (newLeft == null || newTop == null)
	{
		var scroll = GetScrollOffset();

		if (newLeft == null)
		{
			newLeft = ((windowSize.x / 2) + scroll.x) - (newSize.x / 2);
			if (newLeft < 0) newLeft = 0;
		}
		
		if (newTop == null)
		{
			newTop = ((windowSize.y / 2) + scroll.y) - (newSize.y / 2);
			if (hasRevertBar == true && popBoxRevertBarAbove == true) newTop += 10;
			if (hasCaption == true && popBoxCaptionBelow == true) newTop -= 10;
			if (newTop < 0) newTop = 0;
		}
	}

	var func = null;
	if (typeof PostPopProcessing == "function")
		func = PostPopProcessing;

	if (typeof PrePopProcessing == "function")
		PrePopProcessing(obj);

	PopBox(elem, startX, startY, newLeft, newTop, popBox[elem.id].wOriginal, popBox[elem.id].hOriginal, newSize.x, newSize.y, speed, speed, className, func);
}

function PopInPlace(obj, speed, className)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	var objToPop = GetObjectToPop(obj);
	var isReady = (typeof objToPop.readyState != 'undefined') ? (objToPop.readyState == "complete") : ((typeof objToPop.complete != 'undefined') ? (objToPop.complete == true) : true);
	if (isReady == false)
	{
		var imgWait = CreateWaitImage(obj);
		var str = "var imgWait = GetRawObject('" + imgWait.id + "'); if (imgWait != null) { imgWait.parentNode.removeChild(imgWait); } PopInPlace('" + obj.id + "'," + speed + ",'" + className + "');";
		objToPop.onload = new Function("", str);
		return;
	}

	var elem = InitPopBox(obj);

	if (popBox[elem.id].isPopped == true) return;

	if (typeof elem.ondblclick == "function")
		elem.onclick = elem.ondblclick;

	var startX = parseInt(elem.style.left);
	var startY = parseInt(elem.style.top);

	// figure out the max window size
	var windowSize = GetInsideWindowSize();
	var hasRevertBar = HasRevertBar(obj);
	var hasCaption = HasCaption(obj);
	if (hasRevertBar == true && popBoxRevertBarAbove == true) windowSize.y -= 20;
	if (hasCaption == true && popBoxCaptionBelow == true) windowSize.y -= 20;
	
	var fullSize = GetPoppedImageSize(elem);
	
	// some browsers have a race condition where it still doesn't get set so just fill the window
	if (fullSize.x == 0 || fullSize.y == 0)
	{
		var scale = Math.min(parseFloat(windowSize.x) / parseFloat(elem.width), parseFloat(windowSize.y) / parseFloat(elem.height));
		fullSize.x = parseInt(elem.width * scale);
		fullSize.y = parseInt(elem.height * scale);
	}

	var newSize = CalculateImageDimensions(0, 0, fullSize.x, fullSize.y, windowSize);
	var newLeft = startX - parseInt(((newSize.x - popBox[elem.id].wOriginal) / 2), 10);
	var newTop = startY - parseInt(((newSize.y - popBox[elem.id].hOriginal) / 2), 10);

	// have the best case position, now adjust it if it would expand beyond the window
	var scroll = GetScrollOffset();
	if (scroll.x > newLeft)
	{
		newLeft = scroll.x;
	}
	else
	{
		var xOffset = ((newLeft + newSize.x) - (windowSize.x + scroll.x));
		if (xOffset > 0) newLeft -= xOffset;
	}

	if (scroll.y > newTop)
	{
		newTop = scroll.y;
	}
	else
	{
		var yOffset = ((newTop + newSize.y) - (windowSize.y + scroll.y));
		if (yOffset > 0) newTop -= yOffset;
	}

	if (hasRevertBar == true && popBoxRevertBarAbove == true) newTop += 10;
	if (hasCaption == true && popBoxCaptionBelow == true) newTop -= 10;
	if (newTop < 0) newTop = 0;
	
	var func = null;
	if (typeof PostPopProcessing == "function")
		func = PostPopProcessing;

	if (typeof PrePopProcessing == "function")
		PrePopProcessing(obj);

	PopBox(elem, startX, startY, newLeft, newTop, popBox[elem.id].wOriginal, popBox[elem.id].hOriginal, newSize.x, newSize.y, speed, speed, className, func);
}

// Helper function for PopBox to move/resize the image back to its original position/size. Use this! It's much easier.
function Revert(obj, speed, className)
{
	if (typeof obj == "string") obj = GetRawObject(obj); 
	if (obj == null || typeof popBox[obj.id] == "undefined" || popBox[obj.id] == null) return;

	if (typeof speed == 'undefined' || speed == null || speed == 0)
		speed = Math.max(popBox[obj.id].velM, popBox[obj.id].velS);
		
	if (typeof className == 'undefined')
		className = popBox[obj.id].originalClassName;
	
	var func = null;
	if (typeof PostRevertProcessing == "function")
		func = PostRevertProcessing;

	if (typeof PreRevertProcessing == "function")
		PreRevertProcessing(obj);

	PopBox(obj, popBox[obj.id].xTarg, popBox[obj.id].yTarg, popBox[obj.id].xOriginal, popBox[obj.id].yOriginal, popBox[obj.id].wTarg, popBox[obj.id].hTarg, popBox[obj.id].wOriginal, popBox[obj.id].hOriginal, speed, speed, className, func);
}

// Helper function to revert all images.
function RevertAll(speed, className)
{
	for (var i = 0; i < popBoxIds.length; i++)
		Revert(popBoxIds[i], speed, className);
}

/***************************************************************************************************
* These methods are the pre and post processing events for Pop/PopEx and Revert.
* Feel free to copy them to your own page script and add your own code to the method bodies.
***************************************************************************************************/

// called before the Pop begins
// The parameter is the original object
//function PrePopProcessing(obj)
//{
//}

// called after the pop is complete
// The parameter is the copy of the object that is resized
//function PostPopProcessing(obj)
//{
//}

// called before the Revert begins
// The parameter is the copy of the object that is resized
//function PreRevertProcessing(obj)
//{
//}

// called after the Revert is complete
// The parameter is the original object
//function PostRevertProcessing(obj)
//{
//}

