// JavaScript Document for findboatsusa
var xmlHttp
var int_count = 0
var int_count_2 = 0

function populate_model(val, combo_name, form_name, selected_value)
{
	
	xmlHttp_new = new_GetXmlHttpObject();
	
	//document.getElementById('second_load').style.display='inline';
	//alert('hi');
	xmlHttp_new.onreadystatechange = function () 
	{
		
		if (xmlHttp_new.readyState == 4 || xmlHttp_new.readyState=="complete") 
		{
			populate_model_combo(val, combo_name,form_name, xmlHttp_new, selected_value);
			obj = document.getElementById(combo_name);
			if(selected_value != '')
			{
				var slvalue = Number(selected_value);
				for (i = 1 ; i < obj.length ; i++)
				{
					var cmb_val = Number(obj.options[i].value);
					
					if (cmb_val == slvalue)
					{
						obj.options[i].selected = true ;
						break;
					}
				}
			}
		}
		
	};
	
	xmlHttp_new.open("GET", "get_models.php?make="+val , true)
	xmlHttp_new.send(null);
	
	
}
function populate_model_combo(val, combo_name,form_name,xmlHttp, selected_value)
{
	//alert(xmlHttp.responseText);
	return_val  = xmlHttp.responseText;
	option_arr  = return_val.split("#");
	var ctrl_temp = document.forms[form_name].elements[combo_name];
	if(option_arr=="")
	{
		ctrl_temp.length=0;
		var cb = ctrl_temp;
		cb.options[cb.options.length] = new Option("Select Model","");
		return;
	}
	new_populateCB(ctrl_temp,option_arr, 'Select Model');
	if(selected_value != '')
	{
		SelectDD(selected_value, ctrl_temp);
	}
}
function populate_model1(val, combo_name, form_name, selected_value)
{
	xmlHttp = new_GetXmlHttpObject();
	//document.getElementById('second_load').style.display='inline';
	//alert('hi');
	xmlHttp.onreadystatechange = function () 
	{
		if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete") 
		{
			populate_model_combo(val, combo_name,form_name, xmlHttp, selected_value);
			//document.getElementById('second_load').style.display='none';
		}
	};
	xmlHttp.open("GET", "get_all_models.php?make="+val , true)
	xmlHttp.send(null)
}
function populate_makes(val, combo_name, form_name, selected_value, optional_combo)
{
	
	//alert(combo_name);
	//alert(form_name);
	//document.getElementById('first_load').style.display='inline';
	//alert('hi');
	if(optional_combo != '')
	{
		var ctrl_optional_combo = document.forms[form_name].elements[optional_combo];
		ctrl_optional_combo.length=0;
		ctrl_optional_combo.options[ctrl_optional_combo.options.length] = new Option("Select Model","");
	}
	xmlHttp_make = new_GetXmlHttpObject();
	//alert(val);
	xmlHttp_make.onreadystatechange = function () 
	{
		//alert(xmlHttp_make.readyState);
		if (xmlHttp_make.readyState == 4 || xmlHttp_make.readyState=="complete") 
		{
			//alert('here');
			populate_makes_combo(val, combo_name,form_name, xmlHttp_make, selected_value);
			//document.getElementById('first_load').style.display='none';
			obj = document.getElementById(combo_name);
			if(selected_value != '')
			{
				var slvalue = Number(selected_value);
				for (i = 1 ; i < obj.length ; i++)
				{
					var cmb_val = Number(obj.options[i].value);
					
					if (cmb_val == slvalue)
					{
						obj.options[i].selected = true ;
						break;
					}
				}
			}
			//alert(document.getElementById(combo_name).length)
		}
	};
	xmlHttp_make.open("GET", "get_makes.php?manufac_id="+val , true);
	xmlHttp_make.send(null);
}

function populate_makes_combo(val, combo_name,form_name,xmlHttp_m, selected_value)
{
	//alert(xmlHttp.responseText);
	return_val  = xmlHttp_m.responseText;
	option_arr  = return_val.split("#");
	var ctrl_temp = document.forms[form_name].elements[combo_name];
	
	if(option_arr=="")
	{
		ctrl_temp.length=0;
		var cb = ctrl_temp;
		cb.options[cb.options.length] = new Option("Select Make","");
		return;
	}
	new_populateCB(ctrl_temp,option_arr, 'Select Make');
	/*
	if(selected_value != '')
	{
		SelectDD(selected_value, ctrl_temp);
	}
	*/
}


