
// JavaScript Document
/* This file contains Javascript and YUI JS components for Pubilc Storage */


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

//array to store all global variables - easier to manage
YAHOO.namespace("ps");
//global alias for root namespace
var psui = YAHOO.ps;
//global alias for log object
var pslog = YAHOO.log;
//construct to hold all global variables in assocoative array
//register all global variables to this array
//eg. psui.globals['myGlobalVar'] = CONSTANT / Object / Variable
psui.globals=new Array;

//define namespaces for other functional groupins
YAHOO.namespace("ps.searchResults");
YAHOO.namespace("ps.order");
var browserName = whichBrs();
function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("firefox") != -1) return 'Firefox';
}

//array of regular expressions for client side form validation.
psui.arrRegExp = [];
psui.arrRegExp['alphaNumeric'] = /^[a-zA-Z0-9]+$/;  //expression to match alpha numeric
psui.arrRegExp['numeric'] = /^[0-9]+$/;  //expression to match  numeric
//This regular expressions matches dates of the form XX/XX/YYYY where XX can be 1 or 2 digits long and YYYY is always 4 digits long
psui.arrRegExp['dateFormat'] = /^\d{1,2}\/\d{1,2}\/\d{4}$/; 
psui.arrRegExp['emailPattern'] = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
psui.arrRegExp['illegalChars'] = /\W/;   // allow only letters, numbers, and underscores
psui.arrRegExp['usZip'] = /^\d{5}$|^\d{5}-\d{4}$/;
//5 digit ZIP code or a ZIP+4 code formatted as 5 digits, a hyphen, and another 4 digits
//psui.arrRegExp['usStreetAddressComplete'] = /^(?n:(?<address1>(\d{1,5}(\ 1\/[234])?(\x20[A-Z]([a-z])+)+ )|(P\.O\.\ Box\ \d{1,5}))\s{1,2}(?i:(?<address2>(((APT|B/;


// -- Standard functions
// array methods to allow for a rich set of array manipulation methods
// regardless of Javascript / Browser version.

// Array.concat() - Join two arrays
if( typeof Array.prototype.concat==='undefined' ) {
 Array.prototype.concat = function( a ) {
  for( var i = 0, b = this.copy(); i<a.length; i++ ) {
   b[b.length] = a[i];
  }
  return b;
  };
};

// Array.copy() - Copy an array
if( typeof Array.prototype.copy==='undefined' ) {
 Array.prototype.copy = function() {
  var a = [], i = this.length;
  while( i-- ) {
   a[i] = typeof this[i].copy!=='undefined' ? this[i].copy() : this[i];
  }
  return a;
 };
};

// Array.pop() - Remove and return the last element of an array
if( typeof Array.prototype.pop==='undefined' ) {
 Array.prototype.pop = function() {
  var b = this[this.length-1];
  this.length--;
  return b;
 };
};

// Array.push() - Add an element to the end of an array, return the new length
if( typeof Array.prototype.push==='undefined' ) {
 Array.prototype.push = function() {
  for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
   this[b+i] = a[i];
  }
  return this.length;
 };
};

// Array.shift() - Remove and return the first element
if( typeof Array.prototype.shift==='undefined' ) {
 Array.prototype.shift = function() {
  for( var i = 0, b = this[0], l = this.length-1; i<l; i++ ) {
   this[i] = this[i+1];
  }
  this.length--;
  return b;
 };
};

// Array.slice() - Copy and return several elements
if( typeof Array.prototype.slice==='undefined' ) {
 Array.prototype.slice = function( a, c ) {
  var i, l = this.length, r = [];
  if( !c ) { c = l; }
  if( c<0 ) { c = l + c; }
  if( a<0 ) { a = l - a; }
  if( c<a ) { i = a; a = c; c = i; }
  for( i = 0; i < c - a; i++ ) { r[i] = this[a+i]; }
  return r;
 };
};

// Array.splice() - Remove or replace several elements and return any deleted elements
if( typeof Array.prototype.splice==='undefined' ) {
 Array.prototype.splice = function( a, c ) {
  var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
  if( !c ) { c = l - a; }
  for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
  for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
  this.length -= c - e.length + 2;
  return d.slice( f, f + c );
 };
}

// Array.unshift() - Add an element to the beginning of an array
if( typeof Array.prototype.unshift==='undefined' ) {
 Array.prototype.unshift = function() {
  this.reverse();
  var a = arguments, i = a.length;
  while(i--) { this.push(a[i]); }
  this.reverse();
  return this.length;
 };
};


// Array.forEach( function ) - Apply a function to each element
Array.prototype.forEach = function( f ) {
 var i = this.length, j, l = this.length;
 for( i=0; i<l; i++ ) { if( ( j = this[i] ) ) { f( j ); } }
};

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
Array.prototype.insert = function( i, v ) {
 if( i>=0 ) {
  var a = this.slice(), b = a.splice( i );
  a[i] = v;
  return a.concat( b );
 }
};

// Array.lastIndexOf( value, begin, strict ) - Return index of the last element that matches value
Array.prototype.lastIndexOf = function( v, b, s ) {
 b = +b || 0;
 var i = this.length; while(i-->b) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.random( range ) - Return a random element, optionally up to or from range
Array.prototype.random = function( r ) {
 var i = 0, l = this.length;
 if( !r ) { r = this.length; }
 else if( r > 0 ) { r = r % l; }
 else { i = r; r = l + r % l; }
 return this[ Math.floor( r * Math.random() - i ) ];
};

// Array.shuffle( deep ) - Randomly interchange elements
Array.prototype.shuffle = function( b ) {
 var i = this.length, j, t;
 while( i ) {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }
 return this;
};

// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 }
 return a;
};

// Array.walk() - Change each value according to a callback function
Array.prototype.walk = function( f ) {
 var a = [], i = this.length;
 while(i--) { a.push( f( this[i] ) ); }
 return a.reverse();
};

