/*
 *    AjaxController
 *    
 */  

function AjaxController(){}

AjaxController.prototype =
{
  xmlHttp : null,
  id      : null,
  re      : null,
  
  request : function(method, id, request)
  {
    this.xmlHttp = this.getXmlHttpObject()
  	if (this.xmlHttp==null) 
    {
  		alert ("Browser does not support HTTP Request")
  		return
  	}
  
  	var url="/figaro/figaro_start.php"
  	this.id = id
  	this.re = 'hello'
    	
  	url+="?method="+method+"&"+request+"&id="+id+"&_ajax=true&rand="+Math.random()
  	this.xmlHttp.onreadystatechange=this.response
  	this.xmlHttp.open("GET",url,true)
  	this.xmlHttp.send(null)
  },
  
  response : function()
  {
  	if (ajax.xmlHttp.readyState==4 || ajax.xmlHttp.readyState=="complete") { 
  		document.getElementById(ajax.id).innerHTML=ajax.xmlHttp.responseText
  	} 
  },
  
  append : function()
  {
  	if (ajax.xmlHttp.readyState==4 || ajax.xmlHttp.readyState=="complete")
    { 
      tr = document.createElement('tr')
      tr.innerHTML = ajax.xmlHttp.responseText
  		document.getElementById(ajax.id).appendChild(tr)
  	} 
  },
  
  getXmlHttpObject : function(handler)
  {
  	var objXMLHttp=null
  	
  	if (window.XMLHttpRequest) {
  		objXMLHttp=new XMLHttpRequest()
  	}
  	else if (window.ActiveXObject) {
  		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  
  	}
  	return objXMLHttp
  }
}

ajax = new AjaxController

// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 800;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}

function checkurl(str)
{
str=str.replace('//', 'doubleslashgoeshere')
return str
}

function toggletab(tab)
{
  if(navigator.appName == 'Microsoft Internet Explorer')
  {
    ietabs = document.getElementsByTagName('li')
    ietabContents = document.getElementsByTagName('div')
    
    for(i=0; i<ietabs.length; i++)
    {
      if(ietabs[i].className == 'tab-selected' || ietabs[i].className == 'tab')
      {
        ietabs[i].className = 'tab'
      }
    }

    for(i=0; i<ietabContents.length; i++)
    {    
     if(ietabContents[i].className == 'tab-content' || ietabContents[i].className == 'tab-content-default')
      {
        ietabContents[i].style.display = 'none'
      }
    }
  }
  else
  {
    tabs = document.getElementsByName('tab')
    tabContents = document.getElementsByName('tab-content')
    
    for(i=0; i<tabs.length; i++)
    {
      tabs[i].className = 'tab'
      tabContents[i].style.display = 'none'
    }
  }

  document.getElementById(tab+'-tab').className = 'tab-selected'
  document.getElementById(tab+'-content').style.display='block'
}

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

function selectAll(id)
{
  
}

function updateMake(year)
{
  request = 'type=select-make&year='+year
  ajax.request('update.hitchfinder.php','select-make-wrapper',request)
  Fat.fade_element('hitchfinder-2')
}

function updateModel(year,make)
{
  request = 'type=select-model&year='+year+'&make='+make
  ajax.request('update.hitchfinder.php','select-model-wrapper',request)
  Fat.fade_element('hitchfinder-3')
}

function updateStyle(year, make, model)
{
  request = 'type=select-style&year='+year+'&make='+make+'&model='+model
  ajax.request('update.hitchfinder.php','select-style-wrapper',request) 
    Fat.fade_element('hitchfinder-4')
}

function isInt(myNum) 
{
 var myMod = myNum % 1;

 if (myMod == 0) {
         return true;
 } else {
         return false;
 }}
