var T="";
var S="";
var TS = "";
var SRC_param = getRequestParameter('SRC');			

var today = new Date;
var weekDayName = new Array ("Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat.");
var monthName = new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

var DayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var curMonthName = new Array ("Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");

	function printDay()
	{
		wd = DayName[today.getDay()];
		document.write( wd );
	}

	function printDateTime()
	{
		mn = curMonthName[today.getMonth()];
		dt = today.getDate();
		hr = today.getHours();
		var ampm = "am";
		if(hr == 0) hr = 12;
		if(hr > 11) {
			ampm = "pm";
		}
		if(hr > 12) {
			hr -= 12;
		}
		mnt = today.getMinutes();
		
		if(mnt < 10) {
			mnt = "0" + mnt;
		} 
		document.write( mn + " " + dt+ ", " + hr + ":" + mnt + ampm );
	}

	function printDate()
	{
		wd = weekDayName[today.getDay()];
		mn = monthName[today.getMonth()];
		dt = today.getDate();
		hr = today.getHours();
		var ampm = "am";
		if(hr == 0) hr = 12;
		if(hr > 11) {
			ampm = "pm";
		}
		if(hr > 12) {
			hr -= 12;
		}
		mnt = today.getMinutes();
		
		if(mnt < 10) {
			mnt = "0" + mnt;
		} 
		document.write( wd+ ", " + mn + " " + dt+ " " + hr + ":" + mnt + ampm );
	}

	function isNumeric(elem){
		var numericExpression = /^[0-9]+$/;
		if(elem.value.match(numericExpression)){
			return true;
		}else{
			return false;
		}
	}

	function getRequestParameter( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}

	function toggleContent(contentID, object){
		if (contentID ==1){
			var listshow = document.getElementById(object);
			listshow.style.display="block";
			var linksel = document.getElementById('links');
			linksel.style.display="none";
		}
		if (contentID==0){
			var listshow = document.getElementById(object);
			listshow.style.display="none";
			var linksel = document.getElementById('links');
			linksel.style.display="inline";
		}
	}
		
	function findCityLink2 (location, oid)
	{  
		if (oid == 'lc') {
			omniTrackGTnSecFeat('Search Widget', 'Local Coupons and Deals'); 
			toggleMyDirHome('coupons'); 
			window.location = "http://yellowpages.superpages.com/profiler/abook.jsp";
		} else if (oid == 'cg') {
			if(location.length== 1) {
				omniTrackGTnSecFeat('Search Widget', 'City Pages and Guides');
				window.location = "http://www.superpages.com/cities";
			} else {
				omniTrackGTnSecFeat('Search Widget', 'City Pages and Guides');
				window.location = "http://www.superpages.com/cities/" + location;
			}
		}
	}

	function toggleTR(contentID, object){
		if (contentID ==1){
			var listshow = document.getElementById(object);
			 if(navigator.appName.indexOf("Microsoft") > -1)
					listshow.style.display="block";
			  else
					listshow.style.display="table-row";
		}
		if (contentID==0){
			var listshow = document.getElementById(object);
			listshow.style.display="none";
		}
	}

	function setTS(pT, pS, pLink, pDomain) {
			
			
		    // #### For Testing - Comment next line before publishing to PROD
			//var redirLink = "http://spdev.superpages.com";

			var redirLink = "http://www.superpages.com";
			var cookieDomain = ".superpages.com";
			
			if( pLink ) {
				redirLink = pLink;
			}
			
			if( pDomain ) {
				cookieDomain = pDomain;
			}

			if( pT && pS ) {
				SPC_LQ = unescape(pT) + "|" + unescape(pS);
				SPC_LQ = pT + "|" + pS;
				SPC_LQ = SPC_LQ.replace(/ /g,"\+");
				SPC_LQ = SPC_LQ.replace(/%20/g,"\+");
				setcookie("SPC_LQ", SPC_LQ, 100, "/", cookieDomain);
//				setcookie("SPC_LQ", SPC_LQ);
			}

			window.location = redirLink;
			
			return false;
						
		}

		
		function setGeoLoc() {
			var SPC_LQ  = unescape(getcookie('SPC_LQ'));
			if(SPC_LQ != "") {
				var idx1 = SPC_LQ.indexOf('|');
				if(idx1 == -1) return "";
				var idx2 = SPC_LQ.indexOf('|',idx1+1);
				if (idx2==-1) idx2=SPC_LQ.length; 
				T = SPC_LQ.substring(0,idx1);
				
				while(T.indexOf('+')>-1) {
					index3 = T.indexOf('+');
					T = "" + (T.substring(0,index3) + " " + T.substring(index3 + 1,T.length));
				}
				S = SPC_LQ.substring(idx1+1,idx2);
				if((T + S) == "") { 
					TS = ""; 
				} else {
					if(T == null || T.length == 0) {
						TS = S;
					} else {
						TS = T + ", " + S;
					}
				}
			}
		}
		
		function displayCityScape() {
			
			// Add by Sarayu for sp.com Redesign, 01/23/2009
			// Set to generic cityscape for Non-cookied home page
			var SPC_LQ = getcookie("SPC_LQ");
			
			if (SPC_LQ == "" || SRC_param == 'insp') {				
				CityScape_SRC = "http://img.superpages.com/images-yp/sp/images/homepage/cityscape_generic.gif";
			} else {
				// Set Cityscape image			
				var cs_image  = getcookie('cs_image');
				
				// Mod by Sarayu to fix broken city images on homepage and static pages, 11/16/2007
				// if( cs_image ) {
				if( cs_image.indexOf('.')>-1 ) {
					// Mod by Sarayu for Skylines, 01/11/2008
					// Gypsy will set cookie "cs_image" with appropriate image including path							
					// CityScape_SRC = "http://img.superpages.com/images-yp/sp/images/skylines/" + cs_image;
					CityScape_SRC = cs_image;
				} else {
					CityScape_SRC = "http://img.superpages.com/images/spacer.gif";
				}
			}
			//document.getElementById('cityscape').src = CityScape_SRC;
			// Mod by Sarayu for sp.com Redesign, 01/15/2009
			//document.write('<img src="' + CityScape_SRC + '" alt="City Skyline" width="187" height="62" border="0" />');
			document.write('<img src="' + CityScape_SRC + '" alt="City Skyline" width="150" height="50" border="0" />');
			
		}
		
		function setColors() {
			// Set Colors
			
			var color1 = getcookie('color1');
			var color2 = getcookie('color2');
			
			document.write('<style type="text/css">.color1 { background-color:#' + color1 + '; } .color2 { background-color:#' + color2 + ';} </style>');

		}
		
		function getcookie(cookiename) {
			var cookiestring=""+document.cookie;
			var idx1=cookiestring.indexOf(cookiename);
			if (idx1==-1 || cookiename=="") return ""; 
			var idx2=cookiestring.indexOf(';',idx1);
			if (idx2==-1) idx2=cookiestring.length; 
			return unescape(cookiestring.substring(idx1+cookiename.length+1,idx2));
		}

		function setcookie( name, value, expires, path, domain, secure ) {
		// set time, it's in milliseconds
			today.setTime( today.getTime() );
			
			var expires_date
			if ( expires )
			{
				expires = expires * 1000 * 60 * 60 * 24;
				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" : "" );
		}
	
//setColors();  

	function lastCookie(){
	var lastCS = getcookie("SPC_LQ");
	var lastC="";
	var lastZ="";
	var lastS="";
	var location="";
	var undefined;
	if (lastCS != null){
	//alert(lastCS);
		var lCS = lastCS.split("|");
		lastC = lCS[0];
		lastC = lastC.replace(/\+/g," ");
		lastS = lCS[1];
		lastZ = lCS[2];
		if ( lastZ == undefined ) lastZ = "";
		location = lastC + " " + lastS + " " +  lastZ; 
		document.ypform.L.value = location;
		//document.ypform.L.value = lastS;
		}
	}

	function profilerLogout(domain){
		//user should default on locations section when logged out
		setMyCookie("defaultSection", 'locations');	
		
		//profiler specfic cookies that need to be deleted to log a user out: SPCUID, SPC_HR, SPC_CP
		var userCookies = new Array();
		userCookies[0] = "SPCUID";
		userCookies[1] = "SPC_HR";
		userCookies[2] = "SPC_CP";
		for (cn in userCookies)
			document.cookie = userCookies[cn] + "=;path=/;domain=" + domain + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}

