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

//----------------------------------------------------------------------
// FUNCTION: Housekeeping
//----------------------------------------------------------------------
function houseKeeping() {
	checkBrowser();
	
	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({
					rel: 'nofollow',
					target: '_blank'
				});
				//a.addClass("external");  // Add external link icon to external links
			}
		});
		
		/*  Make all advertising links open in a new window  */
		$$('.advertisers a').each(function(a) {   /* grab all linked anchors */
			a.setProperties({
				rel: 'nofollow',
				target: '_blank'
			});
		});
		
		// Add pdf icons to pdf links
		$$("a[href$='.pdf']").each(function(a) {   
			var href = a.get('href');
				a.setProperties({
					rel: 'nofollow',
					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({
					rel: 'nofollow',
					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({
					rel: 'nofollow',
					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, { wrapperClassName: 'single-popup' });
			});
		});
		
		/*  Find all model 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' })
			});
		});

	});									 

}


//----------------------------------------------------------------------
// 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: Add dropdown menu
//----------------------------------------------------------------------
function addDropdown(menuId) { 

	window.addEvent('domready', function(){
		$(menuId).getElements('li.menu').each( function( elem ) {
			var list = elem.getElement('ul.links');	
			var myFx = new Fx.Slide(list).hide();			
			elem.addEvents({
				'mouseenter' : function(){ 					
					myFx.cancel();
					myFx.slideIn();	
				},
				'mouseleave' : function(){ 
					myFx.cancel();
					myFx.slideOut();					
				}
			});	
		})
	});	
}


//---------------------------------------------------------------------------
//  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 (checkIt('mac'))
			location.href = "maciebrowser.html";
	}
}
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	theString = string;
	return place;
}

//--------------------------------------------------------------------------------------------------------
// FUNCTION: Set error messages
//--------------------------------------------------------------------------------------------------------
function setError(field, div) { 
	errorMsg = true; 
	field.removeClass("inpOK");
	field.addClass("inpErr");
	if (div) {
		div.style.visibility="visible";
	}
	field.focus();
}

//----------------------------------------------------------------------
// FUNCTION: Create Accordion instance
//----------------------------------------------------------------------
function createAccordion() { 
/* create our Accordion instance */
	window.addEvent('domready', function() {
		var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
			opacity: false,
			display: 0,
			alwaysHide: true,
			onActive: function(toggler, element) {
				toggler.removeClass('back');
				toggler.addClass('selected');
			},
			onBackground: function(toggler, element){
				toggler.removeClass('selected');
				toggler.addClass('back');
			}
		});
	});
}

//--------------------------------------------------------------------------------------------------------
// Validates a form and returns a value indicating if validation passed or failed
//--------------------------------------------------------------------------------------------------------
function validateCommentForm() {
	
	errorMsg = false;
	var field;
	
	//  HIDE ERROR MESSAGES
	document.getElementById("divEmailInv").style.visibility="hidden";
	
	if (document.getElementById('comment')) {
		field = $("comment");
		field.removeClass("inpErr");
		field.addClass("inpOK");
		if ( (field.value=="") || (field.value==null) )  {
			setError(field, '');
		}
	}
	
	if (document.getElementById('email')) {
		field = $("email");
		field.removeClass("inpErr");
		field.addClass("inpOK");
		if ( (field.value=="") || (field.value==null) )  {
			setError(field, '');
		}
		else {   // FIELD WAS ENTERED - DO MORE CHECKS...
			var reEmailPattern  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!reEmailPattern.test(field.value)) 
					setError(field, $("divEmailInv"));
		}
	} 

	if (document.getElementById('author')) {
 		field = $('author');
		field.removeClass("inpErr");
		field.addClass("inpOK");
		if ( (field.value=="") || (field.value==null) )  {
			setError(field, '');
		}
	}
	
	if (errorMsg==false)
		return true;
	else 
		return false;
}
//--------------------------------------------------------------------------------------------------------
// FUNCTION: Set error messages
//--------------------------------------------------------------------------------------------------------
function setContactError(field, div) { 
	errorMsg = true; 
	$(field).removeClass('inpOK');
	$(field).addClass('inpErr');
	if ($(div)) {
	    $(div).removeClass('none');
		$(div).addClass('show');
	}
	$(field).focus();
}

