
function popUp(URL,w,h) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left = 690,top = 425');");
}

function getXY(oElement,coord){
	if(coord=="y"){
		var iReturnValue = 0;
		while( oElement != null ) {
			iReturnValue += oElement.offsetTop;
			oElement = oElement.offsetParent;
		}
	}else if(coord=="x"){
		var iReturnValue = 0;
		while( oElement != null ) {
			iReturnValue += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
	}
	return iReturnValue;
}

function navigation_add_sub(el,num, orientX, orientY){
	orientX = typeof(orientX) != 'undefined' ? orientX : 0 - 26; ////defaults to horitonzal positioning
	orientY = typeof(orientY) != 'undefined' ? orientY : 30;
	var winW = window_size('w');
	var winH = window_size('h');

	if(el!=null && num!=null){
		var fake_array=eval("n"+num);
		var mn=document.getElementById(el);
		var sn=document.getElementById("sub");
		if(fake_array.length>0){
			var nsn='<table cellpadding="0" cellspacing="0">\n';
			for(x=0;x<fake_array.length;x++){
				nsn=nsn+'\t<tr>\n';
				
							if(fake_array[x+1]=="JAVASCRIPT:ALERT"){
																	nsn=nsn+'\t\t<td class="navigation_sub_left"></td><td class="navigation_sub_off" onClick="alert(\'Here is an alert\');" onMouseOver="this.className=\'navigation_sub_over\';" onMouseOut="this.className=\'navigation_sub_off\';"><a href="Javascript:" class="hilite">';
							
							}					else{
						nsn=nsn+'\t\t<td class="navigation_sub_left"></td><td class="navigation_sub_off" onClick="make_link(\''+fake_array[x+1]+'\');" onMouseOver="this.className=\'navigation_sub_over\';" onMouseOut="this.className=\'navigation_sub_off\';"><a href="'+fake_array[x+1]+'" class="hilite">';
					}

				nsn=nsn+fake_array[x]+'</a></td><td class="navigation_sub_right"></td>\n';

				nsn=nsn+'\t</tr>';

				x++;
			}
			var cur_cell = document.getElementById("sub_nav"+num);
			var snw = document.getElementById("snw"+num);
			var tablecell = document.getElementById("tablecell"+num);

			var tbc_x = getXY(tablecell,"x");
			var tbc_y = getXY(tablecell,"y");
			
			//var half_width=((cur_cell.width-sn.width)/2);
			nsn=nsn+'</table>\n';
			sn.innerHTML=nsn;

			elemHeight = sn.clientHeight;
			//alert(tbc_y+orientY+elemHeight+' - '+winH);
			//alert(document.body.scrollTop);
			if((tbc_y+orientY+elemHeight)>(winH+document.body.scrollTop)){
				//newOrientY = (tbc_y+orientY)-(((winH+document.body.scrollTop)-(tbc_y+orientY+elemHeight))*-1);
				newOrientY = (tbc_y-elemHeight)+tablecell.clientHeight+orientY+30;
				sn.style.left=tbc_x+orientX;
				sn.style.top=newOrientY-30;
			}else{
				sn.style.left=tbc_x+orientX;
				sn.style.top=tbc_y+orientY;
			}

		}else{
			var sn=document.getElementById("sub");
			sn.innerHTML='';
			sn.style.left=0;
			sn.style.top=0;
		}
	}else{
		var sn=document.getElementById("sub");
		sn.innerHTML='';
		sn.style.left=0;
		sn.style.top=0;
	}
}
function navigation_remove_sub(){
	var sn=document.getElementById("sub");
	sn.innerHTML='';
	sn.style.left=0;
	sn.style.top=0;
}

function window_size(ret){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	if (winW <= 695){
		winW = 695;
	}
	if(ret=="h"){
		return winH;
	}else if(ret=="w"){
		return winW;
	}
}

function make_link(url) {
	window.location.href = url; 
}


			function qs_btn_ro(obj, action){
				if(obj.className==action){
					//// take no action
				}else{
					obj.className=action;
				}
			}
function findPos(obj,coord) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		if(coord=="x"){
			return [curleft];
		}else{
			return [curtop];
		}
	}
}
//////////////////////MENU SWITCH/////////////////////////////
function SwitchMenu(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
		if(el.style.display != "block"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu2") 
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
function SwitchMenu2(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
		if(el.style.display != "block"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") 
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
//////////////////////IMG FADING SCRIPT//////////////////
var img_on_top="img2";
var has_run_init_funcs=0;
function initial_img_fader_actions(){
	if(has_run_init_funcs==0){
		var sec_div=document.getElementById('img2');
		//sec_div.style.position='absolute';
		//sec_div.style.top=findPos(document.getElementById('img1'),'y'); //findPos(document.getElementById('img1'),'y');
		//sec_div.style.left=findPos(document.getElementById('img1'),'x');; //findPos(document.getElementById('img1'),'x');
		opacity('img2', 100, 0, 10, 'img2');
		has_run_init_funcs=1;
	}
}

function opacity(id, opacStart, opacEnd, millisec, prev_id) {
	//millisec=millisec+2000;
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

	var cur_pic=document.getElementById(id);
	var last_pic=document.getElementById(prev_id);

	cur_pic.style.zIndex=51;
	last_pic.style.zIndex=50;
	//alert(last_pic);

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
    setTimeout("changeOpac(0,'" + prev_id + "')", millisec);
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function findPos(obj,coord) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		if(coord=="x"){
			return [curleft];
		}else{
			return [curtop];
		}
	}
}

function fade_img(image_path,next){
	var prev;
	if(next=='img1'){
		var cur_pic=document.getElementById(next);	
		var last_pic=document.getElementById('img2');	
		image_on_top="img2";
		prev="img2";
	}else if(next=='img2'){
		var cur_pic=document.getElementById(next);	
		var last_pic=document.getElementById('img1');	
		image_on_top="img1";
		prev="img1";
	}

	cur_pic.src=image_path;
	setTimeout("opacity('" + next + "', 0, 100, 500, '" + prev + "')", 750);

	return image_on_top;
}
////////////////////////////////////////////////
/////////////////SUB NAV FUNCTIONS//////////////

//////////////////////////////////////////////////
//////////////AJAX FUNCTIONS \\\\\\\\\\\\\\\\\\\\\
	function mysql_jax(file,path,vars,redirect){
		//alert('in mjax');
		delete mysqljax;
		var mysqljax;
		try{
			// Opera 8.0+, Firefox, Safari
			mysqljax = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				mysqljax = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					mysqljax = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		mysqljax.onreadystatechange = function(){
			if(mysqljax.readyState == 4){
				//This function is just to send vars to be inserted into mysql dbs thus it returns nothing...
				final_results = mysqljax.responseText;

				if(redirect!=undefined){
					window.location = redirect;
				}
			}
	
		}
		
		var queryString = "vars="+vars;
		//can add variables above to specify search file

		mysqljax.open("POST", path+file, true);
		mysqljax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		mysqljax.setRequestHeader("Content-length", queryString.length);
		mysqljax.setRequestHeader("Connection", "close");
		mysqljax.send(queryString);
	}

	function final_jax(file,path,vars,div_name){
		delete finaljax;
		var finaljax;
		try{
			// Opera 8.0+, Firefox, Safari
			finaljax = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				finaljax = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					finaljax = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		finaljax.onreadystatechange = function(){
			if(finaljax.readyState == 4){

				final_results = finaljax.responseText;
				var final_replace=document.getElementById(div_name);
				final_replace.innerHTML=final_results;

				var final_replace2=document.getElementById(div_name);
				final_replace2.innerHTML=final_replace.innerHTML;
			}
	
		}
		
		var queryString = "vars="+vars;
		//can add variables above to specify search file

		finaljax.open("POST", path+file, true);
		finaljax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		finaljax.setRequestHeader("Content-length", queryString.length);
		finaljax.setRequestHeader("Connection", "close");
		finaljax.send(queryString);
	}
/////////////////////////////////////////////////////////////
			function grayOutOnly(vis, options) {

				var options = options || {}; 
  				var zindex = 20;
  				var opacity = options.opacity || 70;
  				var opaque = (opacity / 100);
  				var bgcolor = options.bgcolor || '#000000';
  				var dark=document.getElementById('darkenScreenObject');
  				if (!dark) {
    					var tbody = document.getElementsByTagName("body")[0];
    					var tnode = document.createElement('div');           
        				tnode.style.position='absolute';                
        				tnode.style.top='0px';                          
        				tnode.style.left='0px';                         
        				tnode.style.overflow='hidden';                         
        				tnode.style.display='none';                   
        				tnode.id='darkenScreenObject';                
    					tbody.appendChild(tnode);                           
    					dark=document.getElementById('darkenScreenObject'); 
  				}
  				if (vis) {
					//close_popups(0,'main_h_search_form',0);

    					if(document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        					var pageWidth = document.body.scrollWidth+'px';
        					var pageHeight = document.body.scrollHeight+'px';
    					} else if( document.body.offsetWidth ) {
      						var pageWidth = document.body.offsetWidth+'px';
      						var pageHeight = document.body.offsetHeight+'px';
    					} else {
       						var pageWidth='100%';
       						var pageHeight='100%';
    					}   
	    				dark.style.opacity=opaque;                      
    					dark.style.MozOpacity=opaque;                   
    					dark.style.filter='alpha(opacity='+opacity+')'; 
    					dark.style.zIndex=zindex;        
    					dark.style.backgroundColor=bgcolor;  
	    				dark.style.width= pageWidth;
    					dark.style.height= pageHeight;
    					dark.style.display='block';				 
  				} else {
				     if(document.getElementById('main_dream_home_search')){
					     final_jax('forms.php','absolutes/','\$form=\'main_dream_home_search\';','main_h_search_form');
						//alert('here');
				     }
				     dark.style.display='none';
  				}
			}
	function close_popups(gray_out,div,resize){
		//alert(resize);
		if(resize!=0){
			//alert("is_null");
			resize=1;
		}

		var close_pops;
		if(div!=undefined && div!=""){
			//alert("1 "+div);
			if(document.getElementById(div)!=null){
				close_pops=document.getElementById(div);
				close_pops.innerHTML="";
			}
		}else{
			//alert("2 "+div);
			if(document.getElementById('popup_popup')!=null){
				close_pops=document.getElementById('popup_popup');
				close_pops.innerHTML="";
			}
		}

		if(resize==1){
			//alert("resize");
			close_pops.style.width="0px";
			close_pops.style.height="0px";
		}
		if(gray_out==1){
			grayOutOnly(false)
		}
	}
function final_popup(file,path,vars,div_name,cords,gray_out){
	if(cords!="" && cords!="center" && cords!="under" && cords!="br" && cords!="br2" && cords!="onEvent")
		eval(cords);
	delete popupjax_new;
	var popupjax_new;
	try{
		// Opera 8.0+, Firefox, Safari
		popupjax_new = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			popupjax_new = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				popupjax_new = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	popupjax_new.onreadystatechange = function(){
		if(popupjax_new.readyState == 4){
			//alert('Popup 1');
			final_results = popupjax_new.responseText;
			var final_replace=document.getElementById(div_name);
			final_replace.innerHTML=final_results;
			
			//alert(cords+" "+div_name);
			if(cords=='center'){
				var winW = 1024, winH = 786;
				if (parseInt(navigator.appVersion)>3) {
					if (navigator.appName=="Netscape") {
						winW = window.innerWidth;
						winH = window.innerHeight;
					}
					if (navigator.appName.indexOf("Microsoft")!=-1) {
						winW = document.body.offsetWidth;
						winH = document.body.offsetHeight;
					}
				}

				if(div_name=="home_detail_popup"){
					close_popups(0,'main_h_search_form',0);
					if(file=="search_advanced.php"){
						var hd_left=((winW-800)/2);
						final_replace.style.width = '800px';
						final_replace.style.height = '400px';
	       					final_replace.style.top=(document.body.scrollTop+25)+'px';                          
		       				final_replace.style.left=hd_left;
					}else{
						var hd_left=((winW-1000)/2);
						final_replace.style.width = '1000px';
						final_replace.style.height = '600px';
		       				final_replace.style.top=(document.body.scrollTop+25)+'px';                          
		       				final_replace.style.left=hd_left;
						var fetch_js_exe=document.getElementById('js_exe');
						eval(fetch_js_exe.innerHTML);
					}
					//alert('Center');
				}
				if(div_name=="popup_popup"){
					var hd_left=((winW-450)/2);
					final_replace.style.width = '450px';
	       				final_replace.style.top=(document.body.scrollTop+75)+'px';                          
	       				final_replace.style.left=hd_left;
				}
				if(div_name=="advanced_search"){
					close_popups(0,'main_h_search_form',0);
				}
			}else if(cords=="under"){
				var sc_obj=document.main_search.search_city;
				var sc_xpos=findPos(sc_obj,"x");
				var sc_ypos=findPos(sc_obj,"y");
				sc_ypos=parseInt(sc_ypos);
				sc_xpos=parseInt(sc_xpos)+120;
				//document.body.scrollTop+
				final_replace.style.width = 150;
       				final_replace.style.top=(sc_ypos)+'px';                          
       				final_replace.style.left=sc_xpos;
				final_replace.style.height='200px';
				final_replace.style.overflow='auto';
				final_replace.style.textAlign='left';
			}else if(cords=="br"){
				final_replace.style.width = 403;
       				//final_replace.style.right=200;
				final_replace.style.height=195;
       				//final_replace.style.bottom= 200;
				final_replace.style.textAlign='left';
				var twin_h = document.body.clientHeight + 0;
				var twin_w = document.body.clientWidth + 0;
				//alert (twin_h + " - " + twin_w);

       		final_replace.style.top=twin_h - 197;                          
       		final_replace.style.left=twin_w - 407;
				
			}else if(cords=="br2"){
				final_replace.style.width = 227;
       				//final_replace.style.right=201;
				final_replace.style.height=300;
       				//final_replace.style.bottom= 200;
				final_replace.style.textAlign='left';
			}else if(cords=="onEvent"){
				var winW = 1024, winH = 786;
				if (parseInt(navigator.appVersion)>3) {
					if (navigator.appName=="Netscape") {
						winW = window.innerWidth;
						winH = window.innerHeight;
					}
					if (navigator.appName.indexOf("Microsoft")!=-1) {
						winW = document.body.offsetWidth;
						winH = document.body.offsetHeight;
					}
				}
				var hd_left=((winW-450)/2);
				
       		final_replace.style.top=100;                          
       		final_replace.style.left=hd_left;
			}else{
				
				if (mX < 0){mX = 0;}
				if (mY < 0){mY = 0;}
				move=document.getElementById(div_name);
				if (navigator.appName=="Netscape") {
					winH=winH+(move.offsetHeight/2);
				}
				if(mX+move.offsetWidth>winW){
					mX=mX-move.offsetWidth;
				}else if(mX-(move.offsetWidth/2)<0){
					mX=mX;
				}else{
					mX=mX-(move.offsetWidth/2);
				}
			
				if(mY+move.offsetHeight>winH){
					mY=mY-move.offsetHeight;
				}else if(mY-(move.offsetHeight/2)<0){
					mY=mY;
				}else{
					mY=mY-(move.offsetHeight/2);
				}
				move.style.left=mX;
				move.style.top=mY;
			}
		}
	}
		
	var queryString = "vars="+vars;
	//can add variables above to specify search file
	popupjax_new.open("POST", path+file, true);
	popupjax_new.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	popupjax_new.setRequestHeader("Content-length", queryString.length);
	popupjax_new.setRequestHeader("Connection", "close");
	popupjax_new.send(queryString);
	
	var e = window.event||window.Event;
	//get_cords(e,div_name);
	if(gray_out==1){
		grayOutOnly(true)
	}
}
function get_cords(e){
	var IE_check = document.all?true:false;
	if(!e) var e = window.event||window.Event;
	var mX = 0;
	var mY = 0;
	if (IE_check) {
		mX = e.clientX;			
		mY = e.clientY;
	}else{
		mX = e.pageX;
		mY = e.pageY;
		//alert("e3: "+e+" | mX:"+mX+" | mY:"+mY);
	}
	if (navigator.appName=="Netscape") {
		var winW = window.innerWidth;
		var winH = window.innerHeight;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		var winW = document.body.scrollWidth;
		var winH = document.body.scrollHeight;
	}
	var cc = "var mX="+ mX +"; var mY="+ mY +"; winW="+winW+"; winH="+winH+";";
	return cc;
}
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.

var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  
  
	alert(tempX + " VALS " + tempY);
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	return tempX + "::" + tempY;
}

function user_validate(frm){
		//alert("here 1"+frm);
		j=frm.elements.length;
		var temp="";
		var error_fail=0;
		for(x=0;x<j;x++){
			var tp=frm.elements[x].type;
			var tl=frm.elements[x].title;
			var val=frm.elements[x].value;
			var nm=frm.elements[x].name;
			var found_error=0;
			var rule=tl.split("|");
			//alert(tp + "- "+tl+" - "+val+" - "+nm+" - "+rule[0]);
			
			if(tp=="text"){
				if(tl=="empty"){
					//alert("Made It");
					var tstring="";
					cln_spcs=val.split(" ");
					for(i=0;i<cln_spcs.length;i++)
						tstring+=cln_spcs[i];
					if(tstring==null || tstring==""){
						//alert(nm+" in null");
						
						frm.elements[x].value="";
						var er_msg="Invalid Content.";
						var out = eval("document.getElementById('"+nm+"_er_msg')");
						if(out!=null)	out.innerHTML=er_msg;
						found_error=1;
					}else{
						var er_msg="";
						var out = eval("document.getElementById('"+nm+"_er_msg')");
						if(out!=null)	out.innerHTML=er_msg;
					}
					
				}else if(tl=="zip"){
					var tstring="";
					cln_spcs=val.split(" ");
					for(i=0;i<cln_spcs.length;i++)
						tstring+=cln_spcs[i];
					if(tstring==null || tstring==""){
						frm.elements[x].value="";
						var er_msg="Zip is required for vehicles in your area to be properly displayed.";
						var out = eval("document.getElementById('"+nm+"_er_msg')");
						if(out!=null)	out.innerHTML=er_msg;
						found_error=1;
					}
				}else if(rule[0]=="email_match"){
					var tstring=Trim(val);
					var val2=eval("frm."+rule[1]);
					var tstring2=Trim(val2.value);
					if(tstring!=null || tstring!=""){
						if(tstring!=tstring2){
							
							var er_msg="Email accounts do not match.  Please check spelling.";
							var out = eval("document.getElementById('"+nm+"_er_msg')");
							if(out!=null)	out.innerHTML=er_msg;
							found_error=1;	
						}
						var rslt=echeck(val);
						if(rslt==false){
							
							var er_msg="Invalid email address.";
							var out = eval("document.getElementById('"+nm+"_er_msg')");
							if(out!=null)	out.innerHTML=er_msg;
							found_error=1;
						}
					}else{
						
						var er_msg="Invalid email address.";
						var out = eval("document.getElementById('"+nm+"_er_msg')");
						if(out!=null)	out.innerHTML=er_msg;
						found_error=1;
					}
				}else if(rule[0]=="email" || rule[0]=="email_null"){
					var tstring=Trim(val);
					if(tstring!=null && tstring!=""){
						//alert("="+tstring+"=");
						var rslt=echeck(tstring);
						if(rslt==false){							
							var er_msg="Invalid email address. 2";
							var out = eval("document.getElementById('"+nm+"_er_msg')");
							if(out!=null)	out.innerHTML=er_msg;
							found_error=1;
						}
					}else{
						if(rule[0]!="email_null"){
							alert(rule[0]);
							var er_msg="Invalid email address. 3";
							var out = eval("document.getElementById('"+nm+"_er_msg')");
							if(out!=null)	out.innerHTML=er_msg;
							found_error=1;
						}
					}
				}
			}else if(tp=="select-one"){
				//alert(nm);
				if(tl=="empty"){
					//alert(tl);
					//alert(val);
					if(val==null || val=="" || val=="0"){
						
						var er_msg="Select Option.";
						var out = eval("document.getElementById('"+nm+"_er_msg')");
						if(out!=null)	out.innerHTML=er_msg;
						found_error=1;
					}
				}
			}else if(tp=="checkbox"){
				if(rule[0]=="agree"){
					if(frm.elements[x].checked==false){
						var er_msg="You have to agree to proceed forward.";
						var out = eval("document.getElementById('"+nm+"_er_msg')");
						if(out!=null)	out.innerHTML=er_msg;
						found_error=1;
					}
				}
			}else if(tp=="password"){
				if(rule[0]=="password"){
					//alert("made pass");
					var tstring=Trim(val);
					//alert(tstring);
					var val2=eval("frm."+rule[1]);
					var tstring2=Trim(val2.value);
					if(tstring!=null && tstring!=""){
						if(tstring!=tstring2){
							var er_msg="Passwords do not match.";
							var out = eval("document.getElementById('"+nm+"_er_msg')");
							if(out!=null)	out.innerHTML=er_msg;
							found_error=1;	
						}else if(tstring.length<6){
							var er_msg="Passwords must be at least 6 characters long.";
							var out = eval("document.getElementById('"+nm+"_er_msg')");
							if(out!=null)	out.innerHTML=er_msg;
							found_error=1;	
						}else if(tstring2.length<6){
							var er_msg="Passwords must be at least 6 characters long.";
							var out = eval("document.getElementById('"+nm+"_er_msg')");
							if(out!=null)	out.innerHTML=er_msg;
							found_error=1;	
						}
						
					}else{
						var er_msg="Please enter a valid password.";
						var out = eval("document.getElementById('"+nm+"_er_msg')");
						if(out!=null)	out.innerHTML=er_msg;
						found_error=1;
					}
				}
			}
			if(found_error==0){
				var er_msg="";
				var out = eval("document.getElementById('"+nm+"_er_msg')");
				if(out!=null)	out.innerHTML=er_msg;
			}else{
				error_fail=1;
			}
			temp+=frm.elements[x].type+"\n";
			temp+=frm.elements[x].title+"\n";
			temp+=frm.elements[x].value+"\n";
			
		}
		//alert(temp);
		
		return check_user_name(frm,error_fail)
		
	}
	
	function check_user_name(frm,error_fail){
		//alert("here 2"+frm);
		delete userChkJax;
		var userChkJax;
		try{
			// Opera 8.0+, Firefox, Safari
			userChkJax = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				userChkJax = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					userChkJax = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		userChkJax.onreadystatechange = function(){
			if(userChkJax.readyState == 4){

				final_results = userChkJax.responseText;
				//alert(final_results);
				
				if(final_results=="false"){
					var er_msg="Email Address is already being used, please enter a new email address.";
					var out = eval("document.getElementById('primary_email_er_msg')");
					if(out!=null) {
						out.innerHTML=er_msg;
						error_fail = 1;
					}
				}
				return check_verification_code(frm,error_fail);
			}
		}
		
		var queryString = "?sql_op=validate_emailuser&primary_email="+frm.primary_email.value;
		//can add variables above to specify search file

		userChkJax.open("POST", "free_account.php"+ queryString, true);
		userChkJax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		userChkJax.setRequestHeader("Content-length", queryString.length);
		userChkJax.setRequestHeader("Connection", "close");
		userChkJax.send(queryString);
	}
	
	function check_verification_code(frm,error_fail){
		//alert("here 2"+frm);
		delete userChkJax;
		var userChkJax;
		try{
			// Opera 8.0+, Firefox, Safari
			userChkJax = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				userChkJax = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					userChkJax = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		userChkJax.onreadystatechange = function(){
			if(userChkJax.readyState == 4){

				final_results = userChkJax.responseText;
				//alert(final_results);
				if(final_results=="false"){
					var er_msg=" Invalid Verification Code.";
					var out = eval("document.getElementById('verification_code_er_msg')");
					if(out!=null) {
						out.innerHTML=er_msg;
						error_fail = 1;
					}
					replaceCaptcha(frm);
				}
				else
				{
					var out = eval("document.getElementById('verification_code_er_msg')");
					if(out!=null)
						out.innerHTML='';
				}
				if(error_fail != 1)
					frm.submit();
				else
				{
					return false;
				}
			}
		}
		
		var queryString = "?sql_op=validate_verification_code&verificationCode="+frm.verificationCode.value;
		//can add variables above to specify search file

		userChkJax.open("POST", "free_account.php"+ queryString, true);
		userChkJax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		userChkJax.setRequestHeader("Content-length", queryString.length);
		userChkJax.setRequestHeader("Connection", "close");
		userChkJax.send(queryString);
	}
	
	function replaceCaptcha(frm)
	{
		var d = new Date();
		var rs_t = d.getTime();
		//frm.captcha_img.src="http://johnvanceford.com/random_image.php?rs_t="+rs_t;
	}
	
	function Trim(str) {
		return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	}
	function echeck(str) {
		var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
		if(pattern.test(str))
			return true;
		else
			return false;
	}
	function disregardMessage()
	{
		document.getElementById('new_message').style.display = "none";
		mysql_jax('disregard_message.php','absolutes/','$disregard_msg=1;');
	}
	function compareVehicles()
	{
		var x=document.getElementsByTagName("input");
		var found = 0;
		for(n=0;n<x.length;n++)
		{
			if(x[n].checked)
				found++;
		}
		if(found >= 2)
			document.compare.submit();
		else
			alert('You must check at least 2 vehicles to compare');
	}
	function validateFinancing()
	{
		var price = document.financing.price.value;
		if(price == 0 || price == ""){ 
			alert('You must enter a price!');
			return false;
		}
	}