

/* emg.js.php */
/*
12:25 PM 1/6/2011 - added tokenInit() and toggleClassArray()
3:38 PM 12/13/2010
2:04 PM 10/14/2010
3:52 PM 10/12/2010
/*
Copyright © 2008 Eckx Media Group, LLC. All rights reserved.
Eckx Media Group respects the intellectual property of others, and we ask our users to do the same.
*/
/*<script>*/

var emgInit = function(){
			BrowserDetect.init();				initValForm();			ie6Check();
	//emg link
	$('#emg-link').hide();
	
	if(window.siteInit){
		siteInit();
	}
	
	markupInit();
}; 

$(document).ready(emgInit);

//function to run initial function that changes markup
function markupInit(){
	var bodyElement = $('body')[0]; // cant use document.body because error in IE7, no .select
	confirmInit(bodyElement);
	externalLinks(bodyElement);
	autoCompleteOff(bodyElement);
	defaultClear(bodyElement);
	
	ieSelectExpand();
}

//Event.observe(window, 'load', emgInit);
//document.observe('dom:loaded', emgInit);

// Show / Hide object
function toggle(obj) {
	alert('Deprecated - use toggleClass with css');
	return;
	
	var el = $(obj);
	el.style.display = (el.style.display != 'block' ? 'block' : 'none' );
	el.blur();
}
function toggle2(obj) {
	alert('Deprecated - use toggleClass with css');
	return;
	
	var el = $(obj);
	el.style.display = (el.style.display != 'block' ? 'block' : 'none' );
	el.blur();
}

function toggleClass(id, className) {
	$('#' + id).toggleClass(className);
	/*
	var el = $(id);
	if (el.hasClassName(className)) {
		el.removeClassName(className);
	}
	else {
		el.addClassName(className);
	}*/
}

function toggleClassArray(ids, className){
	for(var i = 0; i < ids.length; i++){
		toggleClass(ids[i], className);	
	}
}

// Reset form fields
function clearForm(id, skipids) {
	if(!skipids){
		skipids = new Array();
	}
	var form = byId(id);
	for (var i = 0; i < form.length; i++) {
		if(inArray(form[i].id, skipids) || form[i].type == 'submit' || form[i].type == 'button' ){
			continue;
		}
		if(form[i].type == 'checkbox' || form[i].type == 'radio') {
			form[i].checked = false;	
		}
		if(form[i].options){ // drop downs
			form[i].selectedIndex = 0;
		}
		else {
			form[i].value = '';
		}
		
	}
}

// Reset form fieldset fields
function clearFieldset(id) {
	var fieldset = $('#' + id + ' input[type="text"], ' + '#' + id + ' input[type="password"], ' + '#' + id + ' input[type="file"], ' + '#' + id + ' select, ' + '#' + id + ' textarea');
	
	for (var i = 0; i < fieldset.length; i++) {
		clearField(fieldset[i]);
	}
}
// Clear individual field
function clearField (field) {
	if(field.type == 'checkbox' || field.type == 'radio') {
		field.checked = false;	
	}
	else {
		field.value = '';
	}
}

function popUpA(URL) { //allow all features
	day = new Date();
	id = "aboutUS";
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=900,height=400,left = 240,top = 212');");
}

function popUpB(URL) { // disable all features
	day = new Date();
	id = "aboutUS";
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300,left = 240,top = 212');");
}

function isset(obj){
	if(typeof obj == 'undefined'){
		return false;
	}
	else{
		return true;	
	}
}


function getMousePos(e) {
	var IE = document.all?true:false
	var scrollXY = getScrollXY();
	var mousePos = new Array();
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = e.x;
		tempY = e.y;
	} 
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.clientX;
		tempY = e.clientY;
	}
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  
	mousePos['x'] = tempX + scrollXY[0];
	mousePos['y'] = tempY + scrollXY[1];
	return mousePos;
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getPageDim(){
	/*if(document.all?true:false){ // IE
		if(document.body.clientHeight > document.body.scrollHeight){
			var height = document.body.clientHeight;
			var width = document.body.clientWidth;
		}
		else{
			var height = document.body.scrollHeight;
			var width = document.body.scrollWidth;
		}
	}
	else{
		var height = document.height;
		var width = document.weidth;
	}
	var viewPortHeight = document.viewport.height();
	if(height < viewPortHeight){
		height = viewPortHeight;
	}*/
	return [ $(document).width(), $(document).height() ];
}

function getVisibleDim(){ alert('function getVisibleDim() decremented, use prototype viewport');
	if(!$('getTopLeft-fake-body')){ //generate fake div to get screen size
		var fakeDiv = document.createElement('div');
		fakeDiv.id = 'getTopLeft-fake-body';
		fakeDiv.style.visibility = 'hidden';
		fakeDiv.style.margin = '0';
		fakeDiv.style.padding = '0';
		fakeDiv.style.position = 'absolute';
		fakeDiv.style.top = '0';
		fakeDiv.style.bottom = '0';
		fakeDiv.style.left = '0';
		fakeDiv.style.right = '0';
		fakeDiv.style.width = '100%';
		fakeDiv.style.height = '100%';
		fakeDiv.style.zIndex = '-1';
		document.body.appendChild(fakeDiv);
	}
	
	var fakeDiv = $('getTopLeft-fake-body');
	var width = fakeDiv.getWidth();
	var height = fakeDiv.height();
	return [ width, height ];
}


function alert2(text, dim, alertTime, className){ 
	//check if alert 2 already exist
	
	var i = 0;
	while(byId('alert2_' + i)){
		i++;
	}
	
	var alert2 = document.createElement('div');
	
	alert2.id = 'alert2_' + i;
	alert2.style.visibility = 'hidden';
	document.body.appendChild(alert2);
	
	alert2 = byId('alert2_' + i);
	if (className === undefined) {
		$(alert2).addClass('alert2');
	}
	else {
		$(alert2).addClass(className);	
	}
	
	alert2.innerHTML = text;
	
	if (dim) {
		width = dim[0];
		height = dim[1];
		alert2.style.width = width + 'px';
		alert2.style.height = height + 'px';
	}
	else {
		width = $(alert2).width();
		height = $(alert2).height();
	}
	
	if(isNaN(width) || isNaN(height)){
		alert('Alert2() error, width or height isNaN');	
	}
	
	var xy = getScrollXY();
	var topLeft = getTopLeft(width, height);
	alert2.style.top = topLeft[0]+'%';
	alert2.style.left = topLeft[1]+'%';
	alert2.style.visibility = 'visible';
	if (!alertTime) {
		alertTime = 2000;	
	}
	setTimeout("document.body.removeChild(document.getElementById('alert2_" + i + "'))", alertTime);
}


//return the top left percentage for an absolute centered layer, req 100% body height
function getTopLeft(width, height){
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var ie = getIEVerNum();
	
	//compensate for scroll
	var xy = getScrollXY();
	
	//get %
	var top = (windowHeight/2 + xy[1] - (height/2)) / windowHeight;
	var left = (windowWidth/2 + xy[0] - (width/2)) / windowWidth;

	if(top < 0){
		top = 0;	
	}
	if(left <0){
		left = 0;	
	}
	
	//compensate for ie 6 usage of %, the entire document not just what u see is 100%
	if(ie == 6){ // ie 6
		var pxHeight = windowHeight * top; //get pixel height
		top = pxHeight/document.body.clientHeight; // get decimal height
	}
	
	top  = Math.round(top * 100); 
	left  = Math.round(left * 100);
			
	return [ top, left ];
}

function money(num){
	var formated = Math.round(num*1000)/1000; //use 1000 for partial cents
	formated = formated.toString();
	if(formated.indexOf('.') == -1){
		formated += '.00';
	}
	else{
		var parts = formated.split('.');
		if(parts[1].length == 1){
			formated += '0';	
		}
	}
	return formated;
}

function urlencode(str) { alert('use encodeURIComponent()');
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function urldecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}

function htmlentities(html) {
	html = html.replace('<','&lt;');
	html = html.replace('>','&gt;');
	html = html.replace('"','&quot;');
	return html;
} 

