// Dart Random Number
_phDartOrd = new Date().getTime();


// New search box javascript for drop down menu

function searchFormSubmit1(form) {
		if(form.q.value == "")
		{
		alert('You must enter a search phrase');
		return false;
		}
		if (form.cat[0].selected == true) {
		parent.location = "http://www.philly.com/philly/search/yahoo_search.html?q=" + form.q.value;
		return false;
		}
		if (form.cat[1].selected == true) {
		parent.location = "http://search.philly.com?cat=site&q=" + form.q.value;
		return false;
		}
		if (form.cat[2].selected == true) {
		parent.location = "http://search.philly.com?cat=news&q=" + form.q.value;
		return false;
		}
		if (form.cat[3].selected == true) {
		parent.location = "http://www.newslibrary.com/nlsearch.asp?search_mode=basic&action=search&sort=d%3Ah&nitems=10&region=pi&dbquery=" + form.q.value;
		return false;
		}
		if (form.cat[4].selected == true) {
		parent.location = "http://search.philly.com?cat=video&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[5].selected == true) {
		parent.location = "http://search.philly.com?cat=restaurant&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[6].selected == true) {
		parent.location = "http://search.philly.com?cat=movie&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[7].selected == true) {
		parent.location = "http://search.philly.com?cat=event&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[8].selected == true) {
		parent.location = "http://search.philly.com?cat=job&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[9].selected == true) {
		parent.location = "http://search.philly.com?cat=car&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[10].selected == true) {
		parent.location = "http://search.philly.com?cat=home&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[11].selected == true) {
		parent.location = "http://search.philly.com?cat=apartment&offset=0&q=" + form.q.value;
		return false;
		}
		if (form.cat[12].selected == true) {
		parent.location = "http://philly.kaango.com/feListAds?searchTLC=717&basicSearch=true&preserveSearch=true&searchContext=0&search=" + form.q.value;
		return false;
		}
		return true;
		}


// Quick Search for Restaurants

function quickSearchSubmit1(form) {
		if (form.cuisine[0].selected == true) {
		window.location = "http://search.philly.com?cat=restaurants&q=" + form.searchWords.value;
		return false;
		}
		else {
		window.location = "http://search.philly.com?cat=restaurants&q=" + form.searchWords.value + "+" + form.cuisine.value;
		return false;
		}
		return true;
		}


// Quick Search for Movies

function quickSearchSubmit2(form) {
		if (form.genre[0].selected == true) {
		window.location = "http://search.philly.com?cat=movie&q=" + form.searchWords.value;
		return false;
		}
		else {
		window.location = "http://search.philly.com?cat=movie&q=" + form.searchWords.value + "+" + form.genre.value;
		return false;
		}
		return true;
		}


function openSlideshow(url,width,height) {
	y=Math.floor((screen.availHeight-height)/2);
	x=Math.floor((screen.width-width)/2);
	window.open(url,'slideshow','width='+width+',height='+height+',top='+y+',left='+x+',scrollbars=yes,resizable=yes').focus();
}
function openWin(URL,WIDTH,HEIGHT) {
	if (typeof WIDTH == 'undefined') {
		WIDTH = 500;
	}
	if (typeof HEIGHT == 'undefined') {
		HEIGHT = 400;
	}
	WIDTH = WIDTH + 200;
	HEIGHT = HEIGHT + 250;

	var Win_Param = 'width='+WIDTH+',height='+HEIGHT+',resizable=yes,scrollbars=yes';
	aWindow = window.open(URL,'thewindow',Win_Param);
}


function searchQuickZip(form) {
		if(form.city.value == "")
		{
		alert('Please enter information for a location search, e.g. zip code, city or neighborhood');
		return false;
		}
		return true;
		}

