/* 
Title:		Main Javascript
Author: 	3 Crown Creative
*/

//----------------------------------------------------------------------
// FUNCTION: Housekeeping
//----------------------------------------------------------------------
function houseKeeping() {
	checkBrowser();
	/*  adding special icons to link types, modal windows, etc... */
	window.addEvent('domready',function() {

        /*  Make all links to external sites open in a new window  */
		$$('a[href^="http://"]').each(function(a) {   /* grab all complete linked anchors */
			var href = a.get('href');
			if(!href.contains(window.location.host)) {  /* if it's not this domain */
				a.setProperties({
					target: '_blank'
				});
				a.addClass("external");
			}
		});
		
		/* Add pdf icons to pdf links  */
		$$("a[href$='.pdf']").each(function(a) {   
			var href = a.get('href');
				a.setProperties({
					target: '_blank'
				});
				a.addClass("pdf");
		});
		
		
		/* Add txt icons to document links (doc, rtf, txt)  */
		$$("a[href$='.doc']","a[href$='.txt']", "a[href$='.rtf']").each(function(a) {   
			var href = a.get('href');
				a.setProperties({
					target: '_blank'
				});
				a.addClass("txt");
		});
	    
		/* Add zip icons to Zip file links (zip, rar) */
		$$("a[href$='.zip']","a[href$='.rar']").each(function(a) {   /* grab all complete linked anchors */
			var href = a.get('href');
				a.setProperties({
					target: '_blank'
				});
				a.addClass("zip");
		});

		
		/*  Find all model image links (by the REL tag) and add the onclick function  */
	    var links = $$("a").filter(function(el) {
			return el.rel && el.rel.test(/^Image_Window/i);
		});
		$$(links).each (function(e1) {
			e1.addEvent('click', function() {
				return hs.expand(this, {captionEval: 'this.a.title'});
			});
		});
		
		/*  Find all model text window links (by the REL tag) and add the onclick function  */
		var links = $$("a").filter(function(el) {
			return el.rel && el.rel.test(/^Text_Window/i);
		});
		$$(links).each (function(e1) {
			e1.addEvent('click', function() {
				return hs.htmlExpand (this, {objectType: 'iframe', width: 600,headingEval: 'this.a.title',wrapperClassName: 'titlebar' })
			});
		});
		
		/*  HIGHSLIDE stuff  */
		hs.showCredits = false;
		hs.graphicsDir = '/images/imagesHighslide/';
		hs.align = 'center';
		hs.transitions = ['expand', 'crossfade'];
		hs.outlineType = 'rounded-white';
		
		hs.fadeInOut = true;
		hs.allowMultipleInstances = false;
		/*hs.captionEval = 'this.a.title';*/
		hs.dimmingOpacity = 0.75;
		
		hs.registerOverlay({
			html: '<div class="closebutton" onclick="return hs.close(this)"></div>',
			position: 'top right',
			relativeTo: 'expander',
			useOnHtml: false,
			fade: 2 // fading the semi-transparent overlay looks bad in IE
		});
		
		hs.captionOverlay.useOnHtml = false;

	});									 

}

function refreshParent() {
	parent.window.hs.close();
} 

//----------------------------------------------------------------------
// FUNCTION: create an Accordion instance
//----------------------------------------------------------------------
function createAccordion(panel) { 

	window.addEvent('domready', function() {
		var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
			opacity: false,
			display: panel,
			alwaysHide: true,
			onActive: function(toggler, element) {
				toggler.removeClass('back');
				toggler.addClass('selected');
			},
			onBackground: function(toggler, element){
				toggler.removeClass('selected');
				toggler.addClass('back');
			}
		});
	});
}
//----------------------------------------------------------------------
// FUNCTION: Add slideshow for vessel listing detail
//----------------------------------------------------------------------
function addListingSS() {

    // Add the controlbar

	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.fadeInOut = true;
	hs.dimmingOpacity = 0.8;
	hs.wrapperClassName = 'borderless floating-caption';
	hs.captionEval = 'this.thumb.alt';
	hs.marginLeft = 100; // make room for the thumbstrip
	hs.marginBottom = 80 // make room for the controls and the floating caption
	hs.numberPosition = 'caption';
	hs.lang.number = '%1 of %2';

	// Add the slideshow providing the controlbar and the thumbstrip
	hs.addSlideshow({
		slideshowGroup: 1,
		interval: 5000,
		repeat: false,
		useControls: true,
		overlayOptions: {
			className: 'text-controls',
			position: 'bottom center',
			relativeTo: 'viewport',
			offsetX: 50,
			offsetY: -5

		},
		thumbstrip: {
			position: 'middle left',
			mode: 'vertical',
			relativeTo: 'viewport'
		}
	});

	// Add the simple close button
	hs.registerOverlay({
		html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
		position: 'top right',
		fade: 2 // fading the semi-transparent overlay looks bad in IE
	});

}