//error message function
//arg 1 = target element id or object
//arg 2 = string for innerHTML to be output.
psui.errorMessage = function() {
	var targetElement = arguments[0];
	var strInnerHTML = arguments[1];
	if(strInnerHTML=='') {
		YAHOO.util.Dom.setStyle(targetElement,'display','none');
	} else {
		YAHOO.util.Dom.setStyle(targetElement,'display','block');
		}
	(YAHOO.util.Dom.get(targetElement)).innerHTML = strInnerHTML;
}
//print helper functions:
psui.updatePrintView = function(id,value) {
    var zipCodeView = (YAHOO.util.Dom.get(id));
    if (zipCodeView){
	    zipCodeView.innerHTML = value;
	}
}

psui.updatePrintViewCheckBox = function(checkboxList,idTarget) {
	var strBuffer = "";
	for(chkIndex=0;chkIndex<checkboxList.length;chkIndex++) {
		if(checkboxList[chkIndex].checked==true) {
		//add value to list
		strBuffer = strBuffer + checkboxList[chkIndex].value + '<br />';
		} 
	}
	if ((YAHOO.util.Dom.get(idTarget)) != null){
		(YAHOO.util.Dom.get(idTarget)).innerHTML = strBuffer;
	}
}

//generate query

psui.generateCheckBoxQueryStringSize= function (checkboxList) {
		var checkSizeQuery ="";
	for(chkIndex=0;chkIndex<checkboxList.length;chkIndex++) {
		if(checkboxList[chkIndex].checked==true ) {
			checkSizeQuery += checkboxList[chkIndex].value + ','  }
		}
		 var checkSizeQuery = ((checkSizeQuery.charAt(checkSizeQuery.length-1,1) == ",") ? checkSizeQuery.substring(0,checkSizeQuery.length-1) : checkSizeQuery);
		  return checkSizeQuery; 
}

psui.generateCheckBoxQueryStringFeature= function (checkboxList) {
		var checkFeatureQuery ="";
	for(chkIndex=0;chkIndex<checkboxList.length;chkIndex++) {
		if(checkboxList[chkIndex].checked==true ) {
			checkFeatureQuery += checkboxList[chkIndex].value + ','  }
		}

		 var checkFeatureQuery = ((checkFeatureQuery.charAt(checkFeatureQuery.length-1,1) == ",") ? checkFeatureQuery.substring(0,checkFeatureQuery.length-1) : checkFeatureQuery);
		  return checkFeatureQuery; 

	
}



//toggle visibility
psui.toggleDisplay = function() {
	var arrElements = [];
	var input = arguments[0];
	if(YAHOO.lang.isArray(input)) {
		//we are passed an array of elements, or element IDs
		for(inputIter=0;inputIter<input.length;inputIter++) {
			if(YAHOO.lang.isObject(input[inputIter])) {
				arrElements[arrElements.length] = input[inputIter];
			} else if(YAHOO.lang.isString((input[inputIter]))) {
				arrElements[arrElements.length] = YAHOO.util.Dom.get((input[inputIter]));	
			}
		}
	} else if(YAHOO.lang.isString(input)) {
		arrElements[0] = YAHOO.util.Dom.get(input);	
	} else if(YAHOO.lang.isObject(input)) {
		arrElements[0] = input;
	}
	for(elemIter=0;elemIter<arrElements.length;elemIter++) {
		var element = arrElements[elemIter];
		var attribDisplay = YAHOO.util.Dom.getStyle(element,'display');
		if(attribDisplay == 'block') {
			YAHOO.util.Dom.setStyle(element,'display','none');
		} else if(attribDisplay == 'none') {
			YAHOO.util.Dom.setStyle(element,'display','block');		
		}
	}
}
//cart and cookie management objects and methods

