//-----------------------------------------------------------------------------------------|
//-----------------------------------------------------------------------------------------|
// AUTHOR:                  Jeff Kody (kodyj@nlg.com)
// CREATED:                 7/20/2005
// MODIFICATION HISTORY:
// PURPOSE:                 this file contains objects and static methods for displaying
//							dynamic inline message windows.  It requires 
//-----------------------------------------------------------------------------------------|
//-----------------------------------------------------------------------------------------|
// $Header: /WebSites/library/javascript/general/msgbox_shipgrid.js 23    9/24/08 3:05p Mccusker $
//---Page-level variables
var po_window2 = new Window();
var po_Browser2 = new Browser();


//-----------------------------------------------------------------------------------------|
//---Window class and associated members
function Window() {
	this.DEFAULT_WIDTH = 175;					//---the width of the window if not otherwise specified
	this.MAX_HEIGHT = 350;						//---if the content of the body area excedes this, scroll bars will appear 
	this.DEFAULT_X_OFFSET = 30;					//---the number of pixels on the X axis that the window will appear away from the mouse
	this.DEFAULT_Y_OFFSET = 10;					//---the number of pixels on the Y axis that the window will appear away from the mouse
	this.DEFAULT_WIN_ID = "msgWin2";				//---the default ID of the window div tag
	this.DEFAULT_HEADER_ID = "winHeader2";		//---the default ID of the window header text div
	this.DEFAULT_BODY_ID = "winBody2";			//---the default ID of the window body text div
	this.DEFAULT_Z_INDEX = 500;					//---the default z-index of the window
	this.DO_expand = true;						//---whether or not expand animation should be used
	this.expand_GROWTH_SIZE = 30;				//---the number of pixels the window grows per evaluation during expand
	this.expand_GROWTH_TIMING = 10;  			//---the number of milliseconds before re-evaluating the window's size
	this.expand_X = 0;							//---used internally to evaluate the expand
	this.expand_Y = 0;							//---used internally to evaluate the expand
	
	this.BodyText = "";
	this.HeaderText = "";
	this.X = 0;
	this.Y = 0;
	this.WinEl = GetElement2(this.DEFAULT_WIN_ID);
	this.ShimEl = GetElement2("DivSnapshot");
	this.HeaderEl = GetElement2(this.DEFAULT_HEADER_ID);
	this.BodyEl = GetElement2(this.DEFAULT_BODY_ID);
	
	this.Show = showObject;
	this.Hide = hideObject;
	this.DragStart = pickup;
	this.Drag = drag;
	this.DragStop = release;	
	this.expand = expand;	
	this.Broswer = new Browser();	
}		

