utils = function(){
	this.urls = []; // event target id,url
	this.baseURL = (typeof(baseURL) != 'undefined') ? baseURL : 'http://espanol.boostmobile.com/sdplans/';
	this.comBaseURL = (typeof(comBaseURL) != 'undefined') ? comBaseURL : 'http://espanol.boostmobile.com/dboostmobilestore/bpdirect/boost/';
	this.secureURL = (typeof(secureURL) != 'undefined') ? secureURL : 'https://espanol.boostmobile.com/dboostmobilestore/bpdirect/boost/';
	this.urls['zipCheck'] = this.baseURL + 'zip_map_handler.aspx';
	this.urls['emailSubmit'] = this.baseURL + 'email_capture_handler.aspx';
	this.urls['hdr_step1'] = this.baseURL + '';

	this.urls['hdr_step2'] = this.urls['phonesButton'] = this.comBaseURL + 'PhoneList.do?action=view';
	this.urls['hdr_step3'] = this.baseURL + 'start_services.html';
	this.urls['accessoriesButton'] = this.comBaseURL + 'AccessoriesList.do?action=view';
	this.urls['thumb'] = this.comBaseURL + 'Start.do?action=view';
	this.urls['checkOutButton'] = this.urls['btnPromoViewCart'] = this.urls['btnPromoCheckOut'] = this.secureURL + 'BillShip.do?action=view';
	this.urls['samplePhoto'] = 'images/Mar23_0005.jpg';
	this.urls['addPhone'] = this.comBaseURL + 'AddPhone.do?action=view';
	this.urls['updateCart'] = this.comBaseURL + 'UpdateCart.do?action=view'; //same on phonelist and accessories page
	this.urls['updateCartOnCheckOut'] = this.secureURL + 'UpdateCart.do?action=view';
	this.urls['selectShipping'] = this.secureURL + 'ShippingCosts.do?action=view';
	this.urls['choose_a_phone_addAccessory'] = this.urls['addPhone'];
	this.urls['accessories_addAccessory'] = this.comBaseURL + 'AddAccessory.do?action=view';
}

utils.prototype.setCookie = function( name, value, expires, path, domain, secure ){
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) expires = expires * 1000 * 60 * 60 * 24 
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" ); 
}

	// this function gets the cookie, if it exists
utils.prototype.getCookie = function( name ){
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&	( name != document.cookie.substring( 0, name.length ) ) ){
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

	// this deletes the cookie when called
utils.prototype.deleteCookie = function( name, path, domain ){
	if ( this.getCookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

utils.prototype.getMovie = function ( movieName ){
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName];
  }	else {
    return document[movieName];
  }
}

utils.prototype.flashSetVar = function( movie, name, val ){
	var movie = (typeof(movie) == 'string') ? this.getMovie(movie) : movie
	try { 	movie.SetVariable( name,val) }catch(err){}
}

utils.prototype.regExTest = function(string,exp){
	var regEx = new RegExp(exp);
	return regEx.test(string);
}

utils.prototype.arrayContains = function(arr,el){
	for (var i = 0; i < arr.length; i++) {
		if (arr[i] == el) return true;
	}
	return false
}

utils.prototype.stripUnmatchingChars = function( pattern,str ){ 
	var c =	str.length;
	var l = new String;
	for (var i = 0;i < c ;i++) {
		l = str.substr(i,1); 
		if (!pattern.test(l)) { 
			if(i == 0) str =		str.substr(i+1);
			else str = str.substring(0,i) + str.substr(i+1);
		}
	}
	return str;
}

utils.prototype.getQueryValue= function( key ){
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (key == pair[0]) {
      return pair[1];
    }
  } 
 	return null;
}

utils.prototype.locationReplace = function( url ){
	(location.href.assign) ? location.href.assign(url) : location.href = url;
}

utils.prototype.goToURL = function( evt ){
	var evt = doc.dhtml.getEvent(evt);
	var id  = doc.dhtml.getTargetId(evt);
	switch (evt.type) {
		case 'mouseover':
			doc.dhtml.swapImgBySrc(null,id,'on');
			return;
			break;
		case 'mouseout':
			doc.dhtml.swapImgBySrc(null,id,'off');
			return;
			break;
		case 'click':
			if(id.indexOf('thumb') > -1) id = 'thumb';
			if(typeof(doc.tracking) != 'undefined') doc.tracking.sendSClickHit(doc.tracking.pageCode + '_' + id);			
			var url = doc.utils.urls[id]
			var pairs = [];
	
			if(typeof(session) != 'undefined'){
				if(session.zip) pairs.push('zip=' + session.zip);
				if(session.viewingModel) pairs.push('id=' + session.viewingModel);
				if(session.bpProductId) pairs.push('bpProductId=' + session.brProductId);
			}

			for(var i = 0; i < pairs.length; i++){
				if(i == 0){
					if(url.indexOf('?') < 0 ) url += '?' + pairs[i];
					else  url += '&' + pairs[i];
				}	else url += '&' + pairs[i];
			}
			doc.utils.locationReplace(url);
			break;
	}		
}