function getJs(url){
	if(!inString(url, '?')){
		url += '?';	
	}
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url+'&klioe='+Math.random()*10000;
	document.body.appendChild(jsel);
}

//Get IE Version Number
function getIEVerNum() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

function confirm2(e, title, yesEval, noEval){
	var delConfirm = document.createElement('div');
	delConfirm.id = 'confirm2';
	document.body.appendChild(delConfirm);
	modal.load();
	modal.content('<p><strong>'+title+'</strong></p><ul class="tools confirm"><li class="yes"><span><a href="#" id="confirm2-yes">Yes</a></span></li><li class="no"><span><a href="#" id="confirm2-no">No</a></span></li></ul>');
	//delConfirm = $('confirm2');
	//delConfirm.addClassName('confirm2');
	//delConfirm.innerHTML = '<div>'+title+'</div><input type="button" id="confirm2_yes" value="Yes"/><br/><input type="button" id="confirm2_no" value="No" />';
	
	//var mousePos = getMousePos(e);
	//delConfirm.style.left=mousePos['x']+'px';
	//delConfirm.style.top=mousePos['y']+'px';
	$('#confirm2-yes')[0].onclick= function(){ 
		//document.body.removeChild($('confirm2'));
		eval(yesEval);
		modal.close();
		return false;
	}
	$('#confirm2-no')[0].onclick= function(){ 
		//document.body.removeChild($('confirm2'));
		eval(noEval); 
		modal.close();
		return false;
	}
}

function checkAll(name, trueFalse){
	var checkBoxes = document.getElementsByName(name);
	var len = checkBoxes.length;
	for(var i=0; i<len; i++){
		checkBoxes[i].checked = trueFalse;
	}
}

function confirmInit(container){
	var anchors = $('a[rel~="confirm"]', container);
	for(var i = 0; i < anchors.length; i++){
		anchors[i].href  = 'javascript:confirm2(null, \'' + anchors[i].title + '\', \'window.location=\\\'' + anchors[i].href + '\\\'\', \'\')';
	}
}

function externalLinks(container) {
	var anchors = $('a[rel~="external"]', container);
	
	for (var i=0; i<anchors.length; i++) {
		anchors[i].target = "_blank";
	}
}

function autoCompleteOff(container){
	var inputs = $('input[class~="autocomplete-off"]', container);
	for (var i=0; i<inputs.length; i++) {
		inputs[i].setAttribute("autocomplete", "off");
	}
}

function defaultClear(container){	
	var inputs = $('[class~="default-clear"]', container);
	
	var defaultClassName = 'default';
	
	
	inputs.focus(function() {
		if(this.value == this.defaultValue){
			this.value = '';
			$(this).removeClass(defaultClassName);
		}
	}).blur(function() {
		if(this.value == ''){
			this.value = this.defaultValue;
			$(this).addClass(defaultClassName);
		}
	});
}

function bookMark(url, title){
	if(document.all?true:false){ // IE
		window.external.AddFavorite(url, title);
	}
	else{
		window.sidebar.addPanel(title, url, '')
	}
}

function ajaxFill(url, containerid, callback){
	alert('depercated, please use EmgAjax.call()');
	return;
	var container = $(containerid);
	if(!container){
		alert('ajaxFill(): '+containerid+' id dosnt exist');
		return;
	}
	container.innerHTML = '<div style="text-align:center"><img src="'+window.CR+'/images/library/loading.gif" /></div>';
	new Ajax.Request(url, { method: 'get', onSuccess: function(ajaxReturn) {
		if(ajaxReturn.responseText == 'died'){
			window.location = window.CR + '/died';
			return;
		}
		container.innerHTML = ajaxReturn.responseText;
		curtain.initLinks(container); //curtain reference
		eval(callback);
	}}); 
}

function ie6Check() {
	if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) {
		var ie6Notice = document.createElement('div');
		ie6Notice.id = 'ie6-notice';
		ie6Notice.innerHTML = '<p class="title">It seems like you are using Internet Explorer 6 or lower.</p><p>IE6 is an outdated web browser that cannot provide the rich web experience that a modern web browser is able to.  This site may not display and function correctly as a result.</p><p>You may want to upgrade to one of these newer web browsers:</p><ul class="browsers"><li><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" title="Download Internet Explorer 8">Download Internet Explorer 8</a></li><li><a href="http://www.mozilla.com/en-US/firefox/" title="Download Mozilla Firefox">Download Mozilla Firefox</a></li><li><a href="http://www.google.com/chrome" title="Download Google Chrome">Download Google Chrome</a></li></ul><p class="hide-notice"><a href="#" onclick="document.getElementById(\'ie6-notice\').style.display = \'none\'; return false;" title="Hide this notice" rel="external">Hide this notice</a></p>';
		document.body.appendChild(ie6Notice);
	}
}

// verify the captcha
function verifyCaptcha(captchaFieldid){
	var url = window.CR + '/ajax/verify-captcha?area=' + captchaFieldid + '&captcha=' + $('#' + captchaFieldid)[0].value;
	var valFormIndex = getValFormIndex(captchaFieldid);
	valForms[valFormIndex].ajaxRunning[captchaFieldid] = true;

	$.ajax({
		   url: url
		   , type: 'get'
		   , dataType: 'text'
		   , cache: false
		   , complete: function(ajaxReturn) {
			   				var response = ajaxReturn.responseText;
							var error = response == '0' ? ' is incorrect.' : false;
							
							valForms[valFormIndex].errorHandler($('#' + captchaFieldid)[0], error);
							valForms[valFormIndex].ajaxRunning[captchaFieldid] = false;
						}
			});
	
}

function refreshCaptcha(formid) {
	var textInput = byId(formid + '-captcha');
	textInput.value = '';
	byId(formid + '-captcha-img').src = '/ajax/show-captcha?area=' + formid + '-captcha&amp;k=' + Math.random();
	textInput.focus();
}

function refreshImg(id){
	var img = byId(id);
	if(inString(img.src, '?')){
		img.src = img.src + '&k='+Math.random();
	}
	else{
		img.src = img.src + '?k='+Math.random();
	}
}

function showFlash(src, w, h, container, parameters, variables){
	alert('decremented, use swfobject.embedSWF(window.CR + \'/swf/player.swf\', containerid, w, h, \'9.0.0\', \'expressInstall.swf\', variables, parameters);'); return;
	var s1 = new SWFObject(src, 'mediaplayer', w, h,'7');
	if(parameters){
		parameters = parameters.split('&');
		for(var i = 0; i < parameters.length; i++){
			var parts = parameters[i].split('=');
			s1.addParam(parts[0], parts[1]);
		}
	}
	if(variables){
		s1.addParam('flashvars', variables);
	} 
	if(!s1.write(container)){
		$(container).innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Click here to get the flash player.</a>';
	}
}

//controlbar: over, under
function showPlayer(flv, w, h, containerid, preview, skin, controlbar){
	var parameters = {};
	parameters.allowfullscreen = true;
	parameters.allowscriptaccess = 'always';
	parameters.wmode = 'opaque';
	
	var variables = {file: flv};
	if(preview){
		variables.image = preview;
	}
	if(skin){
		variables.skin = skin;
	}
	if(controlbar){
		variables.controlbar = controlbar;
	}
	swfobject.embedSWF(window.CR + '/swf/player.swf', containerid, w, h, '9.0.0', 'expressInstall.swf', variables, parameters);
}

// skin: (default) | bekle
// controlbar: bottom (default) | top | over | none
// autostart: false (default) | true
// stretching: uniform (default) | fill | exactfit | none
// volume: (integer)
// mute: false (default) | true
function showVideo(flv, w, h, containerid, image, skin, controlbar, autostart, stretching, volume, mute) {
	var parameters = {};
	// Standard parameters
	parameters.allowfullscreen = true;
	parameters.allowscriptaccess = 'always';
	parameters.wmode = 'opaque';
	
	// Flash variables
	var variables = {file: flv};
	if (image !== undefined){
		variables.image = window.CR + '/images/video-previews/' + image;
	}
	if (skin !== undefined){
		variables.skin = window.CR + '/swf/skins/' + skin + '/overlay.swf';
	}
	variables.controlbar = controlbar === undefined ? 'bottom' : controlbar;
	variables.autostart = autostart === undefined ? 'false' : autostart;
	variables.stretching = stretching === undefined ? 'uniform' : stretching;
	variables.volume = volume === undefined ? 100 : volume;
	variables.mute = mute === undefined ? 'false' : mute;
	
	swfobject.embedSWF(window.CR + '/swf/player.swf', containerid, w, h, '9.0.0', 'expressInstall.swf', variables, parameters);
}