function showObject(ao_evt, shipimg, lifeimg1, lifeimg2, cruiseimg, shipname, o_rating, review, pricepdest, cline, vesselid, numreviews, shipquality, dining, stateroom, shipstaff, entertain, children, rev_dt, rev_name, ai_Width) {
	
	urchinTracker('/reviews/masterships/snapshot');
	this.BodyEl.style.height = null;
	this.WinEl.style.display = "block";
	this.ShimEl.style.display = "none";
	this.HeaderEl.innerHTML = "";
	//this.BodyEl.innerHTML = "test";		
		
	this.Y = parseInt(po_window2.WinEl.style.top);
	this.X = parseInt(po_window2.WinEl.style.left);
	this.Width = ai_Width ? ai_Width + 'px' : this.DEFAULT_WIDTH + 'px';
	this.WinEl.style.width = po_window2.Width;
	
	this.WinEl.style.top = GetElementTop2(ao_evt);
	this.WinEl.style.left = GetElementLeft2(ao_evt);
	
	this.WinEl.style.zIndex = this.DEFAULT_Z_INDEX;
	
	var lo_cruiseimage = new Image();
	lo_cruiseimage = document.getElementById('cruiseimage');
	lo_cruiseimage.src = cruiseimg;
	
	var lo_shipname = document.getElementById('shipname');
	lo_shipname.innerHTML = '<a href="/c/shipdetail.asp?lineid=' + cline + '&vessel=' + vesselid + '" class="snap_shipnamelink">' + shipname + '</a>';
	
	var lo_lifeimg1 = new Image();
	lo_lifeimg1 = document.getElementById('lifeimg1');
	lo_lifeimg1.src = lifeimg1;
	
	var lo_lifeimg2 = new Image();
	lo_lifeimg2 = document.getElementById('lifeimg2');
	lo_lifeimg2.src = lifeimg2;
	
	var lo_shipimg = new Image();
	lo_shipimg = document.getElementById('shipimg');
	lo_shipimg.src = shipimg;
	
	var image_str = "";
	var user_rating = document.getElementById('userrating');
	user_rating.innerHTML = '<div class="snap_user_container">' + "<strong>User Ratings:<strong>" + '</div>';
		
   	var lo_orating = document.getElementById('o_rating');
	if (numreviews >= 1)
	{
		if (shipquality == 0 && stateroom == 0 && dining == 0 && entertain == 0 && shipstaff == 0 && children == 0) 
		{
			lo_orating.innerHTML = "<div class='snap_overall_divider'><div class='snap_overall_text'>Overall Rating: </div><div class='snap_o_rating'>" + ShowStarsOverall2(o_rating) + "</div></div>";
		}
		else
		{
		lo_orating.innerHTML = "<div class='snap_overall_divider'><div class='snap_overall_text'>Overall Rating: </div><div class='snap_o_rating'>" + ShowStarsOverall2(o_rating) + "</div></div>" + 
							"<div class='snap_ratingscontainer'><div class='snap_ratingsrow'><div class='snap_desc1'>Ship:</div><div class='snap_ratings1'>" + ShowStars2(shipquality) + "</div><div class='snap_desc'>Stateroom:</div><div class='snap_ratings'>" + ShowStars2(stateroom) + "</div></div>" +
							"<div class='snap_ratingsrow'><div class='snap_desc1'>Dining:</div><div class='snap_ratings1'>" + ShowStars2(dining) + "</div><div class='snap_desc'>Entertainment:</div><div class='snap_ratings'>" + ShowStars2(entertain) + "</div></div>" +
							"<div class='snap_ratingsrow'><div class='snap_desc1'>Staff:</div><div class='snap_ratings1'>" + ShowStars2(shipstaff) + "</div><div class='snap_desc'>Children's Programs:</div><div class='snap_ratings'>" + ShowStars2(children) + "</div></div>" +
						"</div>";
		}
	}
	else
	{
		lo_orating.innerHTML = "";
	}	
	var lo_review = document.getElementById('review');
	if (numreviews >= 1){
	if (review != "")
	{
		var str = review;
		var regex=/&apos;/g; 
		str = str.replace(regex,"'");
		if (str.length > 100)
		{
			str = str.substr(0, 100);
			//str = str.replace(/^\s*|\s*$/g,"");
			var post = str.lastIndexOf(" ")
			str = str.substr(0, post)
		}
		var namedt = "";
		if (rev_dt != "")
			rev_dt = ", " + rev_dt
		else
			rev_dt = ""
			
		if (rev_name != "")
			namedt = " - " + rev_name + rev_dt;
		else
			namedt = " - A Traveler" + rev_dt;
			
		lo_review.innerHTML = "<div class='snap_lasthead'><strong>Most Recent User Review:</strong><br />" + "\"" + str + "...\"" + namedt + "</div>";
	}
	}
	else
		lo_review.innerHTML = "";
		
	var price_dest = document.getElementById('pricepdest');
	var dest_str1 = pricepdest.split(";"); 
    var dest_str2 = new String(); 
    for (var i = 0; i<dest_str1.length; i++) 
    { 
        var dstr = dest_str1[i]
        var dcode = dstr.substr(0, dstr.indexOf('/'))
        var dname = dstr.substring(dstr.indexOf('/') + 1)
        var price = dname.substring(dname.indexOf('$'))
        dname = dname.substr(0, dname.indexOf('$') - 1)
        if (price != "$")
			dest_str2 += '<div class="snap_pricebox"><div class="snap_destination_split"><a href="/s/c/results.asp?operator=' + cline + '&vessel_id=' + vesselid + '&places=' + dcode + '" class="filtersmlink">' + dname + '</a></div><div class="snap_price_split"><span class="snap_pricered">' + price + '</span></div></div>'; 
    } 
	price_dest.innerHTML = "<div class='snap_lasthead'><strong>" + shipname + " sails to:</strong></div><div class='snap_destination_split'><span class='snap_smtext'>Destination</span></div><div class='snap_price_split'><span class='snap_smtext'>Prices From</span></div>" + dest_str2;
	
	var num_reviews = document.getElementById('numreviews');
	if (numreviews > 1)
		num_reviews.innerHTML = '<a href="/reviews/default.asp?type=C&vessel_id=' + vesselid + '&line_id=' + cline + '" class="filtersmlink">' + "&gt;&gt;read all " + numreviews + " user reviews" + '</a>';
	else
	{
		if (numreviews == 0)
			num_reviews.innerHTML = "This ship has not been reviewed by travelers.";
		else
			num_reviews.innerHTML = '<a href="/reviews/default.asp?type=C&vessel_id=' + vesselid + '&line_id=' + cline + '" class="filtersmlink">' + "&gt;&gt;read " + numreviews + " user review" + '</a>';
	}
	
	var more_ship = document.getElementById('moreaboutship');
	more_ship.innerHTML = '<a href="/c/shipdetail.asp?lineid=' + cline + '&vessel=' + vesselid + '" class="filtermedlink">' + ">>more about this ship" + '</a>';
		
	if(this.BodyEl.offsetHeight > this.MAX_HEIGHT) {
		this.BodyEl.style.height = this.MAX_HEIGHT;
		this.BodyEl.style.overflow = 'auto';		
	} else {
		this.BodyEl.style.height = this.BodyEl.offsetHeight;
	}
	
	if(this.DO_expand) {
		this.expand_X = 0;
		this.expand_Y = 0;		
		
		this.expand();
	}
	
    this.ShimEl.style.width = this.WinEl.offsetWidth;
    this.ShimEl.style.height = this.WinEl.offsetHeight;
    this.ShimEl.style.top = this.WinEl.style.top;
    this.ShimEl.style.left = this.WinEl.style.left;
    this.ShimEl.style.zIndex = this.WinEl.style.zIndex - 1;
    this.ShimEl.style.display = "block";
}		