function populate_makes1(val, combo_name, form_name, selected_value, optional_combo)
{
	//alert(val);
	//alert(combo_name);
	//alert(form_name);
	//document.getElementById('first_load').style.display='inline';
	//alert('hi');
	if(optional_combo != '')
	{
		var ctrl_optional_combo = document.forms[form_name].elements[optional_combo];
		ctrl_optional_combo.length=0;
		ctrl_optional_combo.options[ctrl_optional_combo.options.length] = new Option("Select Model","");
	}
	xmlHttp = new_GetXmlHttpObject();
	xmlHttp.onreadystatechange = function () 
	{
		//alert(val);
		if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete") 
		{
			populate_makes_combo(val, combo_name,form_name, xmlHttp, selected_value);
			//document.getElementById('first_load').style.display='none';
		}
	};
	xmlHttp.open("GET", "get_all_makes.php?manufac_id="+val , true)
	xmlHttp.send(null)
}




function new_GetXmlHttpObject()
{ 
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera") 
		return 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
		strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
		objXmlHttp=new ActiveXObject(strName)
		return objXmlHttp
		} 
		catch(e)
		{ 
		alert("Error. Scripting for ActiveX might be disabled") 
		return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		return objXmlHttp
	}
}
function new_populateCB(elm,data, first_text)
{// build the OPTIONS dynamically
  //var cb = clearCB(elm);
  elm.length = 0;
  cb = elm;
  if(first_text != '')
  {
  	cb.options[cb.options.length] = new Option(first_text,"");
  }
  if(isArray(data))
  {
	  for(var x=0;x<data.length;)
	  {
		var value = data[x++];
		var textval = data[x++];
		cb.options[cb.options.length] = new Option(textval,value);
	  }
  }
}

function codition_changed(ctrl_value)
{
	xmlHttp 		= GetXmlHttpObject(populate_manu);
	//alert(ctrl_value);
	xmlHttp.open("GET", "get_manufacturers.php?man_id="+ctrl_value , true)
	xmlHttp.send(null)
}

function populate_manu()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		return_val  = xmlHttp.responseText;
		//alert(return_val);
		option_arr  = return_val.split("#");
		var ctrl_temp = document.getElementById("sltDynManufacturer");
		if(option_arr=="")
		{
			var cb = clearCB(ctrl_temp);
  			cb.options[cb.options.length] = new Option("All Manufacturers","");
			return;
		}
		populateCB(ctrl_temp,option_arr);
		select_opt();
	}
}

function clearCB(elm)
{// clear out any pre-existing items in a SELECT object
  var parent = elm.parentNode;
  var newElm = elm.cloneNode(false);
  parent.replaceChild(newElm,elm);
  return newElm;
}
function populateCB(elm,data)
{// build the OPTIONS dynamically
  var cb = clearCB(elm);
  cb.options[cb.options.length] = new Option("All Manufacturers","");
  if(isArray(data))
  {
	  for(var x=0;x<data.length;)
	  {
		var value = data[x++];
		var textval = data[x++];
		cb.options[cb.options.length] = new Option(textval,value);
	  }
  }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function show(city,other)
{
	
//	alert(document.getElementById("free_bcity").style.display);
	//alert(city);
	if(document.getElementById(city).value=="other")
	{
	document.getElementById(city).style.display="none";
	document.getElementById(other).style.display="block";
	}
	else
	{
	document.getElementById(city).style.display="block";
	document.getElementById(other).style.display="none";
	}
	
}


function get_cities(type,cont,stateid,cityid)
{
//	alert(type+" 2 "+cont+" 3 "+stateid+" 4 "+cityid);

	int_count  = int_count+1
	if (type == "public")
	{
		url = "./include/get_city.php?stateid=" + stateid + "&cont=" + cont + "&cityid=" + cityid;
	
	}
	if (type == "admin")
	{
		url = "../include/get_city.php?stateid=" + stateid + "&cont=" + cont + "&cityid=" + cityid
	}


	if (url != "")
	{
		var cont = document.getElementById(cont)
		cont.disabled = true
		
		
		xmlHttp=GetXmlHttpObject(cities_state)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)			
	}
}


   


