// common.js
function ShowDiv(DivName)
{
	if	(document.layers) {
		document.layers[DivName].display="block"; 
		document.layers[DivName].visibility="visible"; 
	} else if (document.getElementById) {
		document.getElementById(DivName).style.display="block";
		document.getElementById(DivName).style.visibility="visible";
	} else if (document.all) {
		document.all(DivName).style.display="block";
		document.all(DivName).style.visibility="visible";	
	}
	
}

function HideDiv(DivName) 
{
	if	(document.layers) {
		document.layers[DivName].display="none"; 
		document.layers[DivName].visibility="hidden"; 
	} else if (document.getElementById) {
		document.getElementById(DivName).style.display="none";
		document.getElementById(DivName).style.visibility="hidden";
	} else if (document.all) {
		document.all(DivName).style.display="none";
		document.all(DivName).style.visibility="hidden";	
	}
}

function findPosLeft(obj)
{
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosTop(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

/* Apply Text box CSS and Error Text Box CSS */

function resetTextBoxCSS(object)
{
	object.style.border='1px solid #7f9db9';
	object.style.background='#ffffff';
}
function applyErrorTextBoxCSS(object)
{
	object.style.border='1px solid red';
	object.style.background='#FFDDDD';
}

/* is a Valid Email */
function isValidEmail (str)
{
  // Return immediately if an invalid value was passed in
  if (str+"" == "undefined" || str+"" == "null")
   return false;

  else
  {
   if (str+"" == "")
 return true;  // email is not required
   else

  str += "";
  namestr = str.substring(0, str.indexOf("@"));  // everything before the '@'
  domainstr = str.substring(str.indexOf("@")+1, str.length); // everything after the '@'

  // Rules:
  // namestr must contain something before the '@'
  // domainstr must contain a period that is not the first character (i.e. right after
  // the '@').
  if ((namestr.length == 0) || (domainstr.indexOf(".") <= 0) || (domainstr.indexOf("@") != -1))
   return false;
  }

 return true;
}


function getObj(name)
{
	if (document.getElementById)
	{
	   this.obj = document.getElementById(name);
	   if (this.obj)
		   this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
	   this.obj = document.all[name];
	   if (this.obj)
		   this.style = document.all[name].style;
	}
	else if (document.layers)
	{
	   if (document.layers[name])
	   {
			this.obj = document.layers[name];
			if (this.obj)
				this.style = document.layers[name];
	   }
	   else
	   {
			this.obj = eval("document.layers." + name + ".layers[name]");
			if (this.obj)
			   this.style = eval("document.layers." + name + ".layers[name]");
	   }
	}
}

function getParentObj(name)
{
	if (parent.document.getElementById)
	{
	   this.obj = parent.document.getElementById(name);
	   if (this.obj)
		   this.style = parent.document.getElementById(name).style;
	}
	else if (parent.document.all)
	{
	   this.obj = parent.document.all[name];
	   if (this.obj)
		   this.style = parent.document.all[name].style;
	}
	else if (parent.document.layers)
	{
	   if (parent.document.layers[name])
	   {
			this.obj = parent.document.layers[name];
			if (this.obj)
				this.style = parent.document.layers[name];
	   }
	   else
	   {
			this.obj = eval("parent.document.layers." + name + ".layers[name]");
			if (this.obj)
			   this.style = eval("parent.document.layers." + name + ".layers[name]");
	   }
	}
}

// tabswticher(X, Y)
// tabsetX_buttonY
// tabsetX_divY
function tabswitcher(strTabSet, intTabID) {
	strButtons = 'tabset_' + strTabSet + '_button';
	strDivs = 'tabset_' + strTabSet + '_div';
	for (i = 1; i <= 10; i++) {
		try {
			var objTab = document.getElementById(strButtons + i);
			var objLayer = document.getElementById(strDivs + i);
			
			if (i == intTabID) {
				objTab.className = 'on';
				objLayer.style.display = 'block';
			} else {
				objTab.className = '';
				objLayer.style.display = 'none';
			}
		} catch(e) { i = 100; }
	}
}

// Used to work out window width and height
var windowState = (function(){
var readScroll = {scrollLeft:0,scrollTop:0};
var readSize = {clientWidth:0,clientHeight:0};
var readScrollX = 'scrollLeft';
var readScrollY = 'scrollTop';
var readWidth = 'clientWidth';
var readHeight = 'clientHeight';
function otherWindowTest(obj){
if((document.compatMode)&&(document.compatMode == 'CSS1Compat')&&(document.documentElement)){
return document.documentElement;
}else if(document.body){
return document.body;
}else{
return obj;
}
};
if((typeof this.innerHeight == 'number')&&(typeof this.innerWidth == 'number')){
readSize = this;
readWidth = 'innerWidth';
readHeight = 'innerHeight';
}else{
readSize = otherWindowTest(readSize);
}
if((typeof this.pageYOffset == 'number')&&(typeof this.pageXOffset == 'number')){
readScroll = this;
readScrollY = 'pageYOffset';
readScrollX = 'pageXOffset';
}else{
readScroll = otherWindowTest(readScroll);
}
return {
getScrollX:function(){
return (readScroll[readScrollX]||0);
},
getScrollY:function(){
return (readScroll[readScrollY]||0);
},
getWidth:function(){
return (readSize[readWidth]||0);
},
getHeight:function(){
return (readSize[readHeight]||0);
}
};
})();

// PM page navigation
function FriendlyPrint(id,Did)
{
	window.open("/alto-mitsubishi/print_friendly.asp?news_id="+id+"&dealer_id="+Did,"","menubar=no,scrollbars=yes, resizable=no");
}

function FriendlyPrintDemo(id)
{
	window.open("/alto-mitsubishi/demo_print_friendly.asp?demo_id="+id,"","menubar=no,scrollbars=yes,width=980,height=610, resizable=no");
}

function ContactPrint()
{
	window.open("/alto-mitsubishi/contact_print_friendly.asp","","menubar=no,scrollbars=yes,width=20000,height=600, resizable=no");
}