// adding below function for expand/collapse divs.
              function showHide(buttonImg, divToChange, flgToggle)
		{
			// get the div to change
			var theDiv = document.getElementById(divToChange);
			
			if(flgToggle){
				btnPlus = "http://media.philly.com/designimages/plus_btn.gif";
				btnMinus = "http://media.philly.com/designimages/minus_btn.gif";
			}else{
				btnPlus = "http://media.philly.com/designimages/arrow_up.gif";
				btnMinus = "http://media.philly.com/designimages/arrow_dwn.gif";
			}
				
						
			if ( theDiv.style.display != 'none' ) {
				theDiv.style.display = 'none';
				 setType = btnPlus;
			}else{
				theDiv.style.display = '';
				setType = btnMinus;
			}
			
			document.images[buttonImg].src = setType;
		}

function philly_ShowListings() {
	var i=6;
	if (zSr.length != null) {
		document.write('<div id="adwords">');
		document.write('<div id="adwordsContainer">');
		document.write('<h3><a href="http://searchmarketing.yahoo.com/srch/cm.php?">Sponsored Links</a></h3>');
		while (i < zSr.length) {
			var descr = zSr[i++];
			var unused1 = zSr[i++];
			var clickURL = zSr[i++];
			var title = zSr[i++];
			var sitehost = zSr[i++];
			var unused2 = zSr[i++];           
			document.write('<div class="adword">');
			document.write('<h4><a href="' + clickURL + '" target="_new">' + title + '</a></h4>');
			document.write('<p><a href="' + clickURL + '" target="_new">' + descr + '</a></p>');
			document.write('<a href="' + clickURL + '" target="_new">' + sitehost + '</a>');
			document.write('</div>');
		}
		document.write('<div class="divclear"></div>');
		document.write('</div>');
		document.write('</div>');
	} else {
		document.write('<!-- YSM error - no ads returned -->');
	}
}


// verticals menu js
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
	ele.className=ele.className.replace(reg,' ');
	}
}

var navDelay;
var timeout="400"; // in milliseconds (delay for menu collapse)
function nav(id) {
	
	/*
	*    Create second tier navigation id references
	*/
	var navArr=new Array();
	navArr[0]="jobsdrop";
	navArr[1]="carsdrop";
	navArr[2]="realdrop";
	navArr[3]="rentdrop";
	navArr[4]="shopdrop";
	
	/*
	*    Hide all second tier navigation elements and clear active class from first tier nav items
	*/
	for (var i = 0; i<=navArr.length; i++) {
		var navElem = document.getElementById(navArr[i]);
		var navElemTierOne = document.getElementById(navArr[i]+"TierOne");
		if(navElem) {
			removeClass(navElemTierOne,"active");
			navElem.style.display='none';
		}
	}

	/*
	*    If the parameter passed is a valid id for a navigational element, add block style to element, append active class to corresponding first tier nav item
	*/
	var navElem = document.getElementById(id);
	var navElemTierOne = document.getElementById(id+"TierOne");
	if (navElem) {
		clearTimeout(navDelay);
		addClass(navElemTierOne,"active");
		navElem.style.display='block';
	}
}

function navover(id) {
	
	/*
	*    Create second tier navigation id references
	*/
	var navArr=new Array();
	navArr[0]="drop1";
	navArr[1]="drop2";
	navArr[2]="drop3";
	navArr[3]="drop4";
	navArr[4]="drop5";
	navArr["drop1"]="persistJobs";
	navArr["drop2"]="persistCars";
	navArr["drop3"]="persistRealestate";
	navArr["drop4"]="persistRentals";
	navArr["drop5"]="persistMarketplace";
	
	/*
	*    Hide all second tier navigation elements and clear active class from first tier nav items
	*/
	for (var i = 0; i<=navArr.length; i++) {
		var navElem = document.getElementById(navArr[i]);
		var navElemTierOne = document.getElementById(navArr[i]+"TierOne");
		if(navElem) {
			removeClass(navElemTierOne,"active");
			navElem.style.display='none';
		}
		if(navElemTierOne) {
			removeClass(navElemTierOne,navArr[navArr[i]]);
		}
	}

	/*
	*    If the parameter passed is a valid id for a navigational element, add block style to element, append active class to corresponding first tier nav item
	*/
	var navElem = document.getElementById(id);
	var navElemTierOne = document.getElementById(id+"TierOne");
	if (navElem) {
		navElem.style.display='block';
	}
	if (navElemTierOne) {
		clearTimeout(navDelay);
		addClass(navElemTierOne,"active");
		addClass(navElemTierOne,navArr[id]);
	}
}