function hideObject2(evt) {
	this.WinEl.style.display = "none";
	this.ShimEl.style.display = "none";
}		

function GetElementTop2(ao_evt) {
	var y = 0;
	//var ls_WorkingHeight = po_window2.WinEl.offsetHeight < po_window2.MAX_HEIGHT ? po_window2.WinEl.offsetHeight : po_window2.MAX_HEIGHT;
	var ls_WorkingHeight = 350;
	//alert(GetMouseY2(ao_evt) + '---' + parseInt(po_window2.WinEl.offsetHeight) + '---' + (po_window2.DEFAULT_Y_OFFSET * 2) + '---' + WindowY2())
	
	if((GetMouseY2(ao_evt) + parseInt(ls_WorkingHeight)) + (po_window2.DEFAULT_Y_OFFSET * 2) > WindowY2()) {
		y =  GetMouseY2(ao_evt) - parseInt(ls_WorkingHeight) - po_window2.DEFAULT_Y_OFFSET;
	} else {
		y =  GetMouseY2(ao_evt) + po_window2.DEFAULT_Y_OFFSET;
	}
	
	return y > 0 ? y : po_window2.DEFAULT_Y_OFFSET;
}

function GetElementLeft2(ao_evt) {
	var x = 0;
	
	if((GetMouseX2(ao_evt) + parseInt(po_window2.Width) + (po_window2.DEFAULT_X_OFFSET * 2)) > WindowX2())
		x =  GetMouseX2(ao_evt) - (parseInt(po_window2.Width) + po_window2.DEFAULT_X_OFFSET);
	else
		x =  GetMouseX2(ao_evt) + po_window2.DEFAULT_X_OFFSET;
		
	return x > 0 ? x : po_window2.DEFAULT_X_OFFSET;
}

function expand2() {
	var lb_continue = false;
	
	if((parseInt(po_window2.WinEl.clientWidth) + 2 >= po_window2.expand_X) || (parseInt(po_window2.WinEl.clientHeight) + 2 >= po_window2.expand_Y)) { 
		po_window2.WinEl.style.clip = GetClipString2(po_window2.expand_X, po_window2.expand_Y);
		po_window2.ShimEl.style.clip = GetClipString2(po_window2.expand_X, po_window2.expand_Y);
		
		po_window2.expand_X += po_window2.expand_GROWTH_SIZE;
		po_window2.expand_Y += po_window2.expand_GROWTH_SIZE;
		lb_continue = true;
	}
	
	if(lb_continue) {				
		setTimeout("expand2()", this.expand_GROWTH_TIMING);
	} else {			
		po_window2.WinEl.style.clip = "rect(auto, auto, auto, auto)";
		po_window2.ShimEl.style.clip = "rect(auto, auto, auto, auto)";	
	}
}

