var ValueLabels = {
	init : function(){
		$("input.valuelabel").each(function (i) {this.honkiSecret = this.value});
		$("input.valuelabel").focus( function() {
			if ($(this).attr("value") == $(this).attr("honkiSecret")) $(this).attr("value", "");
			}).blur( function() {
			if ($(this).attr("value") == "") $(this).attr("value", $(this).attr("honkiSecret"));
			});
		}
	};

var cruiseSearch = {
	init : function(){
		var checked = $("#fSave").attr("checked");
		if (!checked)
			$("#fBack").hide(1);
		$("#fSave").click(function(){
			if (!checked) {
				$("#fBack").show();
				$("#fBack select").show();
			}
			else {
				$("#fBack").hide();
				$("#fBack select").hide();
			}
			checked = !checked;
			});
		}
	};

$(document).ready(function(){
	ValueLabels.init();
	cruiseSearch.init();
});


function cityClick(cityId) {
	$("div.city").hide();
	$("div[name='city_" + cityId + "']").show();
}

function submitSendLinkForm() {
	var form 			= document.forms["send_link"];
	var done = true;
	
	$("form.validable .required:input").each( function() {
		
		if($(this).val() == 0 || $(this).val().length <= 0) {
			$(this).addClass('red');
			done = false;
		} else
			$(this).removeClass('red');
	});
	
	if (done)
		form.submit()
	else 
		alert('Fill in the fields required');
}

function submitContactForm() {
	var form 			= document.forms["contact_form"];
	var required 		= new Array("name", "phone", "email", "text");
	var ok				= true;
	var focusedObject	= null;

	for(var i = 0; i < required.length; i++) {
		var field = form.elements[required[i]];
		if ((field.type == "text" || field == "textarea") && form.elements[required[i]].disabled == false) {
			if (field.value == "" || field.value.length == 0) {
				ok = false;
				if (!focusedObject)
					focusedObject = field;
				field.style.border = "1px solid #ff0000";
			}
			else {
				field.style.borderTop = "1px solid #197eb8";
				field.style.borderLeft = "1px solid #197eb8";
				field.style.borderBottom = "1px solid #dfeef3";
				field.style.borderRight = "1px solid #dfeef3";
				
			}
		}
	}
	
	if (focusedObject)
		focusedObject.focus();

	if (ok)
		if (checkEmail(form.elements["email"].value))
			form.submit();
		else {
			alert('E-mail address is incorrect');
			form.elements["email"].focus();
			form.elements["email"].select();
			form.elements["email"].style.border = "1px solid #ff0000";
		}
	else {
		alert('Fill in the fields required');
	}
}

function submitContactCompanyForm() {
	var form 			= document.forms["contact_company_form"];
	var required 		= new Array("name", "email", "phone", "company", "street", "city", "people", "term", "len", "days");
	var ok				= true;
	var focusedObject	= null;

	for(var i = 0; i < required.length; i++) {
		var field = form.elements[required[i]];
		if ((field.type == "text" || field == "textarea") && form.elements[required[i]].disabled == false) {
			if (field.value == "") {
				ok = false;
				if (!focusedObject)
					focusedObject = field;
				field.style.border = "1px solid #ff0000";
			}
			else {
				field.style.borderTop = "1px solid #197eb8";
				field.style.borderLeft = "1px solid #197eb8";
				field.style.borderBottom = "1px solid #dfeef3";
				field.style.borderRight = "1px solid #dfeef3";
				
			}
		}
	}

	if (form.elements["integration"].checked == false &&
		form.elements["training"].checked == false &&
		form.elements["tour"].checked == false) {
			ok = false;
		}
		
	if (focusedObject)
		focusedObject.focus();

	if (ok)
		if (checkEmail(form.elements["email"].value))
			form.submit();
		else {
			alert('E-mail address is incorrect');
			form.elements["email"].focus();
			form.elements["email"].select();
			form.elements["email"].style.border = "1px solid #ff0000";
		}
	else {
		alert('Fill in the fields required');
	}
}

function checkEmail(str) {
	var filter	= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z0-9]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(str))
		return true;
	else
		return false;
}

function isIE(){
	return ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) );
}