function textAreaExp(id){
	var label = $('label[for="' + id + '"]');
	var header = '';
	if(label){
		header = '<h3>' + label[0].innerHTML + '</h3>';
	}

	var html = '<div class="emg-form">' + header + '<textarea rows="25" cols="100" id="' + id + '-expanded" class="fluid">' + $('#' + id)[0].value + '</textarea><br /><button onclick="$(\'#' + id + '\')[0].value = $(\'#' + id + '-expanded\')[0].value; modal.close();">Finish</button></div>';
	modal.load();
	modal.content(html);
}

//use to show all the properties of an object;
function alerto(obj, hideValues){
	var output = '';
	for (var prop in obj ) {
		output += 'object.' + prop;
		if(hideValues != true){
			output += ' = ' + obj[prop] 
		}
		output += "\n";
	}
	alert(output);
}


function checkedToStr(inputName){
	var checkboxes = document.getElementsByName(inputName);
	var values = new Array();
	for(var i=0; i<checkboxes.length; i++){
		if(checkboxes[i].checked){
			values[values.length] = checkboxes[i].value;
		}
	}
	return values.join('-');
}

function moneyFormat(value, nosymbol, cents) {
	if (isNaN(value)) {
		var formatted = '0.00';
	}
	else {
		//var formatted = Math.round(value*100)/100;
		var formatted = Math.round(value*1000)/1000; //use 1000 for partial cents
		formatted = formatted.toString();
		
		if (formatted.indexOf('.') == -1) {
			formatted += '.00';
		}
		else {
			var parts = formatted.split('.');
			if (parts[1].length == 1) {
				formatted += '0';
			}
		}
		// Thousands commas
		if (formatted.length >= 7) {
			var parts = formatted.split('.');
			var integer = parts[0];
			var rgx = /(\d+)(\d{3})/;
			while (rgx.test(integer)) {
				integer = integer.replace(rgx, '$1' + ',' + '$2');
			}
			formatted = integer + '.' + parts[1];
		}
	}
	if(!nosymbol && !cents){
		formatted = '$' + formatted;
	}
	// Cent symbol
	else if (cents && formatted < 1) {
		return formatted * 100 + '\u00a2';
	}
	return formatted;
}

function emailInUse(emailFieldid){
	checkExist('email', emailFieldid, false);
}

function emailNotExist(emailFieldid){
	checkExist('email', emailFieldid, true);
}

function zipExist(zipFieldid){
	checkExist('zip', zipFieldid, true);
}

function checkExist(field, fieldid, valExists){
	var url = window.CR + '/ajax/check-exist/' + field + '?check-value=' + $('#' + fieldid)[0].value;
	var valFormIndex = getValFormIndex(fieldid);
	valForms[valFormIndex].ajaxRunning[fieldid] = true;
	$.ajax({
		   url: url
		   , type: 'get'
		   , dataType: 'text'
		   , cache: false
		   , complete: function(ajaxReturn) {
						   	if (ajaxReturn.status == '404') { // page not found
								window.location = window.CR + '/error';
								return;
							}
							
			   				var response = ajaxReturn.responseText;
							
							if(valExists){  // for reset password form
								var error = response == '0' ? ' does not exist.' : false;
							}
							else{
								var error = response == '1' ? ' already in use.' : false;
							}
							
							valForms[valFormIndex].errorHandler($('#' + fieldid)[0], error);
							valForms[valFormIndex].ajaxRunning[fieldid] = false;
						}
		   });
}

// Scrolls to hash instead of instant jump
// Also doesn't append hash to current url
// Requires jquery
// Usage: enableHashScroll('a');
// Usage: enableHashScroll(['a', '.nav a]], 1, 16);
function enableHashScroll(anchorSelectors, duration, offset) {
	// Set default duration to 1 second
	duration = isNaN(duration) ? 1000 : duration * 1000;
	offset = isNaN(offset) ? 0 : offset;
	if (!isArray(anchorSelectors)) {
		anchorSelectors = [anchorSelectors];
	}
	
	// For each group of anchor selectors
	$(anchorSelectors).each(function() {
		anchorSelector = $(this).get();
		anchorSelector = anchorSelector === undefined ? 'a' : anchorSelector;
		
		// Anchor events
		$(anchorSelector + '[href^="#"]').click(function() {
			this.blur();
			$('html, body').animate({scrollTop: $(this.hash).offset().top - offset}, duration);
			return false;
		});
	});
}

// Get hash value from url
function getHash(href) {
	return href.split(/#/)[1];
}

// Get document height, or viewport if body height is less
function getDocHeight() {
	return Math.max(
		Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
		Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
		Math.max(document.body.clientHeight, document.documentElement.clientHeight)
	);
}

// IE select expand
// Usage: ieSelectExpand('select.ie-expand')
function ieSelectExpand(selectSelector) {
	if (selectSelector === undefined) {
		selectSelector = 'select.ie-expand';
	}
	if ($.browser.msie) {
		$(selectSelector).bind('mouseover focus', function() {
			$(this).addClass('expanded').removeClass('clicked');
		}).bind('click', function() {
			$(this).toggleClass('clicked');
		}).bind('mouseout', function() {
			if (!$(this).hasClass('clicked')) {
				$(this).removeClass('expanded');
			}
		}).bind('blur', function() {
			$(this).removeClass('expanded clicked');
		});
	}
}

// Set/append return false
function setOnclickFalse(el, replaceOnclick) {
	if (replaceOnclick == true) {
		el.setAttribute('onclick', 'return false;');
	}
	else {
		var originalOnclick = el.onclick;
		el.onclick = (function(e) {
			if (originalOnclick) {
				originalOnclick();
			}
			return false;
		});
	}
}

// Trim
if (typeof(String.prototype.trim) === "undefined") {
	String.prototype.trim = function() {
		return String(this).replace(/^\s+|\s+$/g, '');
	};
}

//use to concat token to action requests
//function is useful when using ajax to login
//currently being used in checkout.js
function tokenInit(){
	var url = window.CR + '/ajax/account/token';
	var callBackComplete = function(ajaxReturn) {				
		if(!inString(ajaxReturn.responseText, 'lv2-token=')){ //token not available, something could be wrong
			return;
		}
		//handle forms
		var forms = $('form');
		for(var i = 0; i < forms.length; i++){
			if(inString(forms[i].action, 'lv2-token=')){ //already has token, potential bugs with user logging in n out with differnt accounts
				continue;	
			}
			if(inString(forms[i].action, window.CR + '/action')){ //if request is an action page
				if(inString(forms[i].action, '?')){
					forms[i].action += '&' + ajaxReturn.responseText;
				}
				else{
					forms[i].action += '?' + ajaxReturn.responseText;
				}
			}
		}
		
		//handle anchors
		var anchors = $('a');
		for(var i = 0; i < anchors.length; i++){
			if(inString(anchors[i].href, 'lv2-token=')){ //already has token, potential bugs with user logging in n out with differnt accounts
				continue;	
			}
			if(inString(anchors[i].href, window.CR + '/action')){ //if request is an action page
				if(inString(anchors[i].href, '?')){
					anchors[i].href += '&' + ajaxReturn.responseText;
				}
				else{
					anchors[i].href += '?' + ajaxReturn.responseText;
				}
			}
		}
	};
	//use ajax to grab token
	$.ajax({url: url, complete: callBackComplete});
}

function isArray(o) {
	return Object.prototype.toString.call(o) === '[object Array]';
}

function inString(haystack, needle){
	if(isArray(haystack)){
		alert('use inArray() for ' + needle);
		return false;
	}
	var index = haystack.indexOf(needle);
	
	if (index != -1) {
		return true;	
	}
	
	return false;	
}

function inArray(needle, haystack){
	var index = $.inArray(needle, haystack);
	
	if (index != -1) {
		return true;	
	}
	
	return false;
}

function byId(id){
	return document.getElementById(id);
}

// The .bind method from Prototype.js 
if (!Function.prototype.bind) { // check if native implementation available
  Function.prototype.bind = function(){ 
    var fn = this, args = Array.prototype.slice.call(arguments),
        object = args.shift(); 
    return function(){ 
      return fn.apply(object, 
        args.concat(Array.prototype.slice.call(arguments))); 
    }; 
  };
}

// Scrollbar Width
function getScrollBarWidth() {  
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";
	
	var outer = document.createElement('div');
	outer.style.position = "absolute";
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);
	
	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;
	
	document.body.removeChild (outer);
	
	return (w1 - w2);
};