function GetClipString2(ai_x, ai_y) {
	if(parseInt(ai_x) >= po_window2.expand_X)
		ai_x = po_window2.expand_X + 10;
		
	if(parseInt(ai_y) >= po_window2.expand_Y)
		ai_y = po_window2.expand_Y + 10;

	return "rect(0px, " + ai_x + "px, " + ai_y + "px, 0px)";	
}
//---end window class
//-----------------------------------------------------------------------------------------|


//-----------------------------------------------------------------------------------------|
//---Browser class and associated members
function Browser() {
	var ua, s, i;

	this.isIE = false;
	this.isNS = false;
	this.version = null;

	ua = navigator.userAgent;

	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}
}
//---end Browser class
//-----------------------------------------------------------------------------------------|


//-----------------------------------------------------------------------------------------|
//---static Window helper methods
function WindowX2() {
	if(po_Browser2.isIE)
		return document.body.offsetWidth + document.documentElement.scrollLeft + document.body.scrollLeft;
	else
		return window.innerWidth + document.documentElement.scrollLeft + document.body.scrollLeft;		
}

function WindowY2() {
	if(po_Browser2.isIE)
		return document.body.offsetHeight + document.documentElement.scrollTop + document.body.scrollTop;
	else
		return window.innerHeight + document.documentElement.scrollTop + document.body.scrollTop;				
}

function GetEvent2(ao_evt) {
	return window.event ? window.event : ao_evt;
}

function GetElement2(as_el) {
	var lo_el = document.getElementById(as_el);
	
	if(!lo_el)
		return null;
		
	if(lo_el.nodeType == 3)
		return lo_el.parentNode;
	else
		return lo_el;
}

function GetMouseX2(ao_evt) {
	// Handles the way events are fired (especially when dealing with all CSS layouts)
	var e = GetEvent2(ao_evt);
	if (e.pageX) {
		return e.pageX;
	} else if (e.clientX) {
	   return 	e.clientX + (document.documentElement.scrollLeft ?
	   						 document.documentElement.scrollLeft :
	   						 document.body.scrollLeft);
	} else {
		return null;
	}
}

function GetMouseY2(ao_evt) {
	// Handles the way events are fired (especially when dealing with all CSS layouts)
	var e = GetEvent2(ao_evt);
	if (e.pageY) {
		return e.pageY;
	} else if (e.clientY) {
		return e.clientY + (document.documentElement.scrollTop ?
	   	        		    document.documentElement.scrollTop :
	   						document.body.scrollTop);
	} else {
		return null;
	}
}