psui.createCookie = function(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

psui.readCookie= function(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;
}

psui.eraseCookie = function(name) {
	createCookie(name,"",-1);
}

//order data model
psui.globals['orderCookie'] = 'psOrderCookie';

//unit data structure
psui.order.objUnit = function() {
    this.SizeId = '';
    this.TransactionType = '';
    this.StartDate = '';
    this.HasInsurance = '';  //boolean to store true or false if insurance is purchased for this unit
    this.InsuranceType = ''; // reference to an insurance object
    this.Description = '';
    this.ProductName = ''; //SC//
    this.Price = ''; //SC//
};
psui.order.InsuranceType = function() {
	this.Sku = '';
	this.description = '';
};
//truck rental data structure
psui.order.objTruck = function() {
	this.SiteId = ''; 
	this.RentalTruckId='';
	this.TruckSize = '';
	this.PickUpDate = '';
	this.DropOffDate = '';
	this.PickUpTime = '';
	this.DropOffTime = '';	
	this.ProductName = ''; //SC//
	this.Price = ''; //SC//
};
//merchandise data structure
psui.order.objMerchandise = function() {
	this.Sku = ''; //alphanumeric
	this.Quantity = ''; //Number 
	this.TransactionType = '';  // Purchase or Reserve	
};
//validation objects - more to be defined
psui.order.validation = { 
	validTruckSizes: 
		['TenFootTruck', 'TwelveFootTruck', 'FifteenFootTruck', 'TwentyFootTruck', 'TwentyFiveFootTruck'],
	dateFormatTruck: 'M/D/YYYY, Morning or Afternoon (e.g. 1/28/2008,Morning)'
	}; 

//data object to hold the cart
psui.order.data = { 
	StorageUnits:new Array, 
	Trucks:new Array,
	Merchandise:new Array
	};	
//empty data object for clearing the order cart	
psui.order.dataEmpty = { 
	StorageUnits:new Array, 
	Trucks:new Array,
	Merchandise:new Array
	};
psui.order.dataCount = function() {
var storageUnits = (psui.order.data.StorageUnits) ? psui.order.data.StorageUnits.length : 0;
var trucks = (psui.order.data.Trucks) ? psui.order.data.Trucks.length : 0;
var merchandise = (psui.order.data.Merchandise) ? psui.order.data.Merchandise.length : 0;

    var count = storageUnits + trucks + merchandise;
    return count;
	};
//function: psui.order.restoreData 
//retrieves orderCookie string and parses it back into a JSON object
psui.order.restoreData = function() {
	//read the cookie data
	//restore the JSON data from the cookie string
	var strCookie = psui.readCookie(psui.globals['orderCookie']);
	if(typeof(strCookie)!=null&&strCookie) { /* JPL EDIT */
		//pslog('cookie exists');
		psui.order.data = YAHOO.lang.JSON.parse(strCookie); 	
	} else {
		//pslog('no cookie');
		psui.order.data.StorageUnits=new Array;
		psui.order.data.Trucks=new Array;
		psui.order.data.Merchandise=new Array;
    }
    psui.order.displayCount('navOrderCount', 'all');
};

//function: psui.order.save 
//stringifys the order data object and saves the string into the order cookie
psui.order.save = function() {
	//stingify the current state of data
	
	var strCookieSave =	YAHOO.lang.JSON.stringify(psui.order.data);
	//psui.createCookie(psui.globals['orderCookie'],strCookieSave,60);
	psui.createCookie(psui.globals['orderCookie'], strCookieSave);

	psui.order.displayCount('navOrderCount', 'all');
};

// function : psui.order.coutnItems
psui.order.countItems = function() {
	
	this.Trucks = psui.order.data.Trucks.length;
	this.StorageUnits = psui.order.data.StorageUnits.length;
	this.Merchandise  = psui.order.data.Merchandise.length;
	this.allItemCount = psui.order.data.StorageUnits.length + psui.order.data.Trucks.length + psui.order.data.Merchandise.length;
	
	return psui.order.data.StorageUnits.length + psui.order.data.Trucks.length + psui.order.data.Merchandise.length;
}

// function : psui.order.displayCount
// function takes in two arguments.
// arg 1 = element ID where the item count should be displayed
// arg 2 = count type trucks, units, merchandis, or all.

psui.order.displayCount = function() {
	var elementTarget = arguments[0];
	var countType = arguments[1];
	var strInnerHTML = "";
	//countType can be trucks, units, merchandise, all
	var itemCount = new psui.order.countItems;
	switch(countType) {
		case 'trucks':
		strInnerHTML = itemCount.Trucks;
		break;
		case 'units':
		strInnerHTML = itemCount.StorageUnits;		
		break;
		case 'merchandise':
		strInnerHTML = itemCount.Merchandise;		
		break;
		case 'all':
		strInnerHTML = itemCount.allItemCount;		
		break;
		default:
		strInnerHTML = itemCount.allItemCount;			
		break;
	}
	
	if(YAHOO.lang.isObject(YAHOO.util.Dom.get(elementTarget))) { 
		(YAHOO.util.Dom.get(elementTarget)).innerHTML = '('+strInnerHTML+')';
		psui.globals['itmeCount'] =strInnerHTML;
	}

}

// function : psui.order.addItem
// function takes in two arguments.
// arg 1 = itemType which can be 'StorageUnits', 'truckRental', or 'merchandise'
// arg 2 = JSON object literal that defines the item parameters
// example: psui.order.addItem('StorageUnits',{ SizeId:'123',TransactionType:'Rental',StartDate:'2/1/2008'});
psui.order.addItem = function() {
//debugger;
    var itemType = arguments[0];
    var itemParameters = arguments[1];
    if (arguments[2]) {
        var itemSecondaryParameters = arguments[2];
    };
    var scData = {}; //SC//
    scData.events = ''; //SC//
    var scLinkName = '';//SC//

    switch (itemType) {
        case 'storageUnit':
            var truckErrorMessage = document.getElementById('truckErrorMessage');
            truckErrorMessage.style.visibility = "hidden";
            var reservedUnitCount = 0;
            var unitCount;
            var duplicate = false;
            for (unitCount = 0; unitCount < psui.order.data.StorageUnits.length; unitCount++) {
                if (psui.order.data.StorageUnits[unitCount].TransactionType == "Reserve") {
                    //reservedUnitCount++; //Commented by Manmohan Pal on 12/03/2009 bec'z it was incrementing the reservedUnitCount
                }
                if (psui.order.data.StorageUnits[unitCount].SizeId == itemParameters.SizeId &&
                    psui.order.data.StorageUnits[unitCount].SiteId == itemParameters.SiteId) {
                    //duplicate = true; // Edited by Manmohan Pal on 12/03/2009 for checking duplicates
                    duplicate = false;
                }
            }
            //if (reservedUnitCount < 3 || itemParameters.TransactionType == "Rent") {
            //    var unitIndex = psui.order.data.StorageUnits.length;
            //    psui.order.data.StorageUnits[unitIndex] = new psui.order.objUnit;
            //    psui.order.data.StorageUnits[unitIndex].SizeId = (itemParameters.SizeId);
            //    psui.order.data.StorageUnits[unitIndex].TransactionType = (itemParameters.TransactionType);
            //    psui.order.data.StorageUnits[unitIndex].StartDate = (itemParameters.StartDate);
            //    psui.order.data.StorageUnits[unitIndex].Description = (itemParameters.Description);
            //}
            //else {
            if (duplicate) {
                var truckErrorMessage = document.getElementById('truckErrorMessage');
                truckErrorMessage.innerHTML = "This unit is already in your cart. Please check out or select another unit.";
                truckErrorMessage.style.visibility = "visible";
                YAHOO.util.Dom.setStyle(truckErrorMessage, 'display', 'block');
                scroll(0, 0);
                return false;
            }
            //if (reservedUnitCount >= 3 && itemParameters.TransactionType == "Reserve") { // Edited by Manmohan Pal on 05/03/2009
            if (reservedUnitCount >= 1 && itemParameters.TransactionType == "Reserve") {
                var truckErrorMessage = document.getElementById('truckErrorMessage');
                truckErrorMessage.innerHTML = "You have exceeded the reservation limit. Maximum of 1 storage unit reservations per transaction.";
                truckErrorMessage.style.visibility = "visible";
                YAHOO.util.Dom.setStyle(truckErrorMessage, 'display', 'block');
                scroll(0, 0);
                return false;
            }

            var unitIndex = psui.order.data.StorageUnits.length;
            if(unitIndex = 0); // Added by Manmohan Pal on 12/03/2009 for allowing one entry.
            {
            psui.order.data.StorageUnits[unitIndex] = new psui.order.objUnit;
            psui.order.data.StorageUnits[unitIndex].SizeId = (itemParameters.SizeId);
            psui.order.data.StorageUnits[unitIndex].TransactionType = (itemParameters.TransactionType);
            psui.order.data.StorageUnits[unitIndex].StartDate = (itemParameters.StartDate);
            psui.order.data.StorageUnits[unitIndex].Description = (itemParameters.Description).replaceAll(',', ' ');
            psui.order.data.StorageUnits[unitIndex].ProductName = (itemParameters.ProductName); //SC//
            psui.order.data.StorageUnits[unitIndex].Price = (itemParameters.Price); //SC//
            }
	    ///////////////////////
            // SITECATALYST EVENTS
	    //SC//
            
            var transactionType = ((itemParameters.TransactionType=='Rent')?'Rent':'Hold');
            //scData.products = ';Unit-' + itemParameters.ProductName + ';1;'+itemParameters.Price+';;eVar20=Unit'+transactionType;
            scData.products = ';Unit-' + itemParameters.ProductName;

            if(transactionType=='Rent'){
		    scData.events += ',event7';
	    }else{
		    scData.events += ',event8';
	    }
	    
	    //scTrack(scData,'Add Storage Unit');
	    scLinkName = 'Add Storage Unit';
	    
            /////////////
            
            break;
        case 'unitInsurance':
            //insurance can only be added to units exisitin in order.
            var unitToUpdate = (itemParameters.SizeId);
            var updateIndex = 0;
            while (updateIndex < psui.order.data.StorageUnits.length) {
                if (psui.order.data.StorageUnits[updateIndex].SizeId == unitToUpdate) {
                    psui.order.data.StorageUnits[updateIndex].HasInsurance = true;
                    psui.order.data.StorageUnits[updateIndex].InsuranceType = new psui.order.InsuranceType;
                    psui.order.data.StorageUnits[updateIndex].InsuranceType.Sku = (itemSecondaryParameters.Sku);
                    psui.order.data.StorageUnits[updateIndex].InsuranceType.description = (itemSecondaryParameters.Description).replaceAll(',', ' ');
                    break;
                }
                updateIndex = updateIndex + 1;
            };
            break;
        case 'truckRental':
            var isTruckAlreadyExists = false;
            var truckIndex;
            var truckErrorMessage = document.getElementById('truckErrorMessage');
            truckErrorMessage.style.visibility = "hidden";
            for (truckIndex = 0; truckIndex < psui.order.data.Trucks.length; truckIndex++) {
                if (psui.order.data.Trucks[truckIndex].SiteId == (itemParameters.SiteId) &&
	            psui.order.data.Trucks[truckIndex].TruckSize == (itemParameters.TruckSize) &&
		        psui.order.data.Trucks[truckIndex].PickUpDate == (itemParameters.PickUpDate) &&
		        psui.order.data.Trucks[truckIndex].DropOffDate == (itemParameters.DropOffDate) &&
		        psui.order.data.Trucks[truckIndex].RentalTruckId == (itemParameters.RentalTruckId)
		        ) {
                    var truckErrorMessage = document.getElementById('truckErrorMessage');
                    truckErrorMessage.style.visibility = "visible";
                    truckErrorMessage.innerHTML = "This truck has already been added to your shopping cart.";
                    scroll(0, 0);
                    return false;
                }
            }
            if (isTruckAlreadyExists == false) {
                truckIndex = psui.order.data.Trucks.length;
                //object def. {SiteId:'',TruckSize:'',PickUpDate:'',DropOffDate:''}
                if (truckIndex < 3) {
                    psui.order.data.Trucks[truckIndex] = new psui.order.objTruck;
                    psui.order.data.Trucks[truckIndex].SiteId = (itemParameters.SiteId);
                    psui.order.data.Trucks[truckIndex].TruckSize = (itemParameters.TruckSize);
                    psui.order.data.Trucks[truckIndex].RentalTruckId = (itemParameters.RentalTruckId);
                    psui.order.data.Trucks[truckIndex].PickUpDate = (itemParameters.PickUpDate);
                    psui.order.data.Trucks[truckIndex].DropOffDate = (itemParameters.DropOffDate);
                    psui.order.data.Trucks[truckIndex].PickUpTime = (itemParameters.PickUpTime);
                    psui.order.data.Trucks[truckIndex].DropOffTime = (itemParameters.DropOffTime);
                    psui.order.data.Trucks[truckIndex].ProductName = (itemParameters.ProductName); //SC//
                    psui.order.data.Trucks[truckIndex].Price = (itemParameters.Price); //SC//
                    
		    ///////////////////////
		    // SITECATALYST EVENTS
		    //SC//
		    scData.events += ',event9';
		    //scData.products = ';Truck-' + itemParameters.ProductName + ';1;' + itemParameters.Price + ';;eVar20=Truck';
		    scData.products = ';Truck-' + itemParameters.ProductName;

		    scLinkName = 'Add Truck';

		    /////////////
                    
                }
                else {
                    var truckErrorMessage = document.getElementById('truckErrorMessage');
                    truckErrorMessage.style.visibility = "visible";
                    truckErrorMessage.innerHTML = "You have exceeded the reservation limit of 3 trucks per transaction.";
                    return false;
                }
            }
            break;
        case 'merchandise':
            var merchIndex = psui.order.data.Merchandise.length;
            //object def. {Sku:'',Quantity:'',TransactionType:''}
            psui.order.data.Merchandise[merchIndex] = new psui.order.objTruck;
            psui.order.data.Merchandise[merchIndex].Sku = (itemParameters.Sku);
            psui.order.data.Merchandise[merchIndex].Quantity = (itemParameters.Quantity);
            psui.order.data.Merchandise[merchIndex].TransactionType = (itemParameters.TransactionType);
            break;
        default:
            break;
    }
    if (!itemParameters.ByPassRentReserveDialog && itemType == 'storageUnit') {
        if (document.forms['rentReserveDialog'].rentDateSelect.value == "" && document.forms['rentReserveDialog'].reserveDate.value == "") {
            YAHOO.util.Dom.setStyle('dialogAddUnitError', 'display', 'block');
            document.getElementById('dialogAddUnitError').innerHTML = 'No Date Entered';
            return false;
        }
    }
    
    // ITEM SUCCESSFULLY ADDED.
if(scData.events) scData.events = scData.events.substr(1);
    if(YAHOO.util.Cookie.get('scOpen')){
	    // ITEMS WERE PREVIOUSLY ADDED
	scData.events = 'scAdd,' + scData.events;
    }else{
	    // FIRST ITEM ADDED TO SESSION
	    YAHOO.util.Cookie.set('scOpen','true');
	    scData.events = 'scOpen,scAdd,' + scData.events;
	};
    
scTrack(scData,scLinkName)

    psui.order.save();
    if (itemParameters.ByPassRentReserveDialog) {
        YAHOO.publicStorage.container.orderRequest();
    }
    else {
        //update the cart drop down and show it.
        //YAHOO.publicStorage.container.redrawOrderView();
        //takes user to the top of the screen
        //YAHOO.publicStorage.container.scrollToTop();
    }
    

    
    return true;
};

// function : psui.order.removeItem
// function takes in two arguments.
// arg 1 = itemType which can be 'StorageUnits', 'truckRental', or 'merchandise'
// arg 2 = JSON object literal that defines the item parameters
// example: psui.order.removeItem('StorageUnits',{ SizeId:'123' });
	psui.order.removeItem = function() {
	    //psui.order.overlayHeight();
	    var itemType = arguments[0];
	    var itemParameters = arguments[1];
	    if (arguments[2]) {
	        var itemSecondaryParameters = arguments[2];
	    };
	    
	    var scData = {}; //SC//
	    var scLinkName = ''; //SC//
	    scData.events = ''; //SC//
	    
	    switch (itemType) {

	        case 'storageUnit':
	            var unitToRemove = (itemParameters.SizeId);
	            var unitTransactionType = (itemParameters.TransactionType);
	            var unitIndex = itemParameters.unitIndex;

	            // DECREMENT TALLY OF # OF RESERVED UNITS
	            if (psui.order.data.StorageUnits[unitIndex].TransactionType == 'Reserve' && psui.globals['reserveUnitCount'] > 0) psui.globals['reserveUnitCount']--;

	            // REMOVE ITEM
	            var product_name = psui.order.data.StorageUnits[unitIndex].ProductName;
	            psui.order.data.StorageUnits.splice(unitIndex, 1);
	            
		    // SITECATALYST EVENTS
		    //SC//
		    scData.products = ';Unit-' + product_name;
		    scLinkName = 'Remove Storage Unit';
		    /////////////

	            break;
	        case 'unitInsurance':
	            //insurance can only be added to units exisitin in order.
	            var unitToUpdate = (itemParameters.SizeId);
	            var updateIndex = 0;
	            while (updateIndex < psui.order.data.StorageUnits.length) {
	                if (psui.order.data.StorageUnits[updateIndex].SizeId == unitToUpdate) {
	                    psui.order.data.StorageUnits[updateIndex].HasInsurance = false;
	                    psui.order.data.StorageUnits[updateIndex].InsuranceType = null;
	                    //psui.order.overlayHeight();
	                    break;
	                }
	                updateIndex = updateIndex + 1;
	            };
	            break;
	        case 'truckRental':
	            var removeIndex = 0;
	            while (removeIndex < psui.order.data.Trucks.length) {
	                //assuming we must match all parameters to remove a truck reservations
	                // && psui.order.data.Trucks[removeIndex].TruckSize==(itemParameters.TruckSize) 
	                if ((psui.order.data.Trucks[removeIndex].SiteId == (itemParameters.SiteId)
			&& psui.order.data.Trucks[removeIndex].PickUpDate == (itemParameters.PickUpDate)
			&& psui.order.data.Trucks[removeIndex].RentalTruckId == (itemParameters.RentalTruckId)
			&& psui.order.data.Trucks[removeIndex].DropOffDate == (itemParameters.DropOffDate))) {
	                    //psui.order.data.Trucks.splice(0, 1);
	                    
	                    scData.products = ';Truck-' + psui.order.data.Trucks[removeIndex].ProductName;
	                    scLinkName = 'Remove Truck';
	                    
	                    psui.order.data.Trucks.splice(removeIndex, 1);
	                    //psui.order.overlayHeight();
	                    
	                    break;
	                }
	                removeIndex = removeIndex + 1;
	            }
	            break;
	        case 'merchandise':
	            var skuToRemove = (itemParameters.Sku);
	            var removeIndex = 0;
	            while (removeIndex < psui.order.data.Merchandise.length) {
	                if (psui.order.data.Merchandise[removeIndex].SizeId == skuToRemove) {
	                    //psui.order.data.Merchandise.splice(0, 1);
	                    psui.order.data.Merchandise.splice(removeIndex, 1);
	                    //psui.order.overlayHeight();
	                    break;
	                }
	                removeIndex = removeIndex + 1;
	            }
	            break;
	        default:
	            break;
	    }
	    
	    // ITEM REMOVED.
	    if(scData.events){
		    scData.events = 'scRemove,' + scData.events.substr(1);
	    }else{
		    scData.events = 'scRemove';
	    }
	    scTrack(scData,scLinkName);

	    psui.order.save();
	};

//function: psui.order.update	
//arg 1 = expects a JSON literal
//eg. psui.order.update({Sku:'sku',Quantity:2,TransactionType:'Reserve'});
psui.order.update = function() {
	var itemParameters = arguments[0];
	var skuToUpdate = (itemParameters.Sku);
	var updateIndex = 0;
	while( updateIndex < psui.order.data.Merchandise.length) {
		if(psui.order.data.Merchandise[removeIndex].SizeId==skuToRemove) {
			psui.order.data.Merchandise.splice(0,1);
			break;
		}
		updateIndex = updateIndex+1;
	}  		
	psui.order.save();	
	};

//function: psui.order.clear
// clears the order data in memory and saves the cookie
psui.order.clear = function() {
	//clear the order contents
	//save an empty cart into the cookie
	psui.order.data = 	psui.order.dataEmpty;
	psui.order.save();
	};

//every time page loads, restore data from the cookie.
YAHOO.util.Event.onDOMReady(psui.order.restoreData);


// Build overlay for Size Guide
YAHOO.namespace("publicStorage.container");

function sizeGuide() {
	// Build overlay for Size Guide
	YAHOO.publicStorage.container.overlaySizeGuide = new YAHOO.widget.Overlay("overlaySizeGuide", { 
																	  		context:["SizeGuideContext", "tl", "bl"], fixedcenter:true,
																	  	  visible:false} );
	YAHOO.publicStorage.container.overlaySizeGuide.render(YAHOO.util.Dom.get('SizeGuideContext'));
	YAHOO.log("OverlaySizeGuide rendered.", "info", "example");	

	
	//YAHOO.util.Event.addListener("showOverlaySizeGuide", "click", YAHOO.publicStorage.container.overlaySizeGuide.show, YAHOO.publicStorage.container.overlaySizeGuide, true);
	//YAHOO.util.Event.addListener("showOverlaySizeGuideGlobal", "click", YAHOO.publicStorage.container.overlaySizeGuide.show, YAHOO.publicStorage.container.overlaySizeGuide, true);
	//YAHOO.util.Event.addListener("showOverlaySizeGuide2", "click", YAHOO.publicStorage.container.overlaySizeGuide.show, YAHOO.publicStorage.container.overlaySizeGuide, true);
	YAHOO.util.Event.addListener("sizeGuideClose", "click", YAHOO.publicStorage.container.overlaySizeGuide.hide, YAHOO.publicStorage.container.overlaySizeGuide, true);
	//var objMask = document.createElement('div');
	//objMask.setAttribute('class','mask');
	//document.body.appendChild.(objMask);
	
}
//YAHOO.util.Event.addListener(window, "load", sizeGuide);
YAHOO.util.Event.onDOMReady(sizeGuide); // load size guide once the DOM is ready

//error message function for 
//arg 1 = target element id or object
//arg 2 = string for innerHTML to be output.
psui.errorMessage.search = function() {
	var targetElement = arguments[0];
	var strInnerHTML = arguments[1];
	var checkElement = arguments[2];
	//var IsZipValueHm = (YAHOO.util.Dom.get('home_location')).value;
	var IsZipValueHm = (YAHOO.util.Dom.get(checkElement)).value;

	if (IsZipValueHm==""){
		(YAHOO.util.Dom.get(targetElement)).innerHTML = strInnerHTML;
		YAHOO.util.Dom.setStyle(targetElement,'display','block');
		YAHOO.util.Dom.setStyle(targetElement,'margin-top','1px');
		var valid = false;
		return valid;
	} else {
		// JPL EDIT:
		// ONLY CLEAR ERROR MSG IF ALREADY POPULATED
		if((YAHOO.util.Dom.get(targetElement)).innerHTML) (YAHOO.util.Dom.get(targetElement)).innerHTML = "";
		var valid = true;
		return valid;
	}

}

//error message function for 
//arg 1 = target element id or object
//arg 2 = string for innerHTML to be output.
psui.errorMessage.searchSL = function() {
	
	var targetElement = arguments[0];
	var strInnerHTML = arguments[1];
	var IsZipValue = (YAHOO.util.Dom.get('local_storage')).getElementsByTagName('input')[0].value;
	if(IsZipValue=="") {		
		(YAHOO.util.Dom.get(targetElement)).innerHTML = strInnerHTML;
		YAHOO.util.Dom.setStyle(targetElement,'display','block');
		var valid = false;
		return valid;
			} 
	else {
		(YAHOO.util.Dom.get(targetElement)).innerHTML = "";
		var valid = true;
		return valid;
		}
}

//disable enable input and select fields 
//arg 1 = target element id or object
//arg 2 = string for innerHTML to be output.
psui.errorMessage.disableInput = function(obj) {

	var inputFields = (YAHOO.util.Dom.get('RelationDetails')).getElementsByTagName('input');
	var selectFields = (YAHOO.util.Dom.get('RelationDetails')).getElementsByTagName('select');
	var inputFieldsCount = inputFields.length;
	var selectFieldsCount = selectFields.length;

	var checkedState ;
		if (obj.value == 'Yes')	{

		for (iterInput=0;iterInput<inputFieldsCount; iterInput++ )	{
				inputFields[iterInput].disabled= false; 
				inputFields[iterInput].style.background="";

				
			}

	for (iterSelect=0; iterSelect<selectFieldsCount; iterSelect++ )	{
			selectFields[iterSelect].disabled= false;
			selectFields[iterSelect].style.background=""; 
			
			}

		}

		else {
			 for (iterInput=0;iterInput<inputFieldsCount; iterInput++ )	{
				inputFields[iterInput].disabled= true;	
				inputFields[iterInput].style.background="#efefef";
				}

			for (iterSelect=0; iterSelect<selectFieldsCount; iterSelect++ )	{
				selectFields[iterSelect].disabled= true; 
				selectFields[iterSelect].style.background="#efefef"; 
				}

		}

		

}
var targetElement='';
var otherElement='';
psui.errorMessage.disableEnableCountry = function(obj) {
	var passportFieldValue =obj.value;
	var countryForm = (YAHOO.util.Dom.get('newCustomer')).getElementsByTagName('select');
	if (targetElement == '' && otherElement == '')
	{
			for (i=0;i<countryForm.length;i++ ){
				if ((YAHOO.util.Dom.get('newCustomer')).getElementsByTagName('select')[i].className=='countries')	{
						 targetElement = (YAHOO.util.Dom.get('newCustomer')).getElementsByTagName('select')[i];
						 otherElement = (YAHOO.util.Dom.get('newCustomer')).getElementsByTagName('select')[i-1];
							}
						}		
			}
	if (passportFieldValue=='Passport'){
		YAHOO.util.Dom.setStyle(targetElement,'display','block');
		YAHOO.util.Dom.setStyle(otherElement,'display','none');
    }
		else{
							YAHOO.util.Dom.setStyle(targetElement,'display','none');
							YAHOO.util.Dom.setStyle(otherElement,'display','block');	
		}
}

YAHOO.namespace("ps.storageDetails");

//disable enable input and select fields 
//arg 1 = target element id or object
//arg 2 = string for innerHTML to be output.
psui.storageDetails.ticker = function(no_in){

var marketingsizeValue = (YAHOO.util.Dom.get('marketingsize')).value;
(YAHOO.util.Dom.get('biggerImage')).src= "images/"+marketingsizeValue+no_in+'.jpg';
}


//show hide billing info 

function showBillInfo(obj, billInfoContent) {
	psui.storageDetails.billingOverlay = new YAHOO.widget.Overlay("billingInfo");	
	var billingOverlay = psui.storageDetails.billingOverlay;
	var coordinates = YAHOO.util.Dom.getXY(obj);
	coordinates[0] = coordinates[0] + 0;
	coordinates[1] = coordinates[1] + 14;
	var indexContent = parseInt((obj.id).replace('bilnfo',''));
	billingOverlay.cfg.setProperty("xy", coordinates); 
	var targetElement = arguments[1];
	billingOverlay.setBody((YAHOO.util.Dom.get(targetElement)).innerHTML)
	billingOverlay.render(document.body); 
	//billingOverlay.render(YAHOO.util.Dom.get(targetElement));
	//billingOverlay.hide();
	billingOverlay.show();
	

};
function hideBillInfo(obj) {
	psui.storageDetails.billingOverlay.hide();
};



// map it 
YAHOO.namespace("ps.mapIt");
var psui = YAHOO.ps;

psui.mapIt.mapOverlay = new Array();
psui.mapIt.showMap = function() {
	var locationId = arguments[0];
	var queryString = 'latValue=33.873&longValue=-118.086&name=27801+-+ARTESIA%2fARTESIA+&address=11635+Artesia+Blvd&city=Artesia&state=CA&zip=90701-3848&phone=5624034771'
	//commented baseURL based on error reported by Ravi/Bala
	var baseUrl ='';//http://www.publicstorage.com/mapscripts/GoogleMap.aspx?'
	var strOverlay ='';
	//strOverlay +='<div class="yui-module yui-overlay hide-scrollbars" id="'+locationId+'" style="visibility: hidden;">\n';
	strOverlay +='<a href="javascript:;" id="locationMap_hide1" class="close">Close</a>\n';
	strOverlay +='<iframe src="'+baseUrl+''+queryString+'" class="locationMapiframe" name="locationMap2"> </iframe>\n';
	strOverlay +='<div id="mapAddressOConfirm" class="mapAddress"></div>\n';
	//strOverlay +='</div>\n';
	var bodyElement=document.getElementsByTagName('body')[0] ;
	var newDiv = document.createElement("div")
	newDiv.Id= locationId
	newDiv.className ='yui-module yui-overlay hide-scrollbars';
	newDiv.style.visibility="hidden";
	document.body.insertBefore(newDiv, bodyElement);
	newDiv.innerHTML = strOverlay;
	
	//var strAddress ='Address Goes Here' ;	
		//if(!YAHOO.lang.isObject(psui.mapIt.mapOverlay[locationId])) {
		psui.mapIt.mapOverlay[locationId] = new YAHOO.widget.Panel(locationId, { fixedcenter:true,visible:false,modal:true} );
		psui.mapIt.mapOverlay[locationId].render('wrapper');
		//}	
	
	YAHOO.util.Dom.addClass(locationId, 'mapItOverlay');
	psui.mapIt.mapOverlay[locationId].show();
	//(YAHOO.util.Dom.get(locationId)).innerHTML=strOverlay;
	
	//(YAHOO.util.Dom.get('mapAddressOConfirm')).innerHTML =strAddress;
	YAHOO.util.Dom.setStyle('locationMap_mask', "z-index", "1000");
	YAHOO.util.Dom.setStyle(locationId, "z-index", "500000000");
	
}

psui.mapIt.showMap1 =function (obj,queryString) {
	var ulItem = obj.parentNode;
	var address='';
	if (arguments[2]){
		address = arguments[2];	
		}
		else {
			var address1 = ulItem.getElementsByTagName('li')[2].innerHTML;
			var address2 = ulItem.getElementsByTagName('li')[3].innerHTML;
			var address3 = ulItem.getElementsByTagName('li')[4].innerHTML;
			address =address1 +address2 +address3;
		}
	var strOverlay ='';
	strOverlay +='<div class="closeContainer"><a href="javascript:;" id="'+obj+'" class="close" id="gMapContainerClose" onclick="psui.mapIt.hideMap()">Close</a></div>\n';
	strOverlay +='<iframe id="gMapContainer" src="'+queryString+'" class="locationMapiframe" name="locationMap2" frameborder="0" scrolling="no"> </iframe>\n';
	strOverlay +='<div id="mapAddressOConfirm" class="mapAddress">'+address+'</div>\n';
	var confirmMapOverlay = new YAHOO.widget.Overlay("orderConfirmMap");
	confirmMapOverlay.cfg.setProperty("fixedcenter", true); 
	confirmMapOverlay.setHeader("");
	confirmMapOverlay.setBody(strOverlay);
	confirmMapOverlay.setFooter("") ;
	confirmMapOverlay.render(document.body) ;
	confirmMapOverlay.hide();
	//mapOverlay.showEvent.subscribe(function() {psui.searchResults.drawMap(lat,long,divId);});
	confirmMapOverlay.show();
	//YAHOO.util.Event.addListener('gMapContainerClose','click',confirmMapOverlay.hide());
};
psui.mapIt.hideMap = function (){
		document.body.getElementsByTagName('iframe')[1].style.display='none';
		(YAHOO.util.Dom.get('orderConfirmMap')).style.visibility='';
		
		
}

//parse root URL for size guide search
var url = window.location.href;
//var url = window.location.href;

var parsePath = function() {
	//this function will return an output string.
	var strOutput = "";
	var strURL = arguments[0];
	//alert('URL input: '+strURL);
	var arrPathParts = strURL.split('/');
	//alert('path parts are: '+arrPathParts);
	var iter=0;
	//important...we are rebuilding the path without the last element...assuming it is the file name.
	for(iter=0;iter<arrPathParts.length-1;iter++) {
		strOutput = strOutput + arrPathParts[iter] + '/';
	}
	return strOutput;
}

//path will no contain the url path without the filename
var path = parsePath(url) ;
//alert(path);

var sizeGuideInit  = function ()    {
    try {
   var bodyElem = document.getElementsByTagName("body")[0];
   var htmlElem = document.getElementsByTagName("html")[0];
   var viewPortWidth = YAHOO.util.Dom.getViewportWidth();
   var viewPortWidthClient = document.documentElement.clientWidth;
   
  if(viewPortWidth>920 && viewPortWidth<1200) {
		YAHOO.util.Dom.addClass(bodyElem, 'vp1024');
		YAHOO.util.setStyle(bodyElem,'width', viewPortWidthClient);
	        } else 

  if(viewPortWidth>800 && viewPortWidth<1024) {
        YAHOO.util.Dom.addClass(bodyElem, 'vp920');
		YAHOO.util.Dom.setStyle(bodyElem,'width', viewPortWidthClient);
        } else
   
  if(viewPortWidth<920) {
        YAHOO.util.Dom.addClass(bodyElem, 'vp800');
		YAHOO.util.Dom.setStyle(bodyElem,'width', viewPortWidthClient);
		        } else

  if(viewPortWidth>1200) {
        YAHOO.util.Dom.addClass(bodyElem, 'vp1200');
		YAHOO.util.Dom.setStyle(bodyElem, 'width', viewPortWidthClient);
		
		}
    } catch(exception) {
    }
}

YAHOO.util.Event.onDOMReady(sizeGuideInit);

var finalUrl ="";
var addUrl = function addUrl(obj, nameAcr){
	var currentUrl = location.href;
	var subStringUrl = currentUrl.substring(0);
	if (subStringUrl.search('#') != -1){
		var extractString =subStringUrl.substring(0, subStringUrl.indexOf('#'));
		finalUrl = extractString +"#"+nameAcr;
			}
		else{
			finalUrl =currentUrl;
			
		}

}
var preValue =new Array;

var FFadjustment= function (){

if(browserName=='Firefox'){	
		
		var containerPosition = document.getElementById('container');
		var mode = document.compatMode; // Standards or Quirks mode? (or null)
		var body = document.body; // Safari and IE/OP/Gecko quirks mode
		var ypix = window.scrollY;
		if (mode && mode.indexOf('CSS') != -1) {
			body = document.documentElement; // IE/OP/Gecko standards mode
		}
	var anim = new YAHOO.util.Scroll(body,{ scroll: { to: [ypix, ypix-100] } }, 0, YAHOO.util.Easing.easeOut); // scroll to top
	anim.animate();
	

}
	}

YAHOO.util.Event.onDOMReady(FFadjustment);

function clone(obj){
    if(obj == null || typeof(obj) != 'object') return obj;
    var temp = new obj.constructor();
    for(var key in obj) temp[key] = clone(obj[key]);
    return temp;
}


function getMySizeGuide() {

    if (!YAHOO.util.Dom.get("sizeGuideSwf")) {
        var so = new SWFObject("images/flash/size_guide_2009_0324.swf", "sizeGuide", "768", "448", "9", "#FFFFFF");
        so.useExpressInstall('images/flash/expressinstall.swf');
        so.addParam("className", "sizeGuideSwf");
        so.addParam("quality", "high");
        so.addParam("wmode", "transparent");
        so.addVariable("urlPath", window.location);
        so.addVariable("searchValue", getCookie("SearchCriteria"));
        so.addVariable("reportSuiteId", s_account);
        so.write("sizeGuide");
    }
    YAHOO.publicStorage.container.overlaySizeGuide.show();
}

function setUnitMoveInDate(obj) {
//debugger;
    var itemInfo = obj.name.replace('ddlMoveInDate_', '').replace('holdUntilDate_', '').split('_');
    var sizeId = itemInfo[0];
    var itemIndex = itemInfo[1];

    if (psui.order.data.StorageUnits && psui.order.data.StorageUnits.length > 0) {
	    // SAVE ONLY IF NEW DATE GIVEN
	  if(obj.value){
	    
	    // Edited by Manmohan Pal on 09/03/2009 for item Index
        //psui.order.data.StorageUnits[itemIndex].StartDate = obj.value;   
        psui.order.data.StorageUnits[0].StartDate = obj.value;  
		  //SC//
   		 scTrack({'eVar5':obj.value},'Set Storage Unit Move-In Date');
	 }
    }

    psui.order.save();
    refreshMoveInDate();
    
}