function openPopup(src, title, params)
{
	// flash
	if  ( src.indexOf(".swf") != -1 ){
		openPopFlash(src, title, params);
	}
	// image
	else if  ( src.indexOf(".") != -1 ){	

		if ( typeof imgCheck == 'undefined' ){
			imgCheck = setInterval(function () {
				checkImgCache(src, title, params);
			}, 200);
		}
		
	// page
	}else{
		openPopPage(src, title, params);
	}
}//openPopup

function openPopFlash(url, title, params){
	
	var pop_title = (title == undefined || title.length == 0) ? "Popup" : title;
	
	if ( params != undefined && params.length > 0 ){
		temp = params.split(",");
		params = new Array();
		
		for ( i=0;i<temp.length;i++ ){
			if ( temp[i] != undefined )
			{
				var k = temp[i].split("=");
				params[k[0]] = new Array();
				params[k[0]] = k[1];
			}
		}
	}
	
	var win_width = screen.availWidth;
	var win_height = screen.availHeight;
	
	var pop_width = 800;
	var pop_height = 700;
	
	var	pop_top = parseInt(win_height/2-pop_height/2);
	var	pop_left = parseInt(win_width/2-pop_width/2);
	
	var pop_params = '';
	
	if ( params != undefined ){
		if ( params['scrollbars'] != undefined ) pop_params += ',scrollbars = yes';
		if ( params['menubar'] != undefined ) pop_params += ',menubar = yes';
		if ( params['resizable'] != undefined ) pop_params += ',resizable = yes';
		if ( params['toolbar'] != undefined ) pop_params += ',toolbar = yes';
		if ( params['location'] != undefined ) pop_params += ',location = yes';
		if ( params['status'] != undefined ) pop_params += ',status = yes';
		
		if ( params['top'] != undefined )  pop_top = params['top'];
		if ( params['left'] != undefined )  pop_left = params['left'];
		if ( params['width'] != undefined )  pop_width = params['width'];
		if ( params['height'] != undefined )  pop_height = params['height'];
		
		if ( params['top'] == undefined && params['left'] == undefined && params['width'] != undefined && params['height'] != undefined){
			pop_top = parseInt(win_height/2-params['height']/2);
			pop_left = parseInt(win_width/2-params['width']/2);
		}
		
	}else{
		pop_params += ',scrollbars=yes,resizable=yes';
		pop_width = 700;
		pop_height = 560;
		pop_top = parseInt(win_height/2-pop_height/2);
		pop_left = parseInt(win_width/2-pop_width/2);
	}
	
	pop_params += ',left='+pop_left+',top='+pop_top+',width='+pop_width+', height='+pop_height;
	
	pop = window.open(url, pop_title, ''+pop_params+'');
	
}//openPopFlash

function openPopPage(url, title, params){
	
	pop_title = (title == undefined || title.length == 0) ? "Popup" : title;
	
	if ( params != undefined && params.length > 0 ){
		temp = params.split(",");
		params = new Array();
		
		for ( i=0;i<temp.length;i++ ){
			if ( temp[i] != undefined )
			{
				var k = temp[i].split("=");
				params[k[0]] = new Array();
				params[k[0]] = k[1];
			}
		}
	}
	
	var win_width = screen.availWidth;
	var win_height = screen.availHeight;
	
	var pop_width = 800;
	var pop_height = 700;
	
	var	pop_top = parseInt(win_height/2-pop_height/2);
	var	pop_left = parseInt(win_width/2-pop_width/2);
	
	var pop_params = '';
	
	if ( params != undefined ){
		if ( params['scrollbars'] != undefined ) pop_params += ',scrollbars = yes';
		if ( params['menubar'] != undefined ) pop_params += ',menubar = yes';
		if ( params['resizable'] != undefined ) pop_params += ',resizable = yes';
		if ( params['toolbar'] != undefined ) pop_params += ',toolbar = yes';
		if ( params['location'] != undefined ) pop_params += ',location = yes';
		if ( params['status'] != undefined ) pop_params += ',status = yes';
		
		if ( params['top'] != undefined )  pop_top = params['top'];
		if ( params['left'] != undefined )  pop_left = params['left'];
		if ( params['width'] != undefined )  pop_width = params['width'];
		if ( params['height'] != undefined )  pop_height = params['height'];
		
		if ( params['top'] == undefined && params['left'] == undefined && params['width'] != undefined && params['height'] != undefined){
			pop_top = parseInt(win_height/2-params['height']/2);
			pop_left = parseInt(win_width/2-params['width']/2);
		}
		
	}else{
		pop_params += ',scrollbars=yes,resizable=yes';
		pop_width = 700;
		pop_height = 560;
		pop_top = parseInt(win_height/2-pop_height/2);
		pop_left = parseInt(win_width/2-pop_width/2);
	}
	
	pop_params += ',left='+pop_left+',top='+pop_top+',width='+pop_width+', height='+pop_height;
	pop_params = pop_params.substr(1);
	
	pop = window.open(url, pop_title, pop_params);
	
}//openPopPage

