if( typeof( Cookie.read ) != "undefined" ) {
Cookie.get = function( name ) {
	return Cookie.read( name );
}
}
/*
if( typeof(Tips) == "undefined" ) {
	new Element( 'script', {
		'type': 'text/javascript',
		'src': '/central-texas/tips.js'
	}).inject( document.body );
}
*/
function center( styles ) {
	return { 
		'left': Math.round( ( ( window.getScrollWidth()-parseFloat( styles['width'] ) ) / 2 ), 1 ), 
		'top': Math.round( ( ( window.getHeight()-parseFloat( styles['height'] ) ) / 2 ) + window.getScrollTop(), 1 )
	};
}

function maxOf(x, y) { // Utility function to find max of 2 numbers
	if (($type(x) != 'number') || ($type(y) != 'number')) {
	    return -1;
	}
	if (x < y) {
	    return y;
	}
	return x;
}

function centerit( element ) {

	var top = window.getSize().y / 2;
	var left = window.getSize().x / 2;
	
	element.setStyle("display", "block"); //Without this below line does not give correct value.
	top = maxOf(top - (element.getSize().y / 2), 0);
	left = maxOf(left - (element.getSize().x / 2), 0);
	
	element.setStyle("top", top);
    element.setStyle("left", left);

}

function isZip(s) 
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          alert("Zip Code Is Not Valid");
          return false;
     }

return true;
}

ajaxalert = function( msg ) {

	alert( msg );
/*
	var msg = new Element( 'div' ).setStyles({
		'padding': '4px',
		'background-color': '#EFA017',
		'color': '#ffffff',
		'font-size': '12px',
		'margin-bottom': '10px',
		'margin-top': '10px'
	}).setHTML( msg ).injectTop( $( document.forms[2] ) );
	del = function() { msg.remove(); }.delay(5000);
*/	
}

var equote_ajax = '/central-texas/equotev2/_remote.php/api/';
var homesource_ajax = '/central-texas/homesource/_remote.php/api/';
var autosource_ajax = '/central-texas/autosource/_remote.php/api/';

function isNumeric( str ) {
	return str.length ? !isNaN(str.replace(/\s/,"z")/1) : true
}

function isValidEmail(str) {
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

function isValidCreditCard(number) {
	if(number.length>0 && typeOfCard(number)=="UNKNOWN") return false;
	if(number.length<1) return false;
	var total = 0;
	var flag = 0;
	if(number.length>16) return false;
	for (var i=(number.length - 1);i>=0; i--) {
		if (flag == 1) {
			var digits = number.charAt(i) * 2;
			if (digits > 9) digits -= 9;
			total += digits;
			flag = 0;
		} else {
			total = total + parseInt(number.charAt(i));
			flag = 1;
		}
	}
	if ((total%10) == 0 ) {
		return true;
	} else {
		return false;
	}
}
function typeOfCard(number) {
	var firstNumber = number.substring(0,1);
	var firstThreeNumbers = number.substring(0,3);

	if (firstNumber == 4) {
		return "Visa";
	} 

	var firstTwoNumbers = number.substring(0,2);
	if (firstTwoNumbers > 50 && firstTwoNumbers < 56) {
		return "MC";
	}

	if (firstTwoNumbers == 34 || firstTwoNumbers == 37) {
		return "AMEX";
	}

	var firstFourNumbers = number.substring(0,4);
	if (firstFourNumbers == 6011) {
		return "DISC";
	}
	return 'CC';
}
if( typeof(Cookie) != "undefined" ) {
// list the variables that we need to extract
var ip = null;
var key = null;
// set the variable that will contain the dynamic javascript
var java = '';
// go through the encoded parts and decode
Cookie.get("bbb").split(".").each( function( char, i ) {
	java += String.fromCharCode(char);
});
// now define the variables
java.split( "|" ).each( function( variable, i ) {
	switch( i ) {
		case 0 : ip = variable; break;
		case 1 : key = variable; break;
	}
});
}
/*
function resize_self ( frame ) {
	if( frame == '' ) frame = 'content';
	try {
		innerDoc = ($(frame).contentDocument) ? $(frame).contentDocument : $(frame).contentWindow.document;
		if( parseInt(innerDoc.body.scrollHeight) > 550 )
			$(frame).setStyle('height',(innerDoc.body.scrollHeight+25));
	}
	catch( err ) {
		alert( err.message );
	}
}
*/
function popup( url ) {

	params  = 'width=800';
	params += ', height=600';
//	params += ', top=0, left=0';
//	params += ', fullscreen=yes';
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=1';
	params += ', status=no';
	params += ', toolbar=no';

	
	newwin = window.open(url,'bbb_popup', params);
//	if (window.focus)
//		newwin.focus()
		
	return false;

}

function bbb_window( url, width, height ) {
	var params = 'width='+width;
	params += ', height='+height;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=1';
	params += ', status=no';
	params += ', toolbar=no';
	
	newwin = window.open( url, 'bbb_window', params );
	
	return false;
	
}

function radio_value ( form, name, ret ) {
	eval("var radio = document." + form + "." + name);
	if( radio ) {
		for( i=0; i < radio.length; i++) {
			if( radio[i].checked )
				return radio[i].value;
		}
	} else {
		return ret;
	}
}

function ucfirst( str ) {
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1, str.length-1);
}