function cities_state()
{

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		int_count_2 = int_count_2 + 1
		var control  
		var control_arr = new Array();		
		var control_arr_arr = new Array();				
		var temp = new Array();
		var temp1 = new Array();		
		var is_select = false
		var is_select_index = -1
		
		return_val  = xmlHttp.responseText

		control_arr  = return_val.split("[cont]") 
		
		if(control_arr.length == 1) 
		return;
		control_arr_arr = control_arr[1].split("[select]")
		
		control  = document.getElementById(control_arr_arr[0])
		
		
		

		// Remove Options
		for (i = control.options.length; i >= 0; i--) 
		{
			control.options[i] = null; 
		}		

		temp	= control_arr[0].split("[row]")
		j	= 1
		control.options[0] = new Option("Select City","");
		for (i = 0 ; i < temp.length  ; i++)
		{

			if (temp[i] != "")
			{
				temp1  = temp[i].split("[record]")
				//is_select
				
				if (temp1[0] == control_arr_arr[1])
				{
					is_select = true
					is_select_index = j

				}
				
				if (temp1 != "empty")
				{
					control.options[j] = new Option(temp1[1],temp1[0] );
					
				}
				
			}
			j = j + 1
			
		}			
		control.options[j-2] = new Option("------------","");
		control.options[j-1] = new Option("Other","other");
		control.disabled = false

		if (is_select == true)
		{
			control.options[is_select_index].selected = true

		}

		//.innerHTML  = "<OPTION value='e'>e</OPTION>"
		//alert(document.getElementById("city").innerHTML)


	}	
	
	

//////////////////////////////////////////////////////////////////
				if (int_count_2 != int_count)
				{
					ajax_refresh_control = document.getElementById("ajax_refresh")
			
					if (ajax_refresh_control)
					{
						ajax_refresh_control.style.display = ''
					}
				}
				else
				{
					ajax_refresh_control = document.getElementById("ajax_refresh")
			
					if (ajax_refresh_control)
					{
						ajax_refresh_control.style.display = 'none'
					}					
				}
///////////////////////////////////////////////////////////////////

}


function chkrv(rv_name,is_profile,p_address,rv_id,dealer_id,advertiser_type)
{

	if (rv_name != ""  || rv_id != "" || dealer_id != "" || advertiser_type != "")
	{		
		url = "../include/chkrv.php?rv_name=" + rv_name + "&is_profile=" + is_profile + "&p_address=" + p_address + "&rv_id=" + rv_id + "&dealer_id=" + dealer_id + "&advertiser_type="+advertiser_type
		//alert(url)
		xmlHttp=GetXmlHttpObject(chkrv_state)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)			
	}
}

function chkrv_state()
{

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{

		
		var return_val  = xmlHttp.responseText
		//alert(return_val)
	}	
}

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
}

function SelectDD(cnt,obj)
{
	if(cnt != "")
	{
		for (i = 0 ; i < obj.length ; i++)
		{
			if (obj.options[i].value == cnt)
			{
				obj.options[i].selected = true ;
				break;
			}
		}
	}
}
function get_models(frm_name)
{
	var frm = document.frm;
	frm.action = frm_name;
	frm.method = "POST";
	frm.submit();
}
function CheckLogin(from)
{
	var  errormsg = "";

	if (from == "AFFILIATE")
	{
		Form = document.affiliate;
	}
	
	if (from == "ADVERTISER")
	{
		Form = document.advertiser;
	}
	
	if (Form.user_name.value == "")
		errormsg = errormsg + "Please Enter User Name. \n";

	if (Form.password.value == "")
		errormsg = errormsg + "Please Enter your Password. \n";

	if (errormsg == "")
	{
		Form.action = "checkuser.php";
		Form.submit();
	}
	else
	{
		alert ( errormsg );
	}

}
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue;
}
function my_type_changed(val)
{
	var found = false;
	//alert(val);
	for(var i=0; i<arr_show_eng_info.length;i++)
	{
		if(val == arr_show_eng_info[i])
		{
			found = true;
			break;
		}
	}
	if(found == true)
	{
		document.getElementById('eng_info').style.display='inline';
	}
	else
	{
		document.getElementById('eng_info').style.display='none';
	}

}
function spl_changed()
{
	var ctrl_chk = document.getElementById('chk_special');
	if(ctrl_chk.checked)
	{
		 document.getElementById('show_special').style.display='inline';
	}
	else
	{
		document.getElementById('show_special').style.display='none';
	}
}
var ie4 = false; if(document.all) { ie4 = true; }
function getObject(id) { if (ie4) { return document.all[id]; } else { return document.getElementById(id); } }
function toggle(link, divId) { var lText = link.innerHTML; var d = getObject(divId);
 if (lText == ' + ') { link.innerHTML = ' - '; d.style.display = ''; }
 else { link.innerHTML = ' + '; d.style.display = 'none'; } }