//set cookie and check cookie

	function checkPreviousPage()
		{
			setCookie("checkpreviouspage","",1);
			 var bd = document.getElementById("brandmodel");
			 if(bd == null)
			 {
				//alert("fail");
			}
			else
			{
			//var bdv = bd.nodeValue;
			//alert(bd.innerHTML)
			setCookie("checkpreviouspage",bd.innerHTML,1);
						//alert(bd.innerHTML)										
			}
	}
	function getCookie(c_name)
	 {
			if (document.cookie.length>0)
			{			
				c_start=document.cookie.indexOf(c_name + "=")			
				if (c_start!=-1)			
			   { 		
				   c_start=c_start + c_name.length+1 		
				   c_end=document.cookie.indexOf(";",c_start)		
				   if (c_end==-1) c_end=document.cookie.length		
				   return unescape(document.cookie.substring(c_start,c_end))		
			   } 			
			}
			return ""
	 }
	function DelCookie(sName)
	{
	  document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
	}

	 function setCookie(c_name,value,expiredays)
	 {		
	 		
		var today = new Date();

		today.setTime( today.getTime() );

		if ( expiredays ) {

		expiredays = expiredays * 1000 * 60 * 3; //cookie will expire in 3 min
	
		}

		var expires_date = new Date( today.getTime() + (expiredays) );
		document.cookie = c_name+'='+escape( value ) + ( ( expiredays ) ? ';expires='+expires_date.toGMTString() : '' );  	 
	 		//var expires_date=new Date();
			//expires_date.setDate(exdate.getDate()+expiredays);
			//document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
			
	 
	 }
	 
    start = function() {
        // get the reference for the body
	
    var bd = getCookie("checkpreviouspage");
	if (bd != "")
	{
	var name = document.getElementById("pname");
 	var model = document.createElement("span");

	var cellText = document.createTextNode(" (works with " + bd + ")");
    model.appendChild(cellText);
	name.appendChild(model);
	
	//document.getElementById('pname').innerHTML = bd;	
		
	//highlightSearchTerms(bd,1);
	//highlightSearchTerms(bd,1);
	DelCookie("checkpreviouspage") ;

	}
	setCookie("checkpreviouspage","",1);
	
		
/*URL Model Funciton*/
	var alink = new String(window.location);
	var parameterOfLink = alink.split("?");

	if(parameterOfLink.length>1){
		//var divItem = window.document.getElementById("urlmodel");
		
		var name = document.getElementById("pname");
		var model2 = document.createElement("span");
		//model2.style.color = "red";
		//model2.style.margin="0 5px 0 0";
		var model = new String(parameterOfLink[1]);
		var value = model.split("model=");

		var repStr = new String(value[1]);
	
		if(repStr.indexOf("+") != -1){
   		
			while(repStr.indexOf("+") != -1){
   	 			repStr = repStr.replace("+", " ");
   			}
			
  		}else if(repStr.indexOf("%20") != -1){
		   while(repStr.indexOf("%20") != -1){
    			repStr = repStr.replace("%20", " ");
   			}
		  }
		
		if(repStr !="" && repStr !="undefined"){
		
		DelCookie("checkpreviouspage");
		
		var cellText = document.createTextNode(" (works with " +  repStr + ")");
		model2.appendChild(cellText);
		name.appendChild(model2);
		//uncomment the next line to hightlight keywords
		
		//highlightSearchTerms(repStr,1);

		 //var cellTextx = document.createTextNode(repStr+" ");
	     //model2.appendChild(cellTextx);
 		 //var parentDiv = name.parentNode;
		 //parentDiv.insertBefore(model2, name);
	
		}
	}

/*	end of url model function*/
	
    }


// These functions are activated upon page load. They embed JavaScript without function calls from appearing within the HTML.
init = function() {
	start();
	//highlightSearchTerms(1);
}

// Standard Global Fully Browser-compat onload function init call.
if (window.addEventListener)
window.addEventListener("load", init, false)
else if (window.attachEvent)
window.attachEvent("onload", init)
else if (document.getElementById)
window.onload=init;

//highlight function
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}

/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText,treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
 	//var alinkx = new String(window.location);
	//var parameterOfLinkx = alinkx.split("?");
	//if(parameterOfLinkx.length>1){
//	var model3 = new String(parameterOfLinkx[1]);
//	var value = model3.split("model=");

//	var repStrx = new String(value[1]);
	
//	if(repStrx.indexOf("+") != -1){
   		
//		while(repStrx.indexOf("+") != -1){
 //  	 		repStrx = repStrx.replace("+", " ");
 //  		}
			