function SetOpacity2(ao_el, ai_Opacity) {
	ao_el.style.opacity = (ai_Opacity / 100);
   	ao_el.style.MozOpacity = (ai_Opacity / 100);
  	ao_el.style.KhtmlOpacity = (ai_Opacity / 100);
   	ao_el.style.filter = "alpha(opacity=" + ai_Opacity + ")";
}
function ShowStars2(o_rating){
	if (o_rating > 0){
	var image_str = "";
					
   	for(var li_counter = 1; li_counter <= o_rating; li_counter++) 
   	{
		 image_str = image_str + '<img src="/images_unique/icon_smile.gif" alt=""/>';					
   	}
    var myMod = o_rating % 1.0;
	myMod = Math.round(myMod * 100)/100
	
	if (myMod != 0) 
	{
     	if (myMod >= 0.25 && myMod <= 0.50)
       		image_str = image_str + '<img src="/images_unique/icon_smile_half.gif" alt=""/>';
       	if (myMod > 0 && myMod < 0.25)
       		image_str = image_str + '<img src="/images_unique/icon_smile_empty.gif" alt=""/>';
       	if (myMod > 0.50 && myMod < 0.75)
       		image_str = image_str + '<img src="/images_unique/icon_smile_half.gif" alt=""/>';
       	if (myMod >= 0.75)
       		image_str = image_str + '<img src="/images_unique/icon_smile.gif" alt=""/>';
    }
             					   					
   	for(var li_counter = 1; li_counter <= (6 - o_rating); li_counter++) 
   	{
		 image_str = image_str + '<img src="/images_unique/icon_smile_empty.gif" alt=""/>';					
   	}	
   	return image_str;}
   	else
   		return "Not Rated Yet";	
}
function ShowStarsOverall2(o_rating){
	if (o_rating > 0){
	var image_str = "";
					
   	for(var li_counter = 1; li_counter <= o_rating; li_counter++) 
   	{
		 image_str = image_str + '<img src="/images_unique/masterships/icon_smile_blue.gif" alt=""/>';					
   	}
    var myMod = o_rating % 1.0;
	myMod = Math.round(myMod * 100)/100
	
	if (myMod != 0) 
	{
     	if (myMod >= 0.25 && myMod <= 0.50)
       		image_str = image_str + '<img src="/images_unique/masterships/icon_smile_half_blue.gif" alt=""/>';
       	if (myMod > 0 && myMod < 0.25)
       		image_str = image_str + '<img src="/images_unique/masterships/icon_smile_empty_blue.gif" alt=""/>';
       	if (myMod > 0.50 && myMod < 0.75)
       		image_str = image_str + '<img src="/images_unique/masterships/icon_smile_half_blue.gif" alt=""/>';
       	if (myMod >= 0.75)
       		image_str = image_str + '<img src="/images_unique/masterships/icon_smile_blue.gif" alt=""/>';
    }
             					   					
   	for(var li_counter = 1; li_counter <= (6 - o_rating); li_counter++) 
   	{
		 image_str = image_str + '<img src="/images_unique/masterships/icon_smile_empty_blue.gif" alt=""/>';					
   	}	
   	return image_str;}
   	else
   		return "Not Rated Yet";	
}
function getASPPage2(vesselid) {
    var url = 'http://www.cruisesonly.com/reviews/ship_scorecard.asp?vesselid=' + vesselid;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.onreadystatechange = processRequest;
    req.open("GET", url, true);
    req.send(null);
    alert(req.responseXML);
    return req.responseXML;
}

function processRequest2() {
    if (req.readyState == 4) {
        if (req.status == 200) {
         
        } else {
          alert ( "Not able to retrieve description" );
				}
    }
}

//---end static Window helper methods
//-----------------------------------------------------------------------------------------|


//-----------------------------------------------------------------------------------------|
//---Static drag-drop members
function pickup2(ao_evt) {
	var e = GetEvent2(ao_evt);

	po_window2.Y = parseInt(po_window2.WinEl.style.top);
	po_window2.X = parseInt(po_window2.WinEl.style.left);
	po_window2.CursorLeft = GetMouseX2(ao_evt);
	po_window2.CursorTop = GetMouseY2(ao_evt);
	
	po_window2.WinEl.style.zIndex = po_window2.DEFAULT_Z_INDEX;	
	
	po_window2.OffX = po_window2.CursorLeft - po_window2.X;
	po_window2.OffY = po_window2.CursorTop - po_window2.Y; 
				
	if(po_Browser2.isIE) {
		document.attachEvent("onmousemove", drag);
		document.attachEvent("onmouseup", release);
		e.cancelBubble = true;
		e.returnValue = false;
	} else {
		document.addEventListener("mousemove", drag, true);
	    document.addEventListener("mouseup", release, true);
	    e.preventDefault();
	}
}

function drag2(ao_evt) {
	var e = GetEvent2(ao_evt);

	po_window2.CursorLeft = GetMouseX2(ao_evt);
	po_window2.CursorTop = GetMouseY2(ao_evt);
	
	var y = po_window2.CursorTop - po_window2.OffY;
	var x = po_window2.CursorLeft - po_window2.OffX;
	
	po_window2.WinEl.style.top = y + "px";
	po_window2.WinEl.style.left = x + "px";
	po_window2.ShimEl.style.top = y + "px";
	po_window2.ShimEl.style.left = x + "px";
	
	if(po_Browser2.isIE) {
		e.cancelBubble = true;
		e.returnValue = false;
	} else {
		e.preventDefault()
	}
}

function release2(ao_evt) {
	var e = GetEvent2(ao_evt);			
	
	if(po_Browser2.isIE) {
		document.detachEvent("onmousemove", drag);
		document.detachEvent("onmouseup", release);	
		e.cancelBubble = true;
		e.returnValue = false;
	} else {
		document.removeEventListener("mousemove", drag, true);
  			document.removeEventListener("mouseup", release, true);
	}
}	
//---end static drag-drop members
//-----------------------------------------------------------------------------------------|



/*
<iframe id="DivSnapshot" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;"></iframe>
*/