var addBookmarkObj = {
  linkText:'Bookmark This Page',
  addTextLink:function(parId){
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    a.appendChild(document.createTextNode(addBookmarkObj.linkText));
  },
  addImageLink:function(parId,imgPath){
    if(!imgPath || isEmpty(imgPath)) return;
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    var img = document.createElement('img');
    img.alt = addBookmarkObj.linkText;
    img.title = '';
    img.src = imgPath;
    a.appendChild(img);
  },
  makeLink:function(parId) {
    if(!document.getElementById || !document.createTextNode) return null;
    parId=((typeof(parId)=='string')&&!isEmpty(parId))
      ?parId:'addBookmarkContainer';
    var cont=document.getElementById(parId);
    if(!cont) return null;
    var a=document.createElement('a');
    a.href=location.href;
    if(window.opera) {
      a.rel='sidebar'; // this makes it work in Opera 7+
    } else {
      // this doesn't work in Opera 7+ if the link has an onclick handler,
      // so we only add it if the browser isn't Opera.
      a.onclick=function() {
        addBookmarkObj.exec(this.href,this.title);
        return false;
      }
    }
    a.title=document.title;
    return cont.appendChild(a);
  },
  exec:function(url, title) {
    var isKonq=(isLikelyKonqueror3 && isLikelyKonqueror3());
    var isMac=(navigator.userAgent.toLowerCase().indexOf('mac')!=-1);
    var buttonStr = isMac?'Command/Cmd':'CTRL';

    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        // IE4/Win generates an error when you
        // execute "typeof(window.external.AddFavorite)"
        // In IE7 the page must be from a web server, not directly from a local 
        // file system, otherwise, you will get a permission denied error.
        window.external.AddFavorite(url, title); // IE/Win
    } else if(isKonq) {
      alert('You need to press CTRL + B to bookmark our site.');
    } else if(window.opera) {
      void(0); // do nothing here (Opera 7+)
    } else if(window.home) { // Netscape, iCab
      alert('You need to press '+buttonStr+' + D to bookmark our site.');
    } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
      alert('You need to press Command/Cmd + D to bookmark our site.');    
    } else {
      alert('In order to bookmark this site you need to do so manually '+
        'through your browser.');
    }
  }
}

function isEmpty(s){return ((s=='')||/^\s*$/.test(s));}

function isLikelyKonqueror3() {
  if(!document.getElementById) return false;
  if(document.defaultCharset || window.opera || !window.print) return false;
  if(window.home) return false; // Konqueror doesn't support this but Firefox,
    // which has silent support for document.all when in Quirks Mode does
  if(document.all) return true; // Konqueror versions before 3.4
  var likely = 1;
  // testing for silent document.all support; try-catch used to keep it from
  // generating errors in other browsers.
  // try-catch causes errors in IE4 and NS4.x so we use the eval() to hide it.
  // try {
  //   var str=document.all[0].tagName;
  // } catch(err) { likely=0; }
  eval("try{var str=document.all[0].tagName;}catch(err){likely=0;}");
  return likely;
}

function dss_addEvent(el,etype,fn) {
  if(el.addEventListener && (!window.opera || opera.version) &&
  (etype!='load')) {
    el.addEventListener(etype,fn,false);
  } else if(el.attachEvent) {
    el.attachEvent('on'+etype,fn);
  } else {
    if(typeof(fn) != "function") return;
    if(typeof(window.earlyNS4)=='undefined') {
      // to prevent this function from crashing Netscape versions before 4.02
      window.earlyNS4=((navigator.appName.toLowerCase()=='netscape')&&
      (parseFloat(navigator.appVersion)<4.02)&&document.layers);
    }
    if((typeof(el['on'+etype])=="function")&&!window.earlyNS4) {
      var tempFunc = el['on'+etype];
      el['on'+etype]=function(e){
        var a=tempFunc(e),b=fn(e);
        a=(typeof(a)=='undefined')?true:a;
        b=(typeof(b)=='undefined')?true:b;
        return (a&&b);
      }
    } else {
      el['on'+etype]=fn;
    }
  }
}

dss_addEvent(window,'load',addBookmarkObj.addTextLink);