function youtubeEmbed(selector, url, w, h, autoplay){
	//get video id
	var parts = url.split('?');
	var variables = parts[1].split('&');
	for(var i = 0; i < variables.length; i++){
		var variableParts = variables[i].split('=');
		if(variableParts[0] == 'v'){
			var id = variableParts[1];
		}
	}
	
	if(id == null){
		return;	
	}
	
	if(autoplay == null || !autoplay){
		autoplay = '0';
	}
	else if(autoplay){
		autoplay = '1';	
	}
	
	var html = '<object width="' + w + '" height="' + h + '">';
	html += '<param name="movie" value="http://www.youtube.com/v/' + id + '?fs=1&amp;hl=en_US&autoplay=' + autoplay + '"></param>';
	html += '<param name="allowFullScreen" value="true"></param>';
	html += '<param name="allowscriptaccess" value="always"></param>';
	html += '<param name="wmode" value="opaque"></param>';
	html += '<embed src="http://www.youtube.com/v/' + id + '?fs=1&amp;hl=en_US&autoplay=' + autoplay + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="' + w + '" height="' + h + '"></embed>';
	html += '</object>';

	$(selector)[0].innerHTML = html;
}

/* browser-detect.js.php */
/*<script>*/
// Browser name:	BrowserDetect.browser
// Browser version:	BrowserDetect.version
// OS name:			BrowserDetect.OS
/* July 16 09 */ 
/*
Copyright Â© 2008 Eckx Media Group, LLC. All rights reserved.
Eckx Media Group respects the intellectual property of others, and we ask our users to do the same.
*/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.userAgent,
			subString: "iPhone",
			identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

/* functions.js.php */
/*<script>*/
function siteInit() {
	var slideshow = new Slideshow({navClass: '#slideshow ul.nav'
								, slidesClass: '#slideshow ul.slides'
								, autoplay: true
								, slideDuration: 5
								, transition: 'fade'
								, transitionDuration: 0.5
								});
								
	var gallery = new Slideshow({previousNextNavClass: '.slider ul.previous-next-nav'
								, navClass: '.slider ul.nav'
								, slidesClass: '.slider ul.slides'
								, autoplay: true
								, slideDuration: 5
								, transition: 'scroll'
								, transitionDuration: 0.5
								});

	giftCertificateEvents();
}

function giftCertificateEvents() {
	var count = 2;
	$('#gift-certificate-form p.add a').click(function() {
		this.blur();
		
		var lastLi = $('ul.gift-certificates li:last-child');
		var newLi = lastLi.clone();
		
		// Update ids
		$(newLi).children().each(function() {
			if (this.id) {
				count++;
				var parts = this.id.split('-');
				parts[parts.length - 1] = count;
				this.id = parts.join('-');
			}
		});
		
		$(lastLi).after(newLi);
		
		return false;
	});
	
	$('#gift-certificate-form p.remove a').live('click', function() {
		$(this).closest('li').remove();
		
		return false;
	});
}

/* slideshow-v4.js.php */
/*<script>*/
// Requires jquery
// Usage:
/* var slideshow = new Slideshow({previousNextNavClass: '#slideshow ul.previous-next-nav'
								, navClass: '#slideshow ul.nav'
								, slidesClass: '#slideshow ul.slides'
								, autoplay: true
								, slideDuration: 5
								, transition: 'scroll'
								, transitionDuration: 0.5
								//, replaceOnlick = false
								});
*/
function Slideshow(args) {
	// Constructor
	this.construct = function(args) {
		// Required Parameters
		this.previousNextNavClass = args.previousNextNavClass;
		this.navClass = args.navClass;
		this.slidesClass = args.slidesClass;
		// Optional parameters (set default values in 'else' condition)
		this.autoplay = args.autoplay == true ? true : false;
		this.slideDuration = args.slideDuration > 0 ? args.slideDuration : 4;
		this.transition = args.transition;
		this.transitionDuration = args.transitionDuration > 0 ? args.transitionDuration : 1;
		
		// Navs & Slides
		this.previousNextNavs = $(this.previousNextNavClass + ' > li');
		this.navs = $(this.navClass + ' > li');
		this.slides = $(this.slidesClass + ' > li');
		this.count = this.slides.length;
		// Need slides container for 'scroll'
		this.slidesContainer = $(this.slidesClass)[0];
		
		this.scrollAmount = $(this.slidesClass + ' > li:first-child').width();
		
		this.current = 1;
		this.currentClass = 'current';
		this.currentPreviousClass = 'current-previous';
		this.previousClass = 'previous';
		this.nextClass = 'next';
		
		// Tabbed class for classname handling
		this.tabbed = false;
		
		// Return if elements don't exist
		if (this.slides.length < 1 || (this.navs.length + this.previousNextNavs.length < 1)) {
			return;
		}
		// Create Tabbed instance
		else {
			this.tabbed = new Tabbed({navClass: this.navClass});
		}
		
		// Set slides container width for scroll transition
		if (this.transition == 'scroll') {
			$(this.slidesContainer).width($(this.slides[0]).width() * $(this.slides).length);
		}
		
		this.setEvents();
		
		setTimeout((function() {
			this.play();
		}).bind(this), this.slideDuration * 1000);
	}
	
	// Event handlers
	this.setEvents = function() {
		// Stop autoplay if list item is clicked on
		this.slides.click((function() {
			this.stop();
		}).bind(this));
		
		// Swap events
		$(this.navClass + ' > li > a').each((function(i, el) {
			// Click event
			$(el).click((function() {
				this.swap(el.hash);
				return false;
			}).bind(this, el))
		}).bind(this));
		
		// Previous / Next links
		$(this.previousNextNavClass + ' > li > a').each((function(i, el) {
			$(el).click((function() {
				if ($(el).parent().hasClass(this.previousClass)) {
					this.previous(false);
				}
				else if ($(el).parent().hasClass(this.nextClass)) {
					this.next(false);
				}
				return false;
			}).bind(this, el))
		}).bind(this));
	}
	
	// Autoplay
	this.play = function() {
		if (!this.autoplay) {
			return;
		}
		
		// Go to next slide
		this.next(true);
		
		// Continue autoplay
		setTimeout((function() {
			this.play();
		}).bind(this), (this.slideDuration + this.transitionDuration) * 1000);
	}
	
	// Swap target slide with current
	this.swap = function(target, autoplay) {
		if (!autoplay) {
			this.stop();
		}
		
		// Target slide <li> element
		var targetSlide = $(target);
		var currentSlide = $(this.slides[this.current - 1]);
		
		// Do nothing if swap target is current
		var newCurrent = $(this.slides).index(targetSlide) + 1;
		if (this.current ==  newCurrent) {
			return;
		}
		
		// Fade
		if (this.transition == 'fade') {
			// Fade out
			// Add currentPreviousClass so we can fade out from the current slide			
			$(currentSlide).addClass(this.currentPreviousClass);
			$(currentSlide).fadeOut(this.transitionDuration * 1000);
			
			// Fade in			
			$(targetSlide).hide();
			$(targetSlide).fadeIn(this.transitionDuration * 1000, (function() {
				$(this.slides).removeClass(this.currentPreviousClass);
			}).bind(this));
		}
		// Scroll
		else if (this.transition == 'scroll') {
			var displacement = -(this.scrollAmount) * (newCurrent - 1);
			$(this.slidesContainer).animate({marginLeft: displacement}, this.transitionDuration * 1000, 'swing');
		}
		
		// Set new current
		this.current = newCurrent;
	}
	
	// Go to previous slide
	this.previous = function(autoplay) {
		this.traverse(false, autoplay);
	}
	// Go to next slide
	this.next = function(autoplay) {
		this.traverse(true, autoplay);
	}
	
	// Traverse (Previous/Next) slides
	// previous: direction = 0
	// next: direction = 1
	this.traverse = function(direction, autoplay) {
		// Default autoplay is false
		autoplay = autoplay == true ? true : false;
		
		// Default direction is true (next)
		var targetAnchorIndex = 0;
		if (direction == false) {
			targetAnchorIndex = (this.current == 1) ? this.count - 1 : this.current - 2;
		}
		else {
			targetAnchorIndex = (this.current == this.count) ? 0 : this.current;
		}
		// Swap
		var targetAnchor = $(this.navClass + ' > li > a')[targetAnchorIndex];
		
		this.tabbed.setCurrents(targetAnchor);
		this.swap(targetAnchor.hash, autoplay);
	}
	
	// Stop autoplay
	this.stop = function() {
		if (this.autoplay) {
			this.autoplay = false;
		}
	}
	
	this.construct(args);
}