//  	}else if(repStrx.indexOf("%20") != -1){
//		while(repStrx.indexOf("%20") != -1){
 //   		repStrx = repStrx.replace("%20", " ");
 //  		}
//	 }
		  
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
	}
//}


//hilight function
/*
Hilite={elementid:"content",exact:true,max_nodes:1000,onload:true,style_name:"hilite",style_name_suffix:true,debug_referrer:""};
Hilite.search_engines=[["google\\.","q"],["search\\.yahoo\\.","p"],["search\\.msn\\.","q"],["search\\.live\\.","query"],["search\\.aol\\.","userQuery"],["ask\\.com","q"],["altavista\\.","q"],["feedster\\.","q"],["search\\.lycos\\.","q"],["alltheweb\\.","q"],["technorati\\.com/search/([^\\?/]+)",1],["dogpile\\.com/info\\.dogpl/search/web/([^\\?/]+)",1,true]];

Hilite.decodeReferrer=function(_1)
{var _2=null;var _3=new RegExp("");
for(var i=0;i<Hilite.search_engines.length;i++){var se=Hilite.search_engines[i];_3.compile("^http://(www\\.)?"+se[0],"i");var _6=_1.match(_3);if(_6){var _7;if(isNaN(se[1])){_7=Hilite.decodeReferrerQS(_1,se[1]);}else{_7=_6[se[1]+1];}if(_7){_7=decodeURIComponent(_7);
if(se.length>2&&se[2]){_7=decodeURIComponent(_7);}_7=_7.replace(/\'|"/g,"");_7=_7.split(/[\s,\+\.]+/);return _7;}break;}}return null;};

Hilite.decodeReferrerQS=function(_8,_9)
{var _a=_8.indexOf("?");var _b;if(_a>=0){var qs=new String(_8.substring(_a+1));_a=0;_b=0;
while((_a>=0)&&((_b=qs.indexOf("=",_a))>=0))
{var _d,val;_d=qs.substring(_a,_b);_a=qs.indexOf("&",_b)+1;if(_d==_9){if(_a<=0){return qs.substring(_b+1);}else{return qs.substring(_b+1,_a-1);}}}}return null;};Hilite.hiliteElement=function(_e,_f)
{if(!_f||_e.childNodes.length==0){return;}var qre=new Array();for(var i=0;i<_f.length;i++){_f[i]=_f[i].toLowerCase();if(Hilite.exact){qre.push("\\b"+_f[i]+"\\b");}else{qre.push(_f[i]);}}qre=new RegExp(qre.join("|"),"i");var _12={};for(var i=0;i<_f.length;i++){if(Hilite.style_name_suffix){_12[_f[i]]=Hilite.style_name+(i+1);}else{_12[_f[i]]=Hilite.style_name;}}var _14=function(_15){var _16=qre.exec(_15.data);if(_16){var val=_16[0];var k="";
var _19=_15.splitText(_16.index);var _1a=_19.splitText(val.length);var _1b=_15.ownerDocument.createElement("SPAN");
_15.parentNode.replaceChild(_1b,_19);_1b.className=_12[val.toLowerCase()];_1b.appendChild(_19);return _1b;}else{return _15;}};
Hilite.walkElements(_e.childNodes[0],1,_14);};Hilite.hilite=function(){var q=Hilite.debug_referrer?Hilite.debug_referrer:document.referrer;var e=null;
q=Hilite.decodeReferrer(q);if(q&&((Hilite.elementid&&(e=document.getElementById(Hilite.elementid)))||(e=document.body))){Hilite.hiliteElement(e,q);}};
Hilite.walkElements=function(_1e,_1f,_20){
var _21=/^(script|style|textarea)/i;
var _22=0;while(_1e&&_1f>0){_22++;
if(_22>=Hilite.max_nodes){var _23=function(){Hilite.walkElements(_1e,_1f,_20);};
setTimeout(_23,50);return;}if(_1e.nodeType==1){if(!_21.test(_1e.tagName)&&_1e.childNodes.length>0){_1e=_1e.childNodes[0];_1f++;continue;}}else{if(_1e.nodeType==3){_1e=_20(_1e);}}if(_1e.nextSibling){_1e=_1e.nextSibling;}else{while(_1f>0){_1e=_1e.parentNode;_1f--;if(_1e.nextSibling){_1e=_1e.nextSibling;break;}}}}};if(Hilite.onload){if(window.attachEvent){window.attachEvent("onload",Hilite.hilite);}
else{if(window.addEventListener){window.addEventListener("load",Hilite.hilite,false);}else
{var __onload=window.onload;
window.onload=function(){Hilite.hilite();__onload();};}}}
*/