function checkImgCache(image, title, params){
	
	var img = new Image();
	var img_src = (image.substring(0,7)!= '_images') ? '_images'+image : image;
	
	img.src = img_src;
	var width = img.width;
	var height = img.height;
	
	if ( width > 0 ){
		clearInterval(imgCheck);
		delete imgCheck;
		
		var pop_title = (title == undefined || title.length == 0) ? "Popup" : title;
		var img = new Image();
		img.src = img_src;
		var img_width = img.width;
		var img_height = img.height;
		
		if ( params != undefined && params.length > 0 ){
			temp = params.split(",");
			params = new Array();
			
			for ( i=0;i<temp.length;i++ ){
				if ( temp[i] != undefined )
				{
					var k = temp[i].split("=");
					params[k[0]] = new Array();
					params[k[0]] = k[1];
				}
			}
		}
		
		var win_width = screen.availWidth;
		var win_height = screen.availHeight;
		
		var pop_top = parseInt(win_height/2-img_height/2);
		var pop_left = parseInt(win_width/2-img_width/2);
		
		if (navigator.appName == "Microsoft Internet Explorer"){
			var pop_width = img_width+36;
			var pop_height = img_height+20;
		}else{
			var pop_width = img_width+20;
			var pop_height = img_height+20;
		}
		
		
		if ( pop_height > win_height ){
			pop_height = win_height-60;
			pop_top = 0;
		}
		
		if ( pop_width > win_width ){
			pop_width = win_width-60;
			pop_left = 0;
		}
		
		var pop_params = '';
		
		if ( params != undefined ){
			if ( params['scrollbars'] != undefined ) pop_params += ',scrollbars = yes';
			if ( params['menubar'] != undefined ) pop_params += ',menubar = yes';
			if ( params['resizable'] != undefined ) pop_params += ',resizable = yes';
			if ( params['toolbar'] != undefined ) pop_params += ',toolbar = yes';
			if ( params['location'] != undefined ) pop_params += ',location = yes';
			if ( params['status'] != undefined ) pop_params += ',status = yes';
			
			if ( params['top'] != undefined )  pop_top = params['top'];
			if ( params['left'] != undefined )  pop_left = params['left'];
			if ( params['width'] != undefined )  pop_width = params['width'];
			if ( params['height'] != undefined )  pop_height = params['height'];
			
			if ( params['top'] == undefined && params['left'] == undefined && params['width'] != undefined && params['height'] != undefined){
				pop_top = parseInt(win_height/2-params['height']/2);
				pop_left = parseInt(win_width/2-params['width']/2);
			}
			
		}else{
			pop_params += ',scrollbars=yes,resizable=yes';
		}
		
		pop_params += ',left='+pop_left+',top='+pop_top+',width='+pop_width+', height='+pop_height;
		
		showPop(pop_title, img_width, img_height, img_src, pop_params);
		
	}
	
}//checkCache

function showPop(pop_title, img_width, img_height, img_src, params){
	
	body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	body += '<html><head><title>'+pop_title+'</title>';
	body += '<script language="JavaScript"></script>';
	body += '</head><body style="background:#ffffff;padding:6px;margin:0px">';
	body += '<div style="position:absolute; left: 50%; top: 50%; width: '+img_width+'px; height: '+img_height+'px; margin-top: -'+(img_height/2)+'px; margin-left: -'+(img_width/2)+'px;"><a id="image" href="#" onClick="window.close()" onfocus="blur()"><img src="'+img_src+'" alt="" style="border:1px solid #CCCCCC" /></a></div>';
	body += '</body></html>';
	pop = window.open('','',''+params+'')
	pop.document.open();
	pop.document.write(body);
	pop.document.close();
	
}//showPop


function goTo(url) {
	document.location = url;
}
