var isNS4		= (document.layers)? true : false;
var isIE4		= (document.all && !document.getElementById)? true : false;
var isIE5		= (document.all && document.getElementById)? true : false;
var isNS6		= (!document.all && document.getElementById)? true : false;

//var language		= "es"; // - defined in JSIncludes.xsl
var sailings		= (language == "en")?"sailings":"salidas";
var sailing			= (language == "en")?"sailing":"salida";
var found			= (language == "en")?"found":"encontradas";
var notFound		= (language == "en")?"No sailings found":"No salidas encontradas";
var allDestinations	= (language == "en")?"All destinations":"Todos los Destinos";
var allCruiselines	= (language == "en")?"All cruise lines":"Todas las L\u00EDneas";
var allCategories	= (language == "en")?"All categories":"Todas las Categorias";
var allShips		= (language == "en")?"All ships":"Todos los Barcos";
var showAll			= (language == "en")?"Show all":"Mostrar Todos";
var allPorts		= (language == "en")?"All ports":"Todos los Puertos";
var allLength		= (language == "en")?"All length":"Todos";
var days			= (language == "en")?"days":"dias";
var all				= (language == "en")?"All":"Todos";

var Jan			= (language == "en")?"Jan":"ene";
var Feb			= (language == "en")?"Feb":"feb";
var Mar			= (language == "en")?"Mar":"mar";
var Apr			= (language == "en")?"Apr":"abr";
var May			= (language == "en")?"May":"may";
var Jun			= (language == "en")?"Jun":"jun";
var Jul			= (language == "en")?"Jul":"jul";
var Aug			= (language == "en")?"Aug":"ago";
var Sep			= (language == "en")?"Sep":"sep";
var Oct			= (language == "en")?"Oct":"oct";
var Nov			= (language == "en")?"Nov":"nov";
var Dec			= (language == "en")?"Dec":"dic";

/**
*
* 
*/
function getElement(name)
{
	var value = null;
	if(isIE4 || isIE5){
		value = document.all(name);
	}else if (isNS6){
		value = document.getElementById(name);
	}
	return value;
}

function getElements(name)
{
	var values = null;
	if(isIE4 || isIE5){
		values = document.all(name);
	}else if (isNS6){
		values = document.getElementsByName(name);
	}
	return values;
}

///<summary>
/// Fill Combo box with a list of items
///</summary>
///<parameter>cb			- DropDown element that should be filled </parameter>
///<parameter>arrayText		- array with text attributes </parameter>
///<parameter>arrayValues	- array with values attributes </parameter>
function FillCombo2(cb, arrayObjects) {
	for(var i=0; i<arrayObjects.length; i++)
		cb.options[cb.length]	= new Option(arrayObjects[i].Name, arrayObjects[i].ID);
}

/**
*
* 
*/
function ClearCombo(cb) {
	for(var i=cb.length-1; i >=0; i--)
		cb.options[i] = null;
}

///<summary>
/// Fill Combo box with a list of items
///</summary>
///<parameter>cb			- DropDown element that should be filled </parameter>
///<parameter>arrayText		- array with text attributes </parameter>
///<parameter>arrayValues	- array with values attributes </parameter>
function FillLengthCombo(cb, arrayObjects, shrink) 
{
	if (shrink)
	{
		for(var i=0; i<arrayObjects.length; i++)
			cb.options[cb.length] = new Option((arrayObjects[i].ID == "0|0")?all:(arrayObjects[i].Name), arrayObjects[i].ID);
	}
	else
	{
		for(var i=0; i<arrayObjects.length; i++)
			cb.options[cb.length] = new Option((arrayObjects[i].ID == "0|0")?allLength:(arrayObjects[i].Name+" "+days), arrayObjects[i].ID);
	}
}

/**
*
*
*/
function AddAllOption (cb, strText) {
	cb.options[0]	= new Option(strText, "-1", false, false);
}


/**
*
*
*/
function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
	newwindow = window.open(theURL,winName,features);
	if (window.focus) {newwindow.focus()}
}

function InsertInnerHTML(objectId, htmlScript) 
{ 
	var htmlObject = getElement(objectId);
	htmlObject.innerHTML		= htmlScript;
}

/**
*
*
*/
function MM_showHideLayers() 
{ //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for(i=0; i<(args.length-2); i+=3)
	if ((obj=MM_findObj(args[i]))!=null) 
	{	
		v=args[i+2];
		if (obj.style){ 
			obj=obj.style; 
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}
		obj.visibility=v;
	}
}
	
/**
*
*
*/	
function MM_findObj(n, d) 
{ //v4.01
	var p,i,x;  
	if(!d) 
		d=document;
		 
	if((p=n.indexOf("?"))>0 && parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	
	if(!(x=d[n]) && d.all) 
		x=d.all[n];
	
	for (i=0;!x && i<d.forms.length;i++)
		x= d.forms[i][n];
	
	for(i=0;!x && d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	
	if(!x && d.getElementById) 
		x=d.getElementById(n);
		
	return x;
}

//
//
//
//gets the value of a cookie if exist
function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) 
	{              
		begin = document.cookie.indexOf(NameOfCookie+"=");       
		if (begin != -1) 
		{           
			begin += NameOfCookie.length+1;       
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end));
		} 
	}
	return null;
}

//
//
//
// set a cookie
function setCookie(NameOfCookie, value, expiredays) {
	var c = NameOfCookie + "=" + escape(value);
	if (expiredays!=null) {
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		document.cookie = c + "; expires=" + ExpireDate.toGMTString();
	} else
		document.cookie = c; 
}


/**
*
* 
*/
function SetDefaultSelection(cb, val)
{
	for(var idx = 0; idx < cb.options.length; idx++)
	{
		if(cb.options[idx].value == val)
		{
			cb.options[idx].selected=true;
			break;
		}
	}
}

function hideCalendar()
{
    try
    {
        window.parent.document.onclick.call();
    }
    catch(e)
    {
    }
}

function toggleHDUrl(source, hdName, idList) 
{
    var inputs = document.getElementsByName(hdName);
    for (var i=0; i < inputs.length; i++)
    {
        inputs[i].checked = source.checked;
    }
    getHDCBID(hdName, idList);
}

function getHDCBID(cbName, idList)
{
    document.getElementById(idList).value = '';
    var inputs = document.getElementsByName(cbName);
    for (var i=0; i < inputs.length; i++)
    {
        if (inputs[i].checked == true)
        {
            document.getElementById(idList).value = document.getElementById(idList).value + inputs[i].id + ",";
        }
    }
    if (document.getElementById(idList).value.length > 0)
    {
        document.getElementById(idList).value = document.getElementById(idList).value.substring(0, document.getElementById(idList).value.length-1);
    }
}