function AttachEvent(elementObj, eventName, eventHandlerFunctionName)
{
if (elementObj != null){
  if (elementObj.addEventListener)
  { // Non-IE browsers
    elementObj.addEventListener(eventName, eventHandlerFunctionName, false);
  }
  else if (elementObj.attachEvent)
  { // IE 6+
    elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);
  }
  else
  { // Older browsers
    var currentEventHandler = elementObj['on' + eventName];
    if (currentEventHandler == null)
    {
      elementObj['on' + eventName] = eventHandlerFunctionName;
    }
    else
    {
      elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
    }
  }
}
}

function getESTHour()
{
	var date = new Date();
	date = new Date(Date.UTC(date.getUTCFullYear(),date.getUTCMonth(),date.getUTCDate(),date.getUTCHours(),date.getUTCMinutes(),date.getUTCSeconds()) - 18000000);
	var dsti = 14 - (Math.floor (1 + date.getUTCFullYear() * 5 / 4) % 7);
	var dste = 7 - (Math.floor (1 + date.getUTCFullYear() * 5 / 4) % 7);
	var tmpi = new Date(Date.UTC(date.getUTCFullYear(), 2, dsti, 2));
	var tmpe = new Date(Date.UTC(date.getUTCFullYear(), 10, dste, 2));
	if ((date.getTime() >= tmpi.getTime()) && (date.getTime() <= tmpe.getTime())) date = new Date(Date.UTC(date.getUTCFullYear(),date.getUTCMonth(),date.getUTCDate(),date.getUTCHours(),date.getUTCMinutes(),date.getUTCSeconds()) + 3600000);
	return date.getUTCHours();
}

/* pop-up function. only needs a url and winName parameter -- attributes are defaulted.
it is recommended that call to function at least include width and height attributes.
any attribute passed in will take precedence over default. -- dtw 8/5/05 */

function popUpWindow(url,winName,attributes)
{
	if (attributes.indexOf("directories") == -1) { attributes += ",directories=0"; }
	if (attributes.indexOf("location") == -1) {	attributes += ",location=0"; }
	if (attributes.indexOf("menubar") == -1) { attributes += ",menubar=0"; }
	if (attributes.indexOf("resizable") == -1) { attributes += ",resizable=0"; }
	if (attributes.indexOf("scrollbars") == -1) { attributes += ",scrollbars=1"; }
	if (attributes.indexOf("status") == -1) { attributes += ",status=0"; }
	if (attributes.indexOf("toolbar") == -1) { attributes += ",toolbar=0"; }
	if (attributes.indexOf("top") == -1) { attributes += ",top=80";	}
	if (attributes.indexOf("left") == -1) { attributes += ",left=50"; }

	var newWindow = window.open(url,winName,attributes);
	if (window.focus) { newWindow.focus() }
}

/* generic name/value pair function
 return a hash (of sorts) of name value pairs from the querystring
 uasge: var qsParams = getQsParams();
 then: qsParams['url'] whould equal whatever url=XXX in the querystring*/

function getQsParameters()
{
	var qs = location.search;
	qs = qs.substring(1);
	// create an 'array' called newArray with the name value pairs from the querystring
	var qsArray = new Array;
	qsArray = qs.split('&'); //creating an array in which the values are separated by ampersands in the code//
	var keyValueArray = new Array; //this one loads the names and values into a hash (of sorts)//
	for(i=0; i<qsArray.length; i++)
	{
		var nameValue = qsArray[i].split('='); //splitting what we find between each ampersand into key value pairs //
		keyValueArray[nameValue[0]] = unescape(nameValue[1]); //we are then turning all the escaped characters back into the 'real thing' ie. %3F turns into a '?' //
	}
	return keyValueArray;
}