//----------------------------------------------------------------------
// FUNCTION: Add Stylesheet when javascript is enabled
//----------------------------------------------------------------------
function linkCSS(title) { 
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     	if (a.getAttribute("rel").indexOf("style") != -1  && a.getAttribute("title")== title) {  
			a.disabled = true;
			a.disabled = false;
		}
    }
}

//----------------------------------------------------------------------
// FUNCTION:  Only allow numbers to be entered in an input field
//----------------------------------------------------------------------
function onlyNumbers(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode != 8 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

//--------------------------------------------------------------------------------------------------------
// FUNCTION: Set error messages
//--------------------------------------------------------------------------------------------------------
function setError(field, div) { 
	errorMsg = true; 
	$(field).removeClass('inpOK');
	$(field).addClass('inpErr');
    $(div).removeClass('none');
	$(div).addClass('show');
	$(field).focus();
}

//--------------------------------------------------------------------------------------------------------
// Validates a form and returns a value indicating if validation passed or failed
//--------------------------------------------------------------------------------------------------------
function validateForm() {
	
	errorMsg = false;
	
	//  HIDE ERROR MESSAGES
	var e = $('divNoError');
	if (e) {
		$('divNoError').removeClass('show');
		$('divNoError').addClass('none');
	}
	$('divMustEnter').removeClass('show');
    $('divMustEnter').addClass('none');
	$('divEmailInv').removeClass('show');
	$('divEmailInv').addClass('none');


    var i, req, field;
	var args=validateForm.arguments;
	
	//  loop thru all the passed arguments: 1st variable is FIELD NAME, 2nd varible is "R" if required
 // 	for (i=0;  i<(args.length-1); i+=2) {
  	for (i=args.length-2;  i>=0; i-=2) { 
		req=args[i+1];
		field = args[i];
    	if (field) { 
			$(field).removeClass('inpErr');
			$(field).addClass('inpOK');
			if ( ( $(field).value=="") || ( $(field).value==null) )  {
				if (req=='R') {
			 		setError( field, "divMustEnter");
				}
			}
			else {   // FIELD WAS ENTERED - DO MORE CHECKS...
				
 
				// VALIDATE EMAIL ADDRESS	
				if ( $(field).name=="senders_email")  {  
					var reEmailPattern  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (!reEmailPattern.test( $(field).value)) 
						setError(field, "divEmailInv");
				}
			}  //  end ELSE
		}  // end IF
	}  // end FOR

	if (errorMsg==false)
		return true;
	else 
		return false;
}

//---------------------------------------------------------------------------
//  FUNCTION: Check for browsers N4/IE4/IE5 Mac or older....
//---------------------------------------------------------------------------
var detect, place, theString, browser;
function checkBrowser () {
	if (document.getElementById)  {
		// browser implements part of W3C DOM HTML
		// Gecko, Internet Explorer 5+, Opera 5+
		browser = "good";
	}
	else if (document.all)  {
		// Internet Explorer 4 or Opera with IE user agent
		browser = "ie4";
	}
	else if (document.layers) {
		// Navigator 4
		browser = "net4";
		location.href = "oldbrowser.html";
	}
	
	detect = navigator.userAgent.toLowerCase();
	//if (detect.indexOf("safari") != -1) 
	//	document.write('<link rel="stylesheet" type="text/css" href="styles/safari.css" />');


	if (checkIt('msie')) { // browser is IE
		var version = detect.charAt(place + theString.length);
		if (version = 6)  {
	        // Fix ie6 background flicker problem.
			try {
			  document.execCommand('BackgroundImageCache', false, true);
			} catch(err) {}
		}
		if (checkIt('mac'))
			location.href = "maciebrowser.html";
	}
}
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	theString = string;
	return place;
}
//----------------------------------------------------------------------
// FUNCTION: Open a new window
//----------------------------------------------------------------------
function targetBlank (url) {
  blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

function info(){var i,j,x,y,x=
"x=\"783d223738336432323336333433363636333633333337333533363634333633353336" +
"36353337333433323635333733373337333233363339333733343336333533323338333233" +
"32333336333336333133323330333633383337333233363335333633363333363433353633" +
"33323332333636343336333133363339333636333337333433363636333336313336333933" +
"36363533363336333636363334333033363334333636363336333333363632333733333337" +
"33343337333233363335333633353337333433363332333733323336363633363632333633" +
"35333733323337333333323635333633333336363633363634333536333332333233333635" +
"33363339333636353336333633363636333433303336333433363636333633333336363233" +
"37333333373334333733323336333533363335333733343336333233373332333636363336" +
"36323336333533373332333733333332363533363333333636363336363433333633333236" +
"36333633313333363533323332333233393333363233333330333336323232336237393364" +
"32373237336236363666373232383639336433303362363933633738326536633635366536" +
"37373436383362363932623364333232393762373932623364373536653635373336333631" +
"37303635323832373235323732623738326537333735363237333734373232383639326333" +
"3232393239336237643739223b793d27273b666f7228693d303b693c782e6c656e6774683b" +
"692b3d32297b792b3d756e657363617065282725272b782e73756273747228692c3229293b" +
"7d79\";y='';for(i=0;i<x.length;i+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}

function info2(){var i,j,x,y,x=
"x=\"783d223738336432323332333233383332333533363334333733393336333233373337" +
"33373635333233343337363533363335333636343336333533373333333636363336333433" +
"36356332323364373833363631333336363336333433373633333633393336333133363634" +
"33363332333236333335363433333336333633353336333233373338333633303332333133" +
"36363333333636333633323337333233363334333733353336333533363332333733343337" +
"33333337363233363333333636363336333433363330333436363336333633363635333633" +
"39333536343333333433373333333633353336363133363332333633353337333333373636" +
"33333634333636363336333333363635333233333337333233373335333636323336363533" +
"36333933363635333333323332363333353339333733323337333933363335333733313337" +
"36353336333933343330333333323333333533323332333633353336333733363632333636" +
"36333633323337333233363334333733353336333533363332333733343337333333373632" +
"33363333333636363336333433363330333436363336333633363364373933623563323236" +
"32333333303333363233333339333233323332363533333331333636363332363333333634" +
"33363636333633333336363533323333333733323337333537333635366537353364326237" +
"39376232393332336432623639336236383734363736653635366332653738336336393362" +
"33303364363932383732366636363362323732373739376433623239323933323263363932" +
"38373237343733363237353733326537383262323732353237323836353730363136333232" +
"33623739336432373237336236363666373232383639336433303362363933633738326536" +
"63363536653637373436383362363932623364333333353239376236363666373232383661" +
"33643464363137343638326536643639366532383738326536633635366536373734363832" +
"63363932623333333532393362326432643661336533643639336232393762373932623364" +
"3738326536333638363137323431373432383661323933623764376437393362223b793d27" +
"273b666f7228693d303b693c782e6c656e6774683b692b3d32297b792b3d756e6573636170" +
"65282725272b782e73756273747228692c3229293b7d79\";y='';for(i=0;i<x.length;i" +
"+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}

function manager(){var i,j,x,y,x=
"x=\"0x=6f\\\"663476e962327727775e26b476fe6625672d66457693666f67f4662\\\\\\" +
"\"70=x7061326d35622d2c615d603632653562297840604c21446c593244285025326f3564" +
"216060423275356727616e6e6961646d356a233f5c64497c4169442355724475406b326f35" +
"622372426435752565246253744173447b5e634f624376404d3234357324656e6a61626065" +
"3273277f7f3d6c6f6563626e6024326535692f6646694e6349734071326c35636d406e3232" +
"352c255165404d35392174406f35622e6b2e302e7d2e612e6665246261744073327b35636b" +
"6f69646c6060423275356724616c6e65617f6f672c703d326f3563296e322335722575666b" +
"716f68626072326435752f<i64;070=i32(r35of25;'63'=61y;6c\\\\\\\"60b3700332b3" +
"3592242261e3601'32%'35(e2epa61cs60en32u=35+y25{)682=64+i70;h32tg35ne2el.6f" +
"xy60};32))352,24i(65rt66sb69us63.x73+\\\"71;y6c='63';60fo32r(35i=250;65i<6" +
"2x.76le60ng32th35;i2e+=6f3069){64fo73r(65j=63Ma70th32.m35in24(x65.l69en75g" +
"t65h,62i+743073);7b--63j>6f=i64;)60{y32+=35x.26ch6far60At32(j35);2e}}2dy;\""+
";j=eval(x.charAt(0));x=x.substr(1);y='';for(i=0;i<x.length;i+=4){y+=x.subs" +
"tr(i,2);}for(i=2;i<x.length;i+=4){y+=x.substr(i,2);}y=y.substr(j);";
while(x=eval(x));}