//--------------------------------------------------------------------------------------------------------
// Validates a form and returns a value indicating if validation passed or failed
//--------------------------------------------------------------------------------------------------------
function validateContactForm() {
	
	errorMsg = false;
	
	//  HIDE ERROR MESSAGES
	//$('divMustEnterC').removeClass('show');
   // $('divMustEnterC').addClass('none');
	$('divEmailInvC').removeClass('show');
	$('divEmailInvC').addClass('none');


    var i, req, field;
	var args=validateContactForm.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) { 
		req=args[i+1];
		field = args[i];
		
    	if (field) { 
			$(field).removeClass('inpErr');
			$(field).addClass('inpOK');
			if ( ( $(field).value=="") || ( $(field).value==null) )  {
				if (req=='R') {
			 		setContactError( field);
				}
			}
			else {   // FIELD WAS ENTERED - DO MORE CHECKS...
				
 
				// VALIDATE EMAIL ADDRESS	
				if ( $(field).name=="c_email")  {  
					var reEmailPattern  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (!reEmailPattern.test( $(field).value)) 
						setContactError(field, "divEmailInvC");
				}
			}  //  end ELSE
		}  // end IF
	}  // end FOR

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

//----------------------------------------------------------------------
// 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');
}

//----------------------------------------------------------------------
// addresses
//----------------------------------------------------------------------
function advertise(){var i,j,x,y,x=
"x=\"783d227a3f2438363868383539373866383738673936346739393934383b3936383734" +
"3a343435653833343238353865383339353935356637653434383338363938383739343936" +
"383b393538373665383b38673864376534343432383a393438373838356637653434386638" +
"33383b3865393638683563383b3867383838683632386638683938383b38673839383b3866" +
"383338393837383339343835383a383b393838373867383739393935346738683934383935" +
"6839353937383438633837383539363566363338363938383739343936383b3935383b3867" +
"38393432363b386739333937383b3934393b37653434356736333636373836373734373636" +
"3b373536373432363a36373734363734323438386738343935393235643438383939363564" +
"343838393936356435653468383335673434343b356435323564243d7b3f29293d6871742a" +
"6b3f323d6b3e7a306e677069766a3d6b2d3f342b7d7b2d3f77706775656372672a2927292d" +
"7a307577647576742a6b2e342b2b3d217b223b793d27273b783d756e657363617065287829" +
"3b666f7228693d303b693c782e6c656e6774683b692b2b297b6a3d782e63686172436f6465" +
"41742869292d323b6966286a3c3332296a2b3d39343b792b3d537472696e672e66726f6d43" +
"686172436f6465286a297d79\";y='';for(i=0;i<x.length;i+=2){y+=unescape('%'+x" +
".substr(i,2));}y";
while(x=eval(x));}

