// JavaScript Document
var core = {
	isMSIE: navigator.appName == "Microsoft Internet Explorer" ? true : false,
	isFF: !document.all && document.getElementById && !this.isOpera,
	isOpera: navigator.appName == "Opera" ? true : false,
	trim: function(str) {
		return str.replace(/^\s*|\s*$/g,"");
	},
	 create:function(strType){
		return document.createElement(strType); 
		 
	 },
	includeJS: function(file) {
		var script = document.createElement("script");
		script.type='text/javascript';
		script.src=file;
		//script.setAttribute(script, "type", "text/javascript");
		//script.setAttribute(script, "src", file);
		var heads = document.getElementsByTagName("head");
		var extention = file.toLowerCase().lastIndexOf(".js");
		if(extention == -1){return false;}
		for(var i=0;i<heads.length;i++) {
			heads[i].appendChild(script);		
			//heads[i].insertBefore(script,heads[i].firstChild);
		}
	},
	includeCSS: function(path) {
		var link = document.createElement("link");
		link.rel='stylesheet';
		link.type='text/css';
		link.href=path;
//		this.setAttribute(link, "rel", "stylesheet");
//		this.setAttribute(link, "type", "text/css");
//		this.setAttribute(link, "href", path);
		var extention = file.toLowerCase().lastIndexOf(".css");
		if(extention == -1){return false;}
		var heads = document.getElementsByTagName("head");
		for(var i=0;i<heads.length;i++) {
			heads[i].appendChild(link);		
		}
	},
	addEvent:function(obj, ev, fu) {
		if (obj.attachEvent)
			obj.attachEvent("on" + ev, fu);
		else
			obj.addEventListener(ev, fu, false);
	},
	removeEvent:function(obj, ev, fu) {
		if (obj.attachEvent)
			obj.detachEvent("on" + ev, fu);
		else
			obj.removeEventListener(ev, fu, false);
	},
	/**
	 * Determine if the given parameter is defined
	 * 
	 * @param p Parameter
	 * @return true/false dependents on definition of the parameter 
	 
	isdefined:function(p) {
		return typeof p == "undefined" ? false : true;	
	},*/
	isnull:function(p){
		return p==null ? true : false;
	},
	isArray:function(obj) {
	  return obj.constructor.toString().indexOf("Array") == -1 ? true : false;
	},
	$:function(strid){
		return document.getElementById(strid);	
	},
	ready:function(fn){
		try{
			
			this.addEvent(window,'load', function(){fn();});
			
		}
		catch(exception){
			//alert(exception);
		}
	},
	loadJQuery:function(strLocation){
		if(strLocation==null){
			strLocation="http://scripts.lunaweb.net/jquery-1.2.6.min.js";	
		}
		this.includeJS(strLocation);
	},
	loadRemote:function(strFileName){
		if(strFileName!=null){
			strLocation="http://scripts.lunaweb.net/"+strFileName;
			this.includeJS(strLocation);
		}
	}
	
}
//alias to core
var omni=core;
function ajaxobj()
{
	var me = this;
	this.postInfo=null;
	this.loadingHtml="";
	this.onFinish="";
	this.onReady=function(){};
	
	this.setPostInfo=function(info){me.postInfo = info;}
	this.setLoadHtml=function(html){me.loadingHtml=html;}
	this.setOnFinish=function(job){me.onFinish=job;}
	
	this.GetXmlHttpObject = function()
		{var xmlHttp=null;
		  try{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();}
		  catch (e){
			// Internet Explorer
			try{
			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e){
			  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
			}
		  return xmlHttp;
		} 
	
	this.stateListen=function(xho,target){
		if(xho.readyState==4){
			var response = xho.responseText;
			if(target!=null){
			target.innerHTML=response;
			}
			if(me.onFinish!=""){eval(me.onFinish);}
			me.onReady(response);
		}
	}
	
	this.send=function(url,container){
			var xho =me.GetXmlHttpObject();
			if(xho==null){alert("No object."); return false;}
			var target =core.$(container);
			if(container==null){container="";}
			if(me.loadingHtml!=""){
				if(target!=null){
				target.innerHTML = me.loadingHtml;
				}
			}
			if(url.indexOf("?")>=0){url+="&rid=" + Math.random();}
			else{url+="?rid=" + Math.random();}
			//if(container==""){alert("There is no container.");}
			xho.onreadystatechange=function(){
				me.stateListen(xho,target);
				}
			if(me.postInfo==null){
				xho.open("GET",url,true);
				xho.send(null);
			}else{
				xho.open("POST",url,true);
				xho.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
				xho.send(me.postInfo);
			}
			
		}//end send
		
	this.getFormInfo=function(oForm){
		if(oForm==null){oForm=document.forms[0];}	
		if(oForm!=null){
			var strReturn='';
			var elementType='';
			for(i=0;i<oForm.length;i++)
			{
				if(oForm.elements[i].name !=''){
						elementType=oForm.elements[i].type;
						if(elementType!='radio' && elementType!='checkbox'){
							if(i>0 && i+1 <oForm.length){strReturn+="&";}
							strReturn+=oForm.elements[i].name +"="+	encodeURI(oForm.elements[i].value);
						}
						else if((elementType=='radio'||elementType=='checkbox') && oForm.elements[i].checked==true)
						{//is radio
							if(i>0 && i+1 <oForm.length){strReturn+="&";}
							strReturn+=oForm.elements[i].name +"="+	encodeURI(oForm.elements[i].value);
						}
				}//end if name !=''
			}//end for
			return strReturn;
		}
		else{//oForm ==null
			return false;
		}
	}//end getFormInfo
		
}//end ajaxobj



function ajaxwindow()
{
	var me =this;
	this.screen = document.createElement("div");
	this.screen.style.cssText="top:0px;left:0px;filter:alpha(opacity=60);opacity:0.6;width:110%;height:1500px;position:absolute; z-index:500; background-color:#000000; display:none;";
	this.wndow = document.createElement("div");
	this.wndow.style.cssText="top:25%; left:30%; position:absolute; z-index:600; display:none;";
	this.width = 500;
	this.height=400;
	this.bgColor='#FFFFFF';
	this.winid=null;
	this.draw=function(){
		//document.body.insertBefore(me.screen, document.body.firstChild);
		me.wndow.style.width=me.width+"px";
		me.wndow.style.height=me.height+"px";
		me.wndow.style.backgroundColor=me.bgColor;
		if(me.winid==null){
			me.wndow.id = "divscreenWindow";
		}else{
			me.wndow.id=me.winid;
		}
		
		core.addEvent(window,'load',function(){
			document.body.insertBefore(me.screen, document.body.firstChild);
			document.body.insertBefore(me.wndow, document.body.firstChild);
		});
		
	}
	this.show=function(){
		me.screen.style.display="block";
		me.wndow.style.display="block";
	}
	this.hide=function(){
		me.screen.style.display="none";
		me.wndow.style.display="none";
	}
}// end ajaxwindow

function openWin(strWin,strOpts){
	if(strOpts==null){
		strOpts="width=1000,height=800,scrollbars=yes";	
	}
	window.open(strWin,'',strOpts);
}
function openUsedTruckWin(){
	//var w=window.open('http://www.truckpaper.com/email.asp?emid=947300','utrucks','width=700,height=500,scrollbars=yes');
	openWin('http://www.truckpaper.com/email.asp?emid=947300');	
}

