function checkEmail(){
  email = document.myForm.email.value
  if(email){
    url = "/ajax/controls.php?cmd=7&email=" + email
    xmlHttp7=GetXmlHttpObject()
    if(xmlHttp7==null){
      alert ("Browser does not support HTTP Request")
      return
    }
    url += "&d="+Date()
    xmlHttp7.onreadystatechange=checkEmail2
    xmlHttp7.open("GET",url,true)
    xmlHttp7.send(null)
  }
}

function checkEmail2(){
  if (xmlHttp7.readyState==4 || xmlHttp7.readyState=="complete"){
    document.getElementById("divEmailValidation").innerHTML=xmlHttp7.responseText;
  }
}

function checkForm(){
  alert(document.myForm.colorID.value)
  if(!document.myForm.colorID.value){
    alert("Please choose a color before submitting")
    return false
  }
  return true
}

function enlargePhoto(photoID,w,h){
  if(screen){
    leftPos=screen.width-786;
    leftPos=(leftPos/2)-5;
    topPos=screen.height-539;
    topPos=(topPos/2)-30;
  }
  url = "/show-photo.php?photoID=" + photoID + "&w=" + w + "&h=" + h
  winAttributes = "width="+w+",height="+h+",left="+leftPos+",top="+topPos;
  photoWin=window.open(url, "photoWin", winAttributes);
}