// For video ad refresh
function LoadAds(adPosID, adSite, adZone, adOrd, adChannel, adCategories, adMiscTag)
{
	//alert("adposID=" + adPosID);
	//alert("adSite=" + adSite);
	//alert("adZone=" + adZone);
	//alert("adOrd=" + adOrd);
	//alert("adChannel=" + adChannel);

	var theAdText = '';
	
	//Only use for video now
	var adType = 'video';
	
	if ((adSite=='')||(adSite==null)) {
		adSite='homepage';
	}
	if ((adZone=='')||(adZone==null)) {
		adZone='video';
	}
	if ((adOrd=='')||(adOrd==null)) {
		adOrd = new Date().getTime();
	}
	if ((adChannel=='')||(adChannel==null)) {
		adChannel = 'homepage';
	} else {
		// overwrite adSite with adChannel
		adSite = adChannel;
	}
	
	if (adPosID=="mrec_300x250") {
		theAdText = 'http://ad.doubleclick.net/adi/ph.'+adSite+'/'+adZone+';!category=video;type='+adType+';pos=mrec;sz=300x250;dcopt=ist;tile=5;'+adMiscTag+';ord='+adOrd+'?';
	} else if ( (adPosID=="rectangle300") && (adZone=="video")) {
			theAdText = 'http://ad.doubleclick.net/adi/ph.'+adSite+'/'+adZone+';!category=video;type='+adType+';pos=mrec;sz=300x250;dcopt=ist;tile=5;'+adMiscTag+';ord='+adOrd+'?';
			adPosID="mrec_300x250";
	} else if (adPosID=="rail_300x250") {
		theAdText = 'http://ad.doubleclick.net/adi/ph.'+adSite+'/'+adZone+';!category=video;type='+adType+';pos=rail;sz=300x250;dcopt=ist;tile=13;'+adMiscTag+';ord='+adOrd+'?';
	} 
	
	if (theAdText!='') {
		//alert("calling adtag:" + theAdText);
		syncRoadBlock(adPosID, theAdText);
	}
}

function syncRoadBlock(adPosID, adTag){
    a = adTag.split(';');
    if (a.length>0)
    {
            for (x=0; x<=a.length-1; x++)
            {
                if (a[x].indexOf('sz=') == 0)
                {
                    size = a[x].substring(3);
                    dims = size.split('x');
                    width = dims[0];
                    height = dims[1];
                    loadRBs(adPosID,width,height,adTag);
                }
            }
    }
}

function loadRBs(s,w,h,adTag){
	if (document.getElementById(s)) {
    	document.getElementById(s).innerHTML = '<iframe src="' + adTag + '" id="ifr_companion" width="'+w+'" height="'+h+'" marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no>' + '</iframe>';
    }
}

//---------------- END GLOBAL.JS

//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06 

var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered? 1=true; 0=false

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("span")[tabnumber]
if (thetab.getAttribute("rel"))
expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("span")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("span")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("span")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("span")[0]) //just auto load first tab instead
}
} //end outer for loop
}


function initializetabcontent1(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("span")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("span")[0]) //just auto load first tab instead
}
} //end outer for loop
}



function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}