/* tabbed-v2.js.php */
/*<script>*/
// Requires jquery
// Usage:
/* var tabbed = new Tabbed({navClass: '.tabbed-content ul.nav'
							, currentItem: 1
							//, currentClass: 'current'
							//, tabbedClass: 'tabbed'
							//, toggle: true // for to
							});
*/
function Tabbed(args) {
	// Constructor
	this.construct = function(args) {
		// Required Parameters
		this.navClass = args.navClass;
		// Optional Parameters
		this.toggle = args.toggle == true ? true : false;
		this.currentItem = args.currentItem > 0 ? args.currentItem : (this.toggle ? 0 : 1);
		this.currentClass = args.currentClass !== undefined ? args.currentClass : 'current';
		this.tabbedClass = args.tabbedClass !== undefined ? args.tabbedClass : 'tabbed';
	
		this.currentNav = false;
		this.currentContent = false;
		
		// Use parent <li>s when applicable
		this.navs = $(this.navClass + ' > li');
		// Don't force anchors to be within <li>
		this.navAnchors = $(this.navClass + ' a[href*="#"]:not([href$="#"])');
		this.contents = [];
		
		// Get content containers based on anchor hashes
		var contentIds = [];
		$(this.navAnchors).each(function() {
			if (this.hash) {
				contentIds.push(this.hash);
			}
		});
		this.contents = $(contentIds.join(', '));
		
		// Return if contents don't exist
		if (this.contents.length < 1) {
			return;
		}
		
		// Append tabbed class to hide
		$([this.navs, this.navAnchors, this.contents]).each((function(i, el) {
			$(el).addClass(this.tabbedClass);
		}).bind(this));
		
		// Set current class to currentItem's nav & content
		$(this.navAnchors).each((function(i, el) {
			if (i + 1 == this.currentItem) {
				this.setCurrents(el);
			}
		}).bind(this));
		
		this.setEvents();
	}
	
	// Set click events on anchors
	this.setEvents = function() {
		var thisClass = this;
		$(this.navAnchors).click(function() {
			this.blur();
				
			// Clear 'current' class from navs and contents
			// Set current nav and content
			// Apply 'current' class
			thisClass.setCurrents(this);
			return false;
		});
	};
	
	// Remove 'current' class name from navs and contents
	this.clearCurrents = function() {
		$([this.navs, this.navAnchors, this.contents]).each((function(i, el) {
			$(el).removeClass(this.currentClass);
		}).bind(this));
	};
	
	// Add 'current' class name on current nav and content
	this.setCurrents = function(targetAnchor) {
		var target = targetAnchor.hash;
		if (!this.toggle) {
			this.clearCurrents();
		}
		
		// Set current on <li> (parent) nav, <a>, and content
		this.currentNav = $(targetAnchor).parent();
		this.currentContent = $(target);
		$([this.currentNav, targetAnchor, this.currentContent]).each((function(i, el) {
			if (!this.toggle) {
				$(el).addClass(this.currentClass);
			}
			else {
				$(el).toggleClass(this.currentClass);
			}
		}).bind(this));
	}
	
	this.construct(args);
}


/* valform-v2.js.php */
/* 9:32 AM 02/08/2011 */
/*
Copyright Â© 2008 Eckx Media Group, LLC. All rights reserved.
Eckx Media Group respects the intellectual property of others, and we ask our users to do the same.
*/
/*<script>*/
/*
PACK:
	replace JS Variables: formClasses submitBtns waitFlag errorStr locate errorField labelFor focusThisFlag validNodes args colonPos
	after pack, need to replace $Vxxxxxx with $w or $A
*/
/*key words

class names
val-form
alert-errors
hide-errors
dont-disable
auto-focus-on

validators
==========
val_req
val_checked (int)(checkboxes only)
val_checked_min (int) (checkboxes only)
val_checked_max (int) (checkboxes only)
val_min(int)
val_max(int)
val_maxNum(int)
val_minNum(int)
val_alpha
val_alpha_num
val_alpha_space
val_alpha_num_space
val_num
val_int
val_email
val_len
val_same(input id)
val_notSame(input id); // id of input(hidden) containing ids of fields to check
val_url
val_ajax(function)
val_func(function)
val_date
val_datetime
val_phone
val_ceil
val_exist
val_not_exist
key words
=========
val_combo(input id): combine multiple elements to a single output error base on input id, elements should have a single name to allow access to lable name
	usage: label for should match with first input id, val_comboe (id of last input)
	ie:
		<label for="register-birthdate-month">Birthdate:</label>
		<select id="register-birthdate-month" name="dob[]" class="month val_req val_combo register-birthdate-year"></select>
		<select id="register-birthdate-day" name="dob[]" class="day val_req val_combo register-birthdate-year"></select>
		<select id="register-birthdate-year" name="dob[]" class="year val_req val_combo register-birthdate-year"></select>
		
val_money: turn into money format
val_errorAfter(element id): errors would be displayed after a html element
val_skipifis(input id): ignore validations if the value is the same as the provided input 
*/

/* bugs
	- error appears then disappears, try placing val_ajax check at the end.


*/
var valForms = new Array(); //global scope
function initValForm(container){
	//getting new forms to initialize valform
	if(container){
		var forms = $('form[class*="val-form"]', container[0]);
	}
	else{
		var forms = $('form[class*="val-form"]');
	};
	
	//adding the valform object to a global list
	for(var i = forms.length; i > 0; i--){
		//check if formid already exist
		var existFlag = false;
		for(var j = 0; j < valForms.length; j++){
			if(valForms[j].form.id == forms[i - 1].id){
				//form id already exist, need to reset event observation and stuff
				valForms[j].reset();
				valForms[j].init(forms[i - 1]);
				existFlag = true;
			}
		}
		if(!existFlag){
			var nextIndex = valForms.length;
			valForms[nextIndex] = new Valform();
			valForms[nextIndex].init(forms[i - 1]);
		}
	}
}

function valFormsResetSubmit(){
	for(var i = 0; i < valForms.length; i++){
		valForms[i].resetSubmit();
	}	
}

function getValFormIndex(nodeid){ // gets valform index based of form id or an input id
	for(var valFormIndex = 0; valFormIndex < valForms.length; valFormIndex++){
		if(valForms[valFormIndex].form.id == nodeid){
			return valFormIndex;
		}
		
		for(var i = 0; i < valForms[valFormIndex].inputs.length; i++){
			if(valForms[valFormIndex].inputs[i].id == nodeid){
				return valFormIndex;
			}
		}
	}
	alert('valform index not found');
}