/*
Cookie functions------------------------------------
*/

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		//alert(value);
	} else
	{
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function interstitial(url){
			PositionedWin(url,'450','300','scrollbars=0,status=0,menubar=0,resizable=0','Interstitial');
			//alert (document.getElementById(src).value);
		}

//Get the parametro thought URL (Mime) ej ?parameter=value :: getParameter('parameter')
function getParameter(parameter){
	if(parameter==null)
		return (null);
	if(location.href.indexOf(parameter)==-1)
		return (null);
	var url = location.href;
	var index = url.indexOf("?");
	index = url.indexOf(parameter,index) + parameter.length;
	if (url.charAt(index) == "="){
		var result = url.indexOf("&",index);
		if (result == -1){result=url.length;};
			return(url.substring(index + 1,result));
	}
}

function flashSupportBrowser(useFlashVersion) {
	if (useFlashVersion != "N") {
		if (!hasFlash && !document.location.href.match("useFlash=N")) {
			var pathMode = ""
			if (document.location.href.indexOf("?") > -1){
				pathMode = document.location.href.replace("useFlash=N", "");
				pathMode = pathMode.replace("useFlash=Y", "");
				pathMode = pathMode + "&useFlash=N";
				pathMode = pathMode.replace("?&", "?");
			} else {
				pathMode = document.location.href + "?useFlash=N";
			}
			document.location.href = pathMode;
		}
	}
}

//Get the relative path of the URL. Eg:
//http://www.pontiac.com/byoCustomizeVehicle.do return http://www.pontiac.com
function getRelativePath(){
	var Str = document.location.href;
	var newStr = "";
	var index=0;
	for(i=0;i<Str.length;i++){
		if(!(Str.charAt(i)=="/" && i > 6)){
			newStr = newStr + Str.charAt(i);
		}else{
			i=Str.length;
		}
	}
	return newStr;
}

//Remplace (String funcion)
function replaceAll(str, rep1, rep2 ) {
	var idx = str.indexOf(rep1);
	while ( idx > -1 ) {
		str = str.replace( rep1, rep2 );
		idx = str.indexOf( rep1 );
	}
	return str;
}

//Save the cookie, param: Array with information
function saveCookie(key,data){
	try{
		createCookie(key,JSON.stringify(data),1);
	}catch(e){}
}

//Load the data from the cookie
function loadCookie(key){
	try{
		data = readCookie(key);
		if(data!=null){
			data = JSON.parse(data);
		}
		return data;
	}catch(e){}
}

//Variables Optimus for RAQ
var OPTIMUSCOOKIENAME = "OptimusCookie";
var OPTIMUSVARIABLES = new Array();
OPTIMUSVARIABLES[0] = "evar1";
OPTIMUSVARIABLES[1] = "seo";
OPTIMUSVARIABLES[2] = "cmp";

//Handler the cookies
function RaqCookieOptimus(){
	var BLANK = "";
	var cookie;
	cookie = loadCookie(OPTIMUSCOOKIENAME);
	if(cookie==null){
		cookie = getBlankCookieOptimus();
	}
	for(optimusi=0;optimusi<OPTIMUSVARIABLES.length;optimusi++){
		tmp = getParameter(OPTIMUSVARIABLES[optimusi]);
		if(tmp==null){
			tmp = BLANK;
			if((cookie[optimusi][1] != BLANK)){
				tmp = cookie[optimusi][1];
			}
		}
		cookie[optimusi] = new Array(OPTIMUSVARIABLES[optimusi],tmp);
	}
	saveCookie(OPTIMUSCOOKIENAME,cookie);
}

//Set the cookies in blank
function getBlankCookieOptimus(){
	var BLANK = "";
	var cookie = new Array();
	for(optimusi=0;optimusi<OPTIMUSVARIABLES.length;optimusi++){
		cookie[optimusi] = new Array(OPTIMUSVARIABLES[optimusi],BLANK);
	}
	return cookie;
}

//Redirect function
function redirectCommon(urlpath){
	try{
		setTimeout("location.href = '" + urlpath + "'",500);
	}catch(e){
		alert(e);
	}
}

RaqCookieOptimus();