// 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/websearch.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;
		}
		
// Disable search until a term is entered
function search_enable(){ 
if (document.all || document.getElementById){
	document.forms['search_form'].elements['q'].value = "";
	document.forms['search_form'].elements['btnG'].disabled = document.forms['search_form'].elements['btnG'].enabled;
}
}


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/arrow_up.gif";
				btnMinus = "http://media.philly.com/designimages/arrow_dwn.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 -->');
	}
}

// For video and gallery ad refresh
// adMiscTag: is the video show

function LoadAds(adPosID, adSite, adZone, adOrd, adChannel, adCategories, adMiscTag)
{

	var theAdText = '';
	var theLeaderBoardText = '';
	
	//Only use for video now
	if (window.location.href.indexOf("video")!=-1) { // only invoked on main 'video'
		var adType = 'video';
	} else if (window.location.href.indexOf("phrequency")!=-1) {
		var adType = 'phreq-photo';
		var adChannel = 'entertainment';
	} else {
		var adType = 'photos';
	}
	
	if ((adSite=='')||(adSite==null)) {
		adSite='homepage';
	}
	if ((adZone=='')||(adZone==null)) {
		adZone=adType;
	}
	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+'/'+adType+';!category='+adType+';type='+adType+';pos=mrec;sz=300x250;dcopt=ist;tile=5;ord='+adOrd+'?';
		
		if (document.getElementById('leaderBoard')) {
			theLeaderBoardText = 'http://ad.doubleclick.net/adi/ph.'+adSite+'/'+adType+';!category='+adType+';type='+adType+';pos=leader;sz=728x90;dcopt=ist;tile=5;ord='+adOrd+'?';
		}
		
		
		if (adMiscTag!='' && adType=='video') { theAdText += ';show='+adMiscTag; }
	} else if ( (adPosID=="rectangle300") && (adZone=="video")) {
			theAdText = 'http://ad.doubleclick.net/adi/ph.'+adSite+'/'+adType+';!category='+adType+';type='+adType+';pos=mrec;sz=300x250;dcopt=ist;tile=5;ord='+adOrd+'?';
			adPosID="mrec_300x250";
			if (adMiscTag!='' && adType=='video') { theAdText += ';show='+adMiscTag; }
	} 
	
	if (theAdText!='') {
		syncRoadBlock(adPosID, theAdText);
	}
	if (theLeaderBoardText!='') {
		syncRoadBlock('leaderBoard', theLeaderBoardText);
	}


	// The folowing codes deal with gallery click track
	if (typeof(s.prop15)!="undefined") {
		var gCookie = "gTrker";
		var gCookieValue =  getCookie(gCookie);
		var gID = s.prop16.split(" - ")[1];
		var gCount=1;
		if((gCookieValue!=null)&&(gCookieValue!="")) {
			var gCookieArray = gCookieValue.split(":");
			if (gCookieArray[0]==gID) { gCount = parseInt(gCookieArray[1])+1; }
		}
		gCookieValue = gID+":"+gCount.toString();
		setCookie(gCookie,gCookieValue);

		// reload cineSport container on every 5th click
		var cineSportContainer = document.getElementById("csprt");
		if ((cineSportContainer!=null)&&(gCount%5==0)) {
			cineSportContainer.src = cineSportContainer.src;
		}

	} // s.prop15 gallery

}



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>';
    }
}



// enable for phillycars and other partners with URL parameters to track or target
function customParam( 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];
}

//---------------- 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=/)
}