function Valform() { 
	//config
	this.errorClass = 'val-error';
	this.errorContainerTag = 'div';
	this.errorContainerClass = 'val_error';
	//!config
	
	//all validator and key words
	this.classList = new Array('val_req', 'val_min', 'val_max', 'val_maxNum', 'val_minNum', 'val_alpha', 'val_alpha_num', 'val_alpha_num_sym', 'val_alpha_space', 'val_alpha_num_space', 'val_num', 'val_int', 'val_email', 'val_len', 'val_same', 'val_notSame', 'val_url', 'val_ajax', 'val_money', 'val_func',  'val_checked', 'val_checked_min', 'val_checked_max', 'val_date', 'val_datetime', 'val_phone', 'val_ceil', 'val_exist', 'val_not_exist');
	//key words that are dependent on next class
	this.dependents = new Array('val_len', 'val_min', 'val_max', 'val_maxNum', 'val_minNum', 'val_same', 'val_notSame', 'val_ajax', 'val_func', 'val_checked', 'val_checked_min', 'val_checked_max', 'val_ceil', 'val_exist', 'val_not_exist');
	this.ajaxClasses = new Array('val_ajax', 'val_exist', 'val_not_exist');
	this.failed = true; // flag for submitting
	this.form = null;	// form obj
	this.formObsFunc = null; //holds event observer function to stop observing
	
	this.submitBtn = null; //button object for submitting form
	this.submitBtnDefaultVal = null; //to toggle between please wait...
	this.ajaxRunning = new Object(); //flag to signal if ajax check is running
	this.alertErrorsFlag = false; //flag to alert errors when submitting
	this.containerErrorsFlag = false; //flag to show errors in a container when submitting
	this.hideErrorsFlag = false; // flag to not display errors next to field
	this.errors = new Object();
	this.errorFocusedFlag = false; //flag to focus on first error field only when submitting
	this.inputs = new Array(); //holds all the form inputs that will be validated
	
	this.originalSubmit = null; //the onsubmit of the form before its overwritten, will run before valform submits
	//arg[0]: form id, arg[1]: options
	//options: ae - alert errors on submit, he = dont display errors next to field
	this.init = function(form){
		
		if(!form){
			alert('Valform.init(), form object dosnt exist');
			return false;
		}
		
		this.form = form;
		
		//handle options
		if($(form).hasClass('alert-errors')){
			this.alertErrorsFlag = true;
		}
		if($(form).hasClass('container-errors')){
			this.containerErrorsFlag = true;
		}
		if($(form).hasClass('hide-errors')){
			this.hideErrorsFlag = true;
		}
		
		//get submit btn
		var submitBtns = $('input[type="submit"]', this.form);
		
		if(submitBtns.length == 0){
			alert('valForm init error: no submit button');	
		}
		else{
			this.submitBtn = submitBtns[0];
			this.submitBtnDefaultVal = this.submitBtn.defaultValue;
			this.resetSubmit();
		}
		
		//get inputs from form elements
		var validNodes = new Array('INPUT', 'TEXTAREA', 'SELECT');
		for(var i = 0; i < this.form.elements.length; i++){
			/* does not work in ie
			if(this.form.elements[i].disabled || validNodes.indexOf(this.form.elements[i].nodeName) == -1){ //no point of checking if disabled or if not valid tag;
			*/
			if(this.form.elements[i].disabled || !inArray(this.form.elements[i].nodeName, validNodes)){ //no point of checking if disabled or if not valid tag;
				continue;	
			}
			this.inputs[this.inputs.length] = this.form.elements[i];
		}
		
		//set event for inputs
		var focusThisFlag = true;
		if($(form).hasClass('auto-focus-on')){
			focusThisFlag = false;
		}
		for(var i = 0; i < this.inputs.length; i++){
			var inputType = this.inputs[i].type.toLowerCase();
			//determine which field to focus first
			if(!focusThisFlag && this.inputs[i].name && inputType != 'hidden'){
				focusThisFlag = true;
				if(inputType != 'radio' && inputType != 'checkbox'){ //radio & checkbox causes blur event to occurw when selecting options
					this.inputs[i].focus();
				}
			}
			
			//setting up events
			$(this.inputs[i]).bind('blur', {parent:this}, this.fieldCheck);
			
			//get all ajax check and initialize the running flag
			for (var j = 0; j < this.ajaxClasses.length; j++) {
				if ($(this.inputs[i]).hasClass(this.ajaxClasses[j])) {
					this.ajaxRunning[this.inputs[i].id] = false;
				}
			}
		}
		
		//set submit event
		this.originalSubmit = this.form.onsubmit; //save original onsubmit function
		this.form.onsubmit = null; // remove it
		this.formObsFunc = 1;
		$(this.form).bind('submit', {parent:this}, this.submitCheck);
	};
	
	this.reset = function(){
		//reset member variables
		this.failed = true;
		this.ajaxRunning = new Object();
		
		if(this.inputs){ // unset event observation
			for(var i = 0; i < this.inputs.length; i++){
				$(this.inputs[i]).unbind('blur', {parent:this}, this.fieldCheck); //stop input obs
			}
		}
		this.inputs = new Array();
		
		if(this.formObsFunc){
			$(this.form).unbind('submit', {parent:this}, this.submitCheck); //stop submit obs
		}
	};

	this.submitCheck = function(event){
		var parent = event.data.parent; //because out of scope because function is called on event
		
		parent.errorFocusedFlag = false; //not focused on any errors yet
		if(!$(parent.form).hasClass('dont-disable')){
			parent.submitBtn.disabled = true; //prevent double click
		}
		parent.submitBtn.value = 'Loading...';
		parent.errors = new Object(); // clean error list
		
		parent.failed = false;
		for(var fieldID in this.ajaxRunning){
			this.ajaxRunning[fieldID] = true;	
		}
		
		for(var i = 0; i < parent.inputs.length; i++){
			parent.fieldCheckSubmit(parent.inputs[i]);
			if(parent.errors[parent.inputs[i].id] && !parent.errorFocusedFlag){ // focusing on error input
				parent.inputs[i].focus();
				parent.errorFocusedFlag = true;
			}
		}
		
		parent.submitAjaxChk();
		//setTimeout('parent.submitAjaxChk()', 1); //causing error in ie, not sure why the setTimeout is needed.
		
		event.preventDefault();
		event.stopPropagation();
		return false;
		
	};
	

	//make sure ajax function is complete
	this.submitAjaxChk = function(){ 
	
		var waitFlag = false;
		for(var fieldID in this.ajaxRunning){
			if(this.ajaxRunning[fieldID]){
				waitFlag = true;
			}
			else{
				if(this.errors[fieldID] && !this.errorFocusedFlag){ // focusing on error fields
					$('#' + fieldID)[0].focus();
					this.errorFocusedFlag = true;
				}
			}
		}
		if(waitFlag){
			var valFormIndex = getValFormIndex(this.form.id);
			setTimeout('valForms[' + valFormIndex + '].submitAjaxChk()', 100);
		}
		else if(!this.failed){
			var tosubmit = true;  //alert(this.originalSubmit);
			if(this.originalSubmit){
				tosubmit = this.originalSubmit.call(this.form);
			}
			if(tosubmit == 'dont reset'){ //special case where originalSubmit is submitting the form
				//nothing
			}
			else if(tosubmit){
				this.form.submit();
			}
			else{ //may cause problems but need it for curtain
				this.resetSubmit();
			}
		}
		else { //failed
			if (this.alertErrorsFlag) {
				var errorStr = '';
				for (var fieldID in this.errors) {
					errorStr += this.errors[fieldID] + "\n";
				}
				
				alert(errorStr);
			}
			
			if (this.containerErrorsFlag && byId(this.form.id + '-errors-cont') != null) {
				var errorStr = '<ul class="' + this.errorContainerClass + '">';
				for (var fieldID in this.errors) {
					errorStr += '<li>' + this.errors[fieldID] + '</li>';
				}
				
				errorStr += '</ul>';
				
				byId(this.form.id + '-errors-cont').innerHTML = errorStr;
			}
			
			this.resetSubmit();
		}
	};
	
	this.resetSubmit = function(){
		this.submitBtn.disabled = false; //make sure the button is enabled
		this.submitBtn.value = this.submitBtnDefaultVal;
	};
	
	this.fieldCheck= function(event){ //check event
		var parent = event.data.parent; //out of scope because function is called on event
		
		var classes = this.className.split(' ');
		//handle combo
		/* does not work in ie
		var index = classes.indexOf('val_combo');
		*/
		var index = $.inArray('val_combo', classes);
		if(index != -1){ // found key word
			if(index + 1 == classes.length){ // dosnt have combo id
				alert('val_combo id required');
				return;
			}
			var comboID = classes[index + 1];
			
			if($('#' + parent.comboID + '_error')){ //clear combo error
				$('#' + parent.comboID + '_error').remove();
			}
			if(parent.errors[comboID]){ //clear combo error
				parent.errors[comboID] = false;
			}
			var comboFields = $('.' + comboID, parent.form); //get all fields with combo id in class
			
			for(var i = 0; i < comboFields.length; i++){
				parent.validate(comboFields[i], comboID);
				if(parent.errors[comboID]){
					return;	
				}
			}
			return;
		}
		
		parent.validate(this);
		return;
	};
	
	this.fieldCheckSubmit= function(field){ //check event
		var classes = field.className.split(' '); //make sure to get the latest class name sice it may have changed
		//handle combo
		/* does not work in ie
		var index = classes.indexOf('val_combo');
		*/
		var index = $.inArray('val_combo', classes);
		if(index != -1){ // found key word
			if(index + 1 == classes.length){ // dosnt have combo id
				alert('val_combo id required');
				return;
			}
			var comboID = classes[index + 1];
			
			if($('#' + this.comboID + '_error')){ //clear combo error
				$('#' + this.comboID + '_error').remove();
			}
			if(this.errors[comboID]){ //clear combo error
				this.errors[comboID] = false;
			}
			
			var comboFields = $('.' + comboID, this.form); //get all fields with combo id in class
			
			for(var i = 0; i < comboFields.length; i++){
				this.validate(comboFields[i], comboID);
				if(this.errors[comboID]){
					return;	
				}
			}
			return;
		}
		
		this.validate(field);
		return;
	};
	
	this.validate= function(field, comboID){ // validate function
		
		if(field.value && field.type.toLowerCase() != 'file'){ //security error for file inputs
			field.value = $.trim(field.value); //auto strip whitespaces
		}
		var classes = field.className.split(' ');
		//check for val_skipifis
		/* does not work in ie
		var locate = classes.indexOf('val_skipifis');
		*/
		
		var locate = $.inArray('val_skipifis', classes);
		if(locate != -1 && locate != (classes.length - 1)){ // exist and not the last class name
			var ifisInput = $('#' + classes[locate + 1])[0];
			if(ifisInput.value != '' && field.value == ifisInput.value){
				/* does not work in ie
				if(classes.indexOf('val_ajax') != -1 ){ // top ajax running, because of submit check
				*/
				for (var j = 0; j < this.ajaxClasses.length; j++) {
					if (inArray(this.ajaxClasses[j], classes)) { // top ajax running, because of submit check
						this.ajaxRunning[field.id] = false;
					}
				}
				this.errorHandler(field, false);
				return;	
			}
		}
		
		for(var i = 0; i < classes.length; i++){
			/*
			does not work in ie
			if(this.classList.indexOf(classes[i]) == -1){ //not a keyword
			*/
			if(!inArray(classes[i], this.classList)){ //not a keyword
				continue;
			}
			/*
			does not work in ie
			if(this.dependents.indexOf(classes[i]) == -1){ //not a dependant
			*/
			if(!inArray(classes[i], this.dependents)){ //not a dependant
				var run = 'var error = this.' + classes[i] + '(field);';
			}
			else{ //dependent on next class
				if(i + 1 == classes.length){
					alert('valForm dependent required');
					return false;
				}
				var run = 'var error = this.' + classes[i] + '(field, "' + classes[i + 1] + '");';
			}
			eval(run); //alert(run);
			
			//if(classes[i] == 'val_ajax'){
			if(inArray(classes[i], this.ajaxClasses)){
				continue;	
			}
			var errorField = field;
			if(comboID){ // display error for combo 
				errorField = $('#' + comboID)[0];
			}
			if(this.errorHandler(errorField, error)){
				break;	
			}
		}
	};
	
	this.errorHandler= function(field, error){ // function to display error	
		var fieldType = field.type.toLowerCase();
		if(fieldType == 'checkbox' && field.name.indexOf('[') != -1 ){ //for checkboxes, name is an array, get label base on first index id 
			var labelFor = $('[name="' + field.name + '"]', this.form)[0].id;
		}
		else{
			var labelFor = field.id;
		}
		
		var label = $('label[for=' + labelFor  + ']', this.form)[0];
		
		if($('#' + field.id + '_error')[0]){
			$('#' + field.id + '_error').remove();
			$([label, field]).removeClass(this.errorClass);
		}
		
		if (!error) { // no error
			return false;	
		}
		this.failed = true;
		
		 //when submiting, ajax running are set, but there is an error, so ajax function will not start, therefore ajax running will never be unset
		if (this.ajaxRunning[field.id]) {
			this.ajaxRunning[field.id] = false;
		}
		
		if (!label) {
			alert(field.id + ' label is missing, check label id');
			return;
		}
		//remove html between label tags or remove a colon and after
		var errorMsg = label.innerHTML;
		
		// Remove <em>*</em>, tooltip
		errorMsg = errorMsg.replace(/^<em>\*<\/em>|<span class="tip">.+<\/span>/gi, '');
		
		// Strip tags
		errorMsg = $('<tag>' + errorMsg + '</tag>').text(); // .text() will only work when string starts with html tag
		
		// Trim whitespace and ending colon
		errorMsg = $.trim(errorMsg);
		errorMsg = errorMsg.replace(/:$/gi, '') + ' ' + error;
		
		if(!this.hideErrorsFlag){
			//check to place error after a diferent element
			var classNames = field.className.split(' ');
			/* does not work in ie
			var findKeyword = classNames.indexOf('val_errorAfter');
			*/
			var findKeyword = $.inArray('val_errorAfter', classNames);
			if (findKeyword != -1){
				if (findKeyword == (classNames.length - 1)) { //missing id for error element
					alert('val_form: val_errorAfter is missing an id');
				}
				else {
					var errorMsgHtml = '<' + this.errorContainerTag + ' id="' + field.id + '_error" class="' + this.errorContainerClass + '">' + errorMsg + '</' + this.errorContainerTag + '>';
					$(errorMsgHtml).insertAfter($('#' + classNames[findKeyword + 1]));
					$([label, field]).addClass(this.errorClass);
				}
			}
			else { //place error after field element
				var errorMsgHtml = '<' + this.errorContainerTag + ' id="' + field.id + '_error" class="' + this.errorContainerClass + '">' + errorMsg + '</' + this.errorContainerTag + '>';
				$(errorMsgHtml).insertAfter(field);
				$([label, field]).addClass(this.errorClass);
			}
		}
		
		this.errors[field.id] = errorMsg;
		
		return true;
	};
	
	
	//-------------- VALIDATORS
	
	this.val_num = function(field) {
		if(field.value.match(/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/) || field.value == '') {
			return false;
		} 
		else {
			return 'needs to be a number.';
		}
	};
	
	this.val_req = function(field) {
		var fieldType = field.type.toLowerCase();
		if(fieldType == 'checkbox' || fieldType == 'radio'){
			var values = $('[name="' + field.name + '"]', this.form);
			for(var i = 0; i < values.length; i++){
				if(values[i].checked){
					return false;	
				}
			}
		}  
		else if(field.value.length != 0) {
			return false;
		} 
		
		return 'is required.';
	};
	
	this.val_min = function(field, minLen) {
		if(field.value.length < parseFloat(minLen) && field.value != ''){
			return 'must be at least ' + minLen + ' characters long.';
		}
		else{
			return false;	
		}
	};
	
	this.val_max = function(field, maxLen) {
		if(field.value.length > parseFloat(maxLen) && field.value != ''){
			return 'must be at most ' + maxLen + ' characters long.';
		}
		else{
			return false;	
		}
	};
	
	this.val_maxNum = function(field, maxNum){
		if(!isNaN(field.value) && field.value > parseFloat(maxNum)){ 
			return 'must be ' + maxNum + ' or less.';
		}
		else{
			return false;	
		}
	};
	
	this.val_minNum = function(field, minNum){
		if(!isNaN(field.value) && (field.value < parseFloat(minNum)) && field.value != ''){
			return 'must be ' + minNum + ' or greater.';
		}
		else{
			return false;	
		}
	};
	
	this.val_len = function(field, len) {
		if(field.value.length != parseFloat(len) && field.value != ''){
			return 'must be ' + len + ' characters long.';
		}
		else{
			return false;	
		}
	};
	
	this.val_same = function(field, field2){
		var field2Obj = $('#' + field2)[0];
		if(!field2Obj){
			alert('val_same: ' + field2 + ' is not defined');
			return true;
		}
		if(field.value != field2Obj.value && field2Obj.value != ''){
			var field2Label = $('label[for=' + field2Obj.id + ']', this.form)[0].innerHTML;
			field2Label = field2Label.replace(/^<em>\*<\/em>|<span class="tip">.+<\/span>/gi, '');
			field2Label = $.trim($('<tag>' + field2Label + '</tag>').text()); // .text() will only work when string starts with html tag
			field2Label = field2Label.replace(/:$/gi, ''); // remove ending colon
			return 'does not match ' + field2Label + '.';
		}
		return false;
	};
	
	this.val_notSame = function(field, field2){
		var field2Obj = $('#' + field2)[0];
		if(!field2Obj){
			alert('val_notSame: ' + field2 + ' is not defined');
			return 'error';
		}
		if(field.value.length == 0){ //blank
			return false;	
		}
		if(field.value == field2Obj.value){
			var field2Label = $('label[for=' + field2Obj.id + ']', this.form)[0].innerHTML;
			field2Label = field2Label.replace(/^<em>\*<\/em>|<span class="tip">.+<\/span>/gi, '');
			field2Label = $.trim($('<tag>' + field2Label + '</tag>').text()); // .text() will only work when string starts with html tag
			field2Label = field2Label.replace(/:$/gi, ''); // remove ending colon
			return ' must not match ' + field2Label;	
		}
		return false;
	};
	
	this.val_email = function(field){
		if(field.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/) || field.value == '') {
			return false;
		} 
		else {
			return 'is not a valid email address.';
		}
	};
	
	this.val_alpha = function(field) {
		if(field.value.match(/^[a-zA-Z]+$/) || field.value == '') {
			return false;
		} 
		else {
			return 'should contain only letters.';
		}
	};
	
	this.val_alpha_space = function(field) {
		if(field.value.match(/^[a-zA-Z\s]*$/) || field.value == '') {
			return false;
		} 
		else {
			return 'should contain only letters and spaces.';
		}
	};
	
	this.val_alpha_num = function(field) {
		if(field.value.match(/^[a-zA-Z0-9]*$/) || field.value == '') {
			return false;
		} 
		else {
			return 'should contain only letters and numbers.';
		}
	};
	
	this.val_alpha_num_space = function(field) {
		if(field.value.match(/^[a-zA-Z0-9\s]*$/) || field.value == '') {
			return false;
		} 
		else {
			return 'value should contain only letters, numbers, and spaces.';
		}
	};
	
	this.val_alpha_num_sym = function(field) {
		if(field.value.match(/^[a-zA-Z0-9_\-.]*$/) || field.value == '') {
			return false;
		} 
		else {
			return 'should contain only letters, numbers, and "-", "_", or ".".';
		}
	};
	
	this.val_int = function(field) {
		if(field.value.match(/(^-?\d\d*$)/) || field.value == '') {
			return false;
		} 
		else {
			return 'needs to be a whole number.';
		}
	};
	
	this.val_url = function(field) {
		if(field.value.match(/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i) || field.value == '') {
			return false;
		} 
		else {
			return 'needs to be a valid url.';
		}


	};
	
	this.val_checked = function(field, len){
		var checked = 0;
		var values = $('[name="' + field.name + '"]', this.form);
		for(var i = 0; i < values.length; i++){
			if(values[i].checked){
				checked++;
			}
		}
		if(checked != len){
			return 'requires ' + len + ' selections.';
		}
		return false;
	};
	
	this.val_checked_min = function(field, len){
		var checked = 0;
		var values = $('[name="' + field.name + '"]', this.form);
		for(var i = 0; i < values.length; i++){
			if(values[i].checked){
				checked++;
			}
		}
		if(checked < len){
			return 'requires at least ' + len + ' selections.';
		}
		return false;
	};

	this.val_checked_max = function(field, len){
		var checked = 0;
		var values = $('[name="' + field.name + '"]', this.form);
		for(var i = 0; i < values.length; i++){
			if(values[i].checked){
				checked++;
			}
		}
		if(checked > len){
			return 'requires at most ' + len + ' selections.';
		}
		return false;
	};

	this.val_ajax = function(field, func){
		eval(func + "('" + field.id + "')");
		return true;
	};
	
	this.val_func = function(field, func){
		eval('var valForm_error = ' + func + "('" + field.id + "')");
		if(valForm_error){
			return valForm_error;
		}
		else{
			return false;
		}
	};
	
	this.val_exist = function(field, fieldToCheck){
		eval("checkExist('" + fieldToCheck + "', '" + field.id + "', true)");
		return true;
	};
	
	this.val_not_exist = function(field, fieldToCheck){
		eval("checkExist('" + fieldToCheck + "', '" + field.id + "', false)");
		return true;
	};
	
	//action key words	
	this.val_money = function(field){
		field.value = field.value.replace(/[^0-9\-\.]/g, '');
		if(field.value == ''){
			return;	
		}
		if(isNaN(field.value)){
			formated = '0.00';
		}
		else{
			var formated = Math.round(field.value * 1000) / 1000; //1000 for partial cents
			formated = formated.toString();
			if(formated.indexOf('.') == -1){
				formated += '.00';
			}
			else{
				var parts = formated.split('.');
				if(parts[1].length == 1){
					formated += '0';	
				}
			}
		}
		field.value = formated;
	};
	
	this.val_date = function(field) {
		if(field.value == ''){
			return false;	
		}
		else if(field.value.match(/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/)) {
			//make sure date is valid
			var dateParts = field.value.split('/');
			var day = dateParts[1];
			var month = dateParts[0];
			var year = dateParts[2];
			var dteDate = new Date(year, month - 1, day);
			if(day == dteDate.getDate() && (month == dteDate.getMonth() + 1) && year == dteDate.getFullYear()){
				return false;
			}
			return 'is an invalid date.';
		} 
		else {
			return 'needs to be mm/dd/yyyy.';
		}
	};
	
	this.val_datetime = function(field) {
		if(field.value.match(/^[0-9]{2}\/[0-9]{2}\/[0-9]{4} [0-9]{2}:[0-9]{2}(:[0-9]{2})? (am|pm|AM|PM)$/) || field.value == '') {
			return false;
		} 
		else {
			return 'needs to be mm/dd/yyyy hh:mm:ss am/pm.';
		}
	};
	
	this.val_phone = function(field) {
		if(field.value == ''){
			return false;	
		}
		var numbers = field.value.replace(/[^0-9]/g, ''); //remove all non numerics
		if(numbers.length < 10){
			return 'needs to be 10 digits.';	
		}
		field.value = numbers.substr(0, 3) + '-' + numbers.substr(3, 3) + '-' + numbers.substr(6, 4);
		// handle extensions
		if(numbers.length > 10){
			field.value += ' x ' + numbers.substr(10);
		}
		return false;
	};
	
	this.val_ceil = function(field, multiple) {
		if(field.value == ''){
			return false;	
		}
		var factor = Math.floor(field.value / multiple);
		var remainder = field.value % multiple;
		if(remainder > 0){
			factor++;	
		}
		field.value = factor * multiple;
	};
}

//Event.observe(window, 'load', this.init);