/***********************************************
* Rich HTML Balloon Tooltip- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Rich HTML Balloon Tooltip: http://www.dynamicdrive.com/dynamicindex5/balloontooltip.htm
//Created: September 10th, 2006

var disappeardelay=250  //tooltip disappear delay (in miliseconds)
var verticaloffset=0 //vertical offset of tooltip from anchor link, if any
var enablearrowhead=0 //0 or 1, to disable or enable the arrow image
var arrowheadimg=["http://media.philly.com/designimages/arrowdown.gif", "http://media.philly.com/designimages/arrowup.gif"] //path to down and up arrow images
var arrowheadheight=11 //height of arrow image (amount to reveal)

/////No further editting needed

var ie=document.all
var ns6=document.getElementById&&!document.all
verticaloffset=(enablearrowhead)? verticaloffset+arrowheadheight : verticaloffset

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e){
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (e.type=="mouseover")
obj.visibility="visible"
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
if (whichedge=="rightedge"){
edgeoffsetx=0
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffsetx=dropmenuobj.contentmeasure-obj.offsetWidth
return edgeoffsetx
}
else{
edgeoffsety=0
var topedge=ie && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) //move up?
edgeoffsety=dropmenuobj.contentmeasure+obj.offsetHeight+(verticaloffset*2)
return edgeoffsety
}
}

function displayballoontip(obj, e){ //main ballooon tooltip function
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous tooltip?
dropmenuobj.style.visibility="hidden"
clearhidemenu()
//obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(obj.getAttribute("rel"))
showhide(dropmenuobj.style, e)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")+verticaloffset
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
if (enablearrowhead)
displaytiparrow()
}

function displaytiparrow(){ //function to display optional arrow image associated with tooltip
tiparrow=document.getElementById("arrowhead")
tiparrow.src=(edgeoffsety!=0)? arrowheadimg[0] : arrowheadimg[1]
var ieshadowwidth=(dropmenuobj.filters && dropmenuobj.filters[0])? dropmenuobj.filters[0].Strength-1 : 0
//modify "left" value depending on whether there's no room on right edge of browser to display it, respectively
tiparrow.style.left=(edgeoffsetx!=0)? parseInt(dropmenuobj.style.left)+dropmenuobj.offsetWidth-tiparrow.offsetWidth-10+"px" : parseInt(dropmenuobj.style.left)+5+"px"
//modify "top" value depending on whether there's no room on right edge of browser to display it, respectively
tiparrow.style.top=(edgeoffsety!=0)? parseInt(dropmenuobj.style.top)+dropmenuobj.offsetHeight-tiparrow.offsetHeight-ieshadowwidth+arrowheadheight+"px" : parseInt(dropmenuobj.style.top)-arrowheadheight+"px"
tiparrow.style.visibility="visible"
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'; dropmenuobj.style.left=0; if (enablearrowhead) tiparrow.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function reltoelement(linkobj){ //tests if a link has "rel" defined and it's the ID of an element on page
var relvalue=linkobj.getAttribute("rel")
return (relvalue!=null && relvalue!="" && document.getElementById(relvalue)!=null && document.getElementById(relvalue).className=="balloonstyle")? true : false
}

function initalizetooltip(){
var all_links=document.getElementsByTagName("a")
if (enablearrowhead){
tiparrow=document.createElement("img")
tiparrow.setAttribute("src", arrowheadimg[0])
tiparrow.setAttribute("id", "arrowhead")
document.body.appendChild(tiparrow)
}
for (var i=0; i<all_links.length; i++){
if (reltoelement(all_links[i])){ //if link has "rel" defined and it's the ID of an element on page
all_links[i].onmouseover=function(e){
var evtobj=window.event? window.event : e
displayballoontip(this, evtobj)
}
all_links[i].onmouseout=delayhidemenu
}
}
}

if (window.addEventListener)
window.addEventListener("load", initalizetooltip, false)
else if (window.attachEvent)
window.attachEvent("onload", initalizetooltip)
else if (document.getElementById)
window.onload=initalizetooltip

