function MakeUpperCase(element, forceZero)
{
	element.value = element.value.toUpperCase();
	
	if(forceZero)
	{
		element.value = element.value.replace("O", "0");
	}
}

function IsDTCOBD1(dtcValue, manufacturerName, year)
{
	var isCodeValid = false;
	var validationExpression = "";

	if(!manufacturerName)
	{
		manufacturerName = "";
	}
	
	if(!year || year <= 1995)
	{
		switch(manufacturerName.toLowerCase())
		{
			case "gm":
			case "isuzu":
			case "chrysler":
			case "jeep":
			case "nissan":
			case "infinity":
				validationExpression = "^[0-9]{2,2}$";
				break;

			case "ford":
			case "lincoln":
			case "mercury":
				validationExpression = "^[0-9]{2,3}$";
				break;
				
			case "honda":
			case "acura":
			case "toyota":
			case "lexus":
				validationExpression = "^[0-9]{1,2}$";
				break;
				
			default:
				validationExpression = "^[0-9]{1,3}$";
				break;
		}
	}

	if(validationExpression != "")
	{

		if (dtcValue == "")
		{
			isCodeValid = true;
		}
		else
		{
			var regExMatch = dtcValue.match(dtcValue, validationExpression);

			if (regExMatch != null)
			{
				isCodeValid = true;
			}
		}
	}

	return isCodeValid;
}

function IsDTCOBD2(dtcValue, manufacturerName, year)
{
	var isCodeValid = false;
//	var validationExpression = "^[bcpuBCPU]{1}[0-9]{1}[0-9a-fA-F]{3}$";
	var validationExpression = "^[bcpuBCPU]{1}[\da-zA-Z]{4}$|^[bcpBCP]{1}[\d]{4}[\da-zA-Z]{2}$|^[\da-zA-Z]{2}-[\da-zA-Z]{2}$|^\d{1,2}$";

	if(!manufacturerName)
	{
		manufacturerName = "";
	}
	
	switch(manufacturerName.toLowerCase())
	{
		case "gm":
		case "ford":
		case "chrysler":
		case "toyota":
			if(year)
			{
				if(year < 1994)
				{
					validationExpression = "";
				}
			}
			break;

		default:
			if(year)
			{
				if(year && year < 1996)
				{
					validationExpression = "";
				}
			}
			break;
	}

//	alert(validationExpression);

	if(validationExpression != "")
	{
		if (dtcValue == "")
		{
			isCodeValid = true;
		}
		else
		{
			var regExMatch = dtcValue.match(dtcValue, validationExpression);

			if(regExMatch != null)
			{
				isCodeValid = true;
			}
		} 
	}
	return isCodeValid;
}

function IsDTCValid(dtcValue, manufacturerName, year)
{
	return (IsDTCOBD1(dtcValue, manufacturerName, year) || IsDTCOBD2(dtcValue, manufacturerName, year));
}


function FormatPhoneNumber(localEvent, textboxElement)
{
	var keyCode = 0;
	
	if(navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4)
	{	
		if(localEvent.which)
		{
			keyCode = localEvent.which;
		}
	}
	else
	{
		if(!localEvent)
		{
			localEvent = window.event;
		}
		
		keyCode = localEvent.keyCode;
	}
	
	//textboxElement.value.length <= 11 && 
	if(keyCode >= 48 && keyCode <= 57)
	{
		if(textboxElement.value.length == 2)
		{
			textboxElement.value = textboxElement.value + String.fromCharCode(keyCode) + "-";
			localEvent.returnValue = false;
		}
		else if(textboxElement.value.length == 6)
		{
			textboxElement.value = textboxElement.value + String.fromCharCode(keyCode) + "-";
			localEvent.returnValue = false;
		}
		else
		{	
			var regex = new RegExp(/\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})/);
		
			var phoneNumber		= textboxElement.value + String.fromCharCode(keyCode);
			var matches			= phoneNumber.match(regex);
		
			if(matches && matches.length == 4)
			{
				textboxElement.value = matches[1] + "-" + matches[2] + "-" + matches[3];
				localEvent.returnValue = false;
			}
		}
	}
	else
	{
		localEvent.returnValue = false;
	}
}


function GetLeftPosition(obj)
{
	var currentLeft = 0;

	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			currentLeft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if(obj.x)
	{
		currentLeft += obj.x;
	}
	
	return currentLeft;
}


function GetTopPosition(obj)
{
	var currentTop = 0;
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			currentTop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if(obj.y)
	{
		currentTop += obj.y;
	}
	
	return currentTop;
}


function ChangeCss(theClass, element, value)
{
	//Last Updated on June 23, 2009
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	var cssRules;

	var added = false;
	for(var S = 0; S < document.styleSheets.length; S++)
	{
		if(document.styleSheets[S]['rules'])
		{
			cssRules = 'rules';
		}
		else if(document.styleSheets[S]['cssRules'])
		{
			cssRules = 'cssRules';
		}
		else
		{
			//no rules found... browser unknown
		}

		for(var R = 0; R < document.styleSheets[S][cssRules].length; R++)
		{
			if(document.styleSheets[S][cssRules][R].selectorText == theClass)
			{
				if(document.styleSheets[S][cssRules][R].style[element])
				{
					document.styleSheets[S][cssRules][R].style[element] = value;
					added = true;
					break;
				}
			}
		}

		if(!added)
		{
			if(document.styleSheets[S].insertRule)
			{
				document.styleSheets[S].insertRule(theClass + ' { ' + element + ': ' + value + '; }', document.styleSheets[S][cssRules].length);
			} else if(document.styleSheets[S].addRule)
			{
				document.styleSheets[S].addRule(theClass, element + ': ' + value + ';');
			}
		}
	}
};

function IsIE8Browser()
{
	var rv = -1;
	var ua = navigator.userAgent;
	var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");

	if(re.exec(ua) != null)
	{
		rv = parseFloat(RegExp.$1);
	}

	return (rv == 4);
};

function IsIEBrowserZoomed()
{
	var isZoomed = false;

	if(navigator.appVersion.indexOf("MSIE") > 0)
	{
		if(IsIE8Browser())
		{
			isZoomed = (window.screen.deviceYDPI != 96);
		}
		else if(navigator.appVersion.indexOf("MSIE 7") > 0)
		{
			var rect = document.body.getBoundingClientRect();
			var zoomLevel = Math.round((rect.right - rect.left) / document.body.clientWidth * 100);
			isZoomed = (zoomLevel < 95 || zoomLevel > 105);
		}
	}

	return isZoomed;
};