function loadMake(makeID){
  url = "/ajax/controls.php?cmd=1&makeID=" + makeID
  xmlHttp1=GetXmlHttpObject()
  if(xmlHttp1==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp1.onreadystatechange=loadMake2
  xmlHttp1.open("GET",url,true)
  xmlHttp1.send(null)
}
//copy
function loadType(makeID){
  url = "/ajax/controls-inventory.php?cmd=1&makeID=" + makeID
  xmlHttp1=GetXmlHttpObject()
  if(xmlHttp1==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp1.onreadystatechange=loadMake2
  xmlHttp1.open("GET",url,true)
  xmlHttp1.send(null)
}

function loadMake2(){
  if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete"){
    document.getElementById("divModels").innerHTML=xmlHttp1.responseText;
  }
}

function loadMakeLeft(makeID){
  url = "/ajax/controls.php?cmd=9&makeID=" + makeID
  xmlHttp9=GetXmlHttpObject()
  if(xmlHttp9==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp9.onreadystatechange=loadMakeLeft2
  xmlHttp9.open("GET",url,true)
  xmlHttp9.send(null)
}

function loadModelLeft(modelID){
  document.leftSearchForm.modelID=modelID
  //alert(document.leftSearchForm.modelID.value)
}

function loadMakeLeft2(){
  if (xmlHttp9.readyState==4 || xmlHttp9.readyState=="complete"){
    document.getElementById("divSearchModel").innerHTML=xmlHttp9.responseText;
  }
}

function xloadModel(modelID){
  loadModelOverview(modelID)
  loadColorSelection(modelID)
  loadOptions(modelID)
  loadDeliveryOptions(modelID)
  loadSubmitButton()
}

function loadModel(modelID,isMark){
  //alert(isMark)
  if(!isMark){
    url = "/ajax/model-form.php?modelID=" + modelID
  }
  else{
    url = "/ajax/model-form-mark.php?modelID=" + modelID
  }
  xmlHttp8=GetXmlHttpObject()
  if(xmlHttp8==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  //url = "/contact-us/contact-us.html"
  //url = "http://rv.markknutson.com/"
  xmlHttp8.onreadystatechange=loadModel2
  xmlHttp8.open("GET",url,true)
  xmlHttp8.send(null)
}

//copy
function loadType3(type){
  if(type){
    url = "inventory3.html?type=" + type
    window.location=url
 if(xmlHttp1==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp1.onreadystatechange=loadMake2
  xmlHttp1.open("GET",url,true)
  xmlHttp1.send(null)
 }
}
//copy search via stockNo:
function loadType4(){
  //alert(isMark)
  var stockNumber = document.getElementById('stockNo');
  //alert(stockNumber.value) 
  url = "/ajax/controls-inventory.php?stockNo=" + stockNumber.value
  xmlHttp8=GetXmlHttpObject()
  if(xmlHttp8==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  //url = "/contact-us/contact-us.html"
  //url = "http://rv.markknutson.com/"
  xmlHttp8.onreadystatechange=loadModel2
  xmlHttp8.open("GET",url,true)
  xmlHttp8.send(null)
}

//copy
function loadTypeModel(type){
  //alert(isMark)
  url = "/ajax/search-inventory-types.php?type=" + type
  xmlHttp8=GetXmlHttpObject()
  if(xmlHttp8==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  //url = "/contact-us/contact-us.html"
  //url = "http://rv.markknutson.com/"
  xmlHttp8.onreadystatechange=loadModel2
  xmlHttp8.open("GET",url,true)
  xmlHttp8.send(null)
}

function loadModel2(){
  if (xmlHttp8.readyState==4 || xmlHttp8.readyState=="complete"){
    document.getElementById("divMainCopy").innerHTML=xmlHttp8.responseText;
  }
}
//

function loadColorSelection(modelID){
  url = "/ajax/controls.php?cmd=3&modelID=" + modelID
  xmlHttp3=GetXmlHttpObject()
  if(xmlHttp3==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp3.onreadystatechange=loadColorSelection2
  xmlHttp3.open("GET",url,true)
  xmlHttp3.send(null)
}

function loadColorSelection2(){
  if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete"){
    document.getElementById("divColors").innerHTML=xmlHttp3.responseText;
  }
}

function loadDeliveryOptions(modelID){
  url = "/ajax/controls.php?cmd=4&modelID=" + modelID
  xmlHttp4=GetXmlHttpObject()
  if(xmlHttp4==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp4.onreadystatechange=loadDeliveryOptions2
  xmlHttp4.open("GET",url,true)
  xmlHttp4.send(null)
}

function loadDeliveryOptions2(){
  if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete"){
    document.getElementById("divDelivery").innerHTML=xmlHttp4.responseText;
  }
}

function loadModelOverview(modelID){
  url = "/ajax/controls.php?cmd=2&modelID=" + modelID
  xmlHttp2=GetXmlHttpObject()
  if(xmlHttp2==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp2.onreadystatechange=loadModel2
  xmlHttp2.open("GET",url,true)
  xmlHttp2.send(null)
}

function xloadModel2(){
  if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete"){
    document.getElementById("divOverview").innerHTML=xmlHttp2.responseText;
  }
}

function loadOptions(modelID){
  url = "/ajax/controls.php?cmd=5&modelID=" + modelID
  xmlHttp5=GetXmlHttpObject()
  if(xmlHttp5==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp5.onreadystatechange=loadOptions2
  xmlHttp5.open("GET",url,true)
  xmlHttp5.send(null)
}

function loadOptions2(){
  if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete"){
    document.getElementById("divOptions").innerHTML=xmlHttp5.responseText;
  }
}

function loadSubmitButton(){
  document.getElementById('divSubmitButton').style.display='block';
}

function toggleStandardFeatures(){
  s = document.getElementById('divStandardFeatures').style.display
  if(s=="none"){
    document.getElementById('divStandardFeatures').style.display='block'
  }
  else{
    document.getElementById('divStandardFeatures').style.display='none'
  }
}

function search_inventory_url(url){
  document.getElementById('divInventory').innerHTML = "<table border=0 cellspacing=0 cellpadding=0><tr><td style='padding-right:5px;'><img src='/images/progress.gif' /></td><td class='copy'><strong>Loading Inventory ...</strong></td></tr></table>";
  xmlHttp_searchInventory=GetXmlHttpObject()
  if(xmlHttp_searchInventory==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
	//alert(url);
  xmlHttp_searchInventory.onreadystatechange=searchInventory2
  xmlHttp_searchInventory.open("GET",url,true)
  xmlHttp_searchInventory.send(null)
}

function search_inventory(){
	is_new = 0;
	is_used = 0;
	var search_form = document.forms.searchForm;
	if(search_form.is_new){
		if(search_form.is_new.checked==true){
			is_new = 1;
		}
	}
	if(search_form.is_used){
		if(search_form.is_used.checked==true){
			is_used = 1;
		}
	}
	
	// var query = search_form.query.value;
	var type = search_form.type.value;
	var model = search_form.model.value;
	var stock = search_form.stock.value;
	
	url = "/ajax/inventory-search.php?t=" + type + "&m=" + model + "&s=" + stock + "&n=" + is_new + "&u=" + is_used;
	url += "&r=" + Math.random();
	
  // url = "/ajax/inventory-search.php?s=" + type + "&q=" + query + "&is_used=" + is_used + "&is_new=" + is_new + "&r=" + Math.random();
  document.getElementById('divInventory').innerHTML = "<table border=0 cellspacing=0 cellpadding=0><tr><td style='padding-right:5px;'><img src='/images/progress.gif' /></td><td class='copy'><strong>Loading Inventory ...</strong></td></tr></table>";
  xmlHttp_searchInventory=GetXmlHttpObject()
  if(xmlHttp_searchInventory==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp_searchInventory.onreadystatechange=searchInventory2
  xmlHttp_searchInventory.open("GET",url,true)
  xmlHttp_searchInventory.send(null)
}

function searchInventory(type,query){
	is_new = 0;
	is_used = 0;
	var search_form = document.forms.searchForm;
	if(search_form.is_new){
		if(search_form.is_new.checked==true){
			is_new = 1;
		}
	}
	if(search_form.is_used){
		if(search_form.is_used.checked==true){
			is_used = 1;
		}
	}
  url = "/ajax/inventory-search.php?s=" + type + "&q=" + query + "&is_used=" + is_used + "&is_new=" + is_new + "&r=" + Math.random();
  document.getElementById('divInventory').innerHTML = "<table border=0 cellspacing=0 cellpadding=0><tr><td style='padding-right:5px;'><img src='/images/progress.gif' /></td><td class='copy'><strong>Loading Inventory ...</strong></td></tr></table>";
  xmlHttp_searchInventory=GetXmlHttpObject()
  if(xmlHttp_searchInventory==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  url += "&d="+Date()
  xmlHttp_searchInventory.onreadystatechange=searchInventory2
  xmlHttp_searchInventory.open("GET",url,true)
  xmlHttp_searchInventory.send(null)
}

function searchInventory2(){
  if (xmlHttp_searchInventory.readyState==4 || xmlHttp_searchInventory.readyState=="complete"){
    document.getElementById("divInventory").innerHTML=xmlHttp_searchInventory.responseText;
  }
}

function searchInventoryFromLeft(type,query){
  url = "/inventory/inventory.html?s=" + type + "&q=" + query;
  window.location = url;
}

function launchPlayer(account,playlist,clip){
  if(screen){
    leftPos=screen.width-786;
    leftPos=(leftPos/2)-5;
    topPos=screen.height-539;
    topPos=(topPos/2)-30;
  }
  url = "http://cst.clickstreamtv.net/gateway/open.html?account="+account+"&playlist="+playlist+"&clip="+clip;
  winAttributes = "width=786,height=539,left="+leftPos+",top="+topPos;
  gmacPlayerWin=window.open(url, "swPlayerWin", winAttributes);
}


// get xml http object
function GetXmlHttpObject(handler){ 
  var objXMLHttp=null
  if (window.XMLHttpRequest){
    objXMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject){
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  return objXMLHttp
}