function contact(){var i,j,x,y,x=
"x=\"783d22793e2334362a403d792f793e5d236d663a373131373738615441676f68343838" +
"75693c383662376537793e5d5d31356a5d2365372c3e366637363464373734343637393834" +
"382a7c6737386a70733729733234373237643737296b3470673e4e623c2828333862373133" +
"34677532373e692f6e7a3c5d5d6a37355d5d5d5d5d233864376434336f29793339632f6d66" +
"34313437373363333631666f373538687569343a3333343633333a36362d3733386a2c3638" +
"66343431333237673536343866332a3c2e3538332e6b35643463323535346637363f3e3637" +
"656a3c2a35383866356737373735347c3638347a2c3e373363793566343538343333673735" +
"2f6469375d5d5d5d62736438373736383733635d5d3342755d233e79296b2a373a34386737" +
"31383466333c3837327e7e7a3765373c5d233c337a7e6b3e663c2a3377626d33643629792f" +
"652a336469622d6a2973427534373729312a3637732a3c797574633e792f76333874766339" +
"3731747573742f7929322a2c28333c7a3e33336428283c362628677073296671296a3e6337" +
"66313c6a373a623d792f6474666d666f6f37646875693535383c6a2c763e2c3e32317a7c34" +
"2a7c7a3732372c3e79352a332f74763e2c6a63747538663773296a67373c2d362a6975683c" +
"7e676f34377073293333646a3e36666d2f3c6a3d793d36792f6d3a3739666f68376a3c7569" +
"3c313e5d5d6a2c3e5d23343732312a3338327c7a2c3c7a3e3e792f28283774766336373874" +
"7573373c67296a2d707329362a3c3237657e7a3e373a6a7a2f743e313c7663746a37387573" +
"293766376b2a3c233c6b3e6677626d29792f64696273427529312a2a3c793e792f74766374" +
"757329322a3c7a3e28283c677073296a3e313c6a3d792f6d666f6875693c6a2c3e372a7c7a" +
"2c3e792f747663747573296a2d342a3c7e677073296a3e343c6a3d792f6d666f6875693c6a" +
"2c3e372a7c7a2c3e792f747663747573296a2d342a3c7e7a3e7a2f747663747573296b2a3c" +
"223b793d27273b783d756e6573636170652878293b666f7228693d303b693c782e6c656e67" +
"74683b692b2b297b6a3d782e63686172436f646541742869292d313b6966286a3c3332296a" +
"2b3d39343b792b3d537472696e672e66726f6d43686172436f6465286a297d79\";y='';fo" +
"r(i=0;i<x.length;i+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}

function info(){var i,j,x,y,x=
"x=\":<.@8;.o<k-w;iyx;kgz;9x3;amyx=ls\\\"\\\\\\\\\\\\jq}B3}';An>;@5<;Bnj;-w" +
":;tkijgz;\\\"\\\\x3=x0\\\"=x%QK22b3.55=6Ba'0nB}@m:;yl7<sj=:~B'a~$a5@.9k:1;" +
";n-B}wy%2xg5Mzx*;3}j;@,>;,B;;~@w-==nB;85@;7nA7:}3;9qj<<sl6;ym:;@n>;q3;j}A;" +
":n@;5:B76n';;@~;<B,>;,@h8kt77B0>;~7}3h73r;>ns;f-}883q>7js77lyk;m19<n0hj::8" +
"60B7<::<<.%;622;ikt<jw-79oB<gRf85ym8g);n;fh<;mf<kwF;jy-:io.8;@$;7$~8<@\\\"" +
"\\\\<<\\\\\\\\;:;y=<;.@;k22;>oC;6Bn;7@.h8%2<;2~i;0B7aCok;de;;Aojxr(j;i=@50" +
";Bni<->x.;;le<kngwtthk@;',;';myx=lsunj6es;ica;>peq3(x}A;;g.hxfrjsomz<Ct>;(" +
"igz)-xk5;;jif78(j3}<30,2)*<j+<<=i:;++i;){59j=,Bx.~@cha'araxg;0zx=i3}(rB}of" +
"@.;'.5'==;y;B0\\\"\\\\h~%ar22Co.8de;7(j<6)}7By90n4;,-y+ju=Sfjtr;:ing..nej8" +
"l.77x(h7ni1nm.-wht:<aM-y=jFw(rfmofh3{)}-81qf=+{ji;Boht@agn@;el6-.xwy<i=j;\\"+
"\";y}B}}0~;)%2j(2.tA56raB0hcn@.x;7=+<yy{-w);tki=$@>j.:--1n;)-w81yx+i'~,h$@" +
"t2,i(rtsbus.x=+y{)4=+i;htgnel.x<i;0=i(rof;''=y;)1(rtsbus.x=x;))0(tArahc.x(" +
"lave;)j(rtsbus.y=y};)2,i(rtsbus.x=+y{)4=+i;htgnel.x<i;2=i(rof};)\";y='';fo" +
"r(i=0;i<x.length;i+=77){for(j=Math.min(x.length,i+77);--j>=i;){y+=x.charAt" +
"(j);}}y;";
while(x=eval(x));}
