//  ON READY 
$(document).ready(function(){

	//  Tooltips.
	if( $('.tooltip') && $('.tooltip').tooltip ) {
		$('.tooltip').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			fade: 250
		});
	}
});

//  GET ELEMENTS OF A SPECIFIC CLASS
function getElementsByStyleClass( className ) {
	var all = document.all ? document.all :
		document.getElementsByTagName('*');
	var elements = new Array();
	for (var e = 0; e < all.length; e++)
		if (all[e].className == className)
	elements[elements.length] = all[e];
	return elements;
}

//  OPEN POPUP WINDOW
var popupList = {};
function openWindow( winName, url, w, h, scroll ) {

	//  Close other instances of this window.
	if ( popupList[winName] != null && typeof( popupList[winName] ) == "object" && !popupList[winName].closed ) {
		popupList[winName].close();
		popupList[winName] = null;
	}

	//  Setup the new window.
	popupList[winName] = window.open( url, winName, "height=" + h + ",width=" + w + ",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=" + scroll + ",status=1,toolbar=0","pop" );

	//  Open the window.
	if ( popupList[winName].opener == null ) {
		popupList[winName].opener = window;
	}
	if ( navigator.appName == 'Netscape' ) {
		popupList[winName].focus;
	}
}

//  NAV ON
function nav_on( el ) {
	if( !el ) { return; }
	el.style.backgroundImage = "url( '/images/nav_on.gif' )";
}

//  NAV OFF
function nav_off( el ) {
	if( !el ) { return; }
	el.style.backgroundImage = "url( '/images/nav_off.gif' )";
}

//  GET CITY/STATE FOR A ZIP CODE
function getZipDetails( zip ) {

	if( !( zip && zip.length == 5 ) ) {
		return;
	}

	var url = "/misc/ajax/zip.php?zip=" + encodeURIComponent( zip );

	var details = $.ajax({
		type: "GET",
		url: url,
		async: false
	}).responseText;

	if( details ) {
		return eval( "(" + details + ")" );
	}

	return;
}

//  CREATE A DIV FOR A JS FORM ERROR
function check_form_error( form, div_id, field_name, type ) {

	var error_cnt = $('#'+div_id);
	var field = $( form.elements[ field_name ] );
	var error_message_cnt = div_id + '-error_message';

	if( !( error_cnt && field ) ) {
		return;
	}

	var error_message = '';

	if( type == 'text' && !field.val().toString().match( /[a-zA-Z0-9]/ ) ) {
		error_message = 'Field Required';
	}

	if( !error_message ) {
		if( document.getElementById( error_message_cnt ) ) {
			$('#'+error_message_cnt).css( 'display', 'none' );
			$('#'+error_message_cnt).css( 'position', 'static' );
		}
		return true;
	}

	if( !document.getElementById( error_message_cnt ) ) {
		var newdiv = document.createElement('div');
		newdiv.id = error_message_cnt;
		newdiv.style.width = '168px';
		newdiv.style.height = '26px';
		newdiv.style.position = 'absolute';
		newdiv.style.left = '-178px';
		newdiv.style.top = '-5px';
		newdiv.style.padding = '10px 0px 0px 10px';

		newdiv.style.background = "url( '/images/error_js_holder.gif' )";
		newdiv.innerHTML = "Field Required";
		document.getElementById( div_id ).style.position = 'relative';
		document.getElementById( div_id ).appendChild( newdiv );
	} else {
		$('#'+error_message_cnt).css( 'display', 'block' );
	}

	return false;
}

SubmitCounter = 0;
function preventMultiSubmit()
{
	SubmitCounter++;
	if(SubmitCounter > 1) { return false; }
	return true;
}










/*
    $('#readyTest').corner();
    
    $(function(){
		$('#dynCorner').click(function() {
			$('#dynamic').corner();
		});
		$('#dynUncorner').click(function() {
			$('#dynamic').uncorner();
		});
	
        $('div.info_box_inner').wrap('<div class="info_box_outer"></div>');
        $('p').wrap("<code></code>");

        $('div.demo, div.info_box_inner').each(function() {
            var t = $('p', this).text();
            eval(t);
        });

        // fixed/fluid tests
        $("div.box, div.plain").corner();
        $("#abs").corner("cc:#08e");
		
		$('.myCorner').corner();
    });
*/