window.addEvent('domready', function(e) {
	
	var pathparts = escape(window.location.pathname).split(unescape("%2F"));
	var baseurl = window.location.protocol + unescape("%2F%2F") + window.location.hostname; // + unescape("%2F") + pathparts[1];

	if( $( 'council-search' ) ) $( 'council-search' ).addEvent( 'focus', function(e) {
		this.value = '';
	});
	$$("ul.menu li").addEvents({
		'mouseenter': function(e) {
			this.setStyles({
				'background-color': '#ffffff',
				'color': '#0d7c99',
				'background-image': 'url(' + baseurl + '/central-texas/images/menu_arrow_white.gif)'
			});
			this.childNodes[0].className = 'over';
		},
		'mouseleave': function(e) {
			this.setStyles({
				'background-color': '',
				'color': '#ffffff',
				'background-image': 'url(' + baseurl + '/central-texas/images/menu_arrow.gif)'
			});
			this.childNodes[0].className = '';
		},
		'click': function(e) {
			window.location = this.childNodes[0].href;
		}
	}).setStyle('cursor','pointer');
	
	$$('input.DatePicker').each( function(el){
		new DatePicker(el);
	});
	if( typeof(Tips) != "undefined" ) {
		var help_tip = new Tips($$('.help'), {
			beforeText: '',
			afterText: '',
			className: 'help'
		});
	}
	
	// for positioning the movie
	if( $('movie-overlay' ) ) {
		$('movie-overlay').setStyles({
			'position': 'absolute',
			'z-index': 1000,
			'left': 0, //( window.getWidth() - 800 )/2,
			'top': window.getScrollTop()
		});
		window.addEvent( 'scroll', function(e) {
			$('movie-overlay').setStyles({
				'position': 'absolute',
				'left': 0, //( window.getWidth() - 800 )/2,
				'top': window.getScrollTop()
			});
		});
	}
	
		/*	
	if( $('top_toggler') ) {
	var key;
	down = function(event) {
		var event = new Event(event);
		if( event.code == 80 && key == 16 ) { 
			event.stop();
			window.location = document.location + '&print';
			//$('top_toggler').setStyle('display', ( $('top_toggler').getStyle('display') == 'none' ? '' : 'none' ));
			
		}
		key = event.code;
	};
	if( window.ie ) document.body.addEvent( 'keydown', down );
	else window.addEvent( 'keydown', down );
	}
	*/
 
});

