// Dart Random Number
_krdDartOrd = new Date().getTime();

//  Dart Tile Number 1-16 unique in page by inc 1
_krdDartInc = 0;

// Dart Random Number
_phDartOrd = new Date().getTime();

//This is needed for prospero comments and possibly other partners
var krd_site = "philly";
var krd_site_display_name = "Philly.com";
var krd_publication = "philly";
var krd_topix_property = "5008";

var navReady = false;
var toolsReady = false;
var partner_group = "";

// 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) {
		window.location = "http://www.philly.com/philly/search/yahoo_search.html?q=" + form.q.value;
		return false;
		}
		if (form.cat[1].selected == true) {
		window.location = "http://search.philly.com?cat=article&q=" + form.q.value;
		return false;
		}
		if (form.cat[2].selected == true) {
		window.location = "http://search.philly.com?cat=news&q=" + form.q.value;
		return false;
		}
		if (form.cat[3].selected == true) {
		window.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) {
		window.location = "http://search.philly.com?cat=multimedia&q=" + form.q.value;
		return false;
		}
		if (form.cat[5].selected == true) {
		window.location = "http://search.philly.com?cat=restaurants&q=" + form.q.value;
		return false;
		}
		if (form.cat[6].selected == true) {
		window.location = "http://search.philly.com?cat=movies&q=" + form.q.value;
		return false;
		}
		if (form.cat[7].selected == true) {
		window.location = "http://search.philly.com?cat=entertainment&q=" + form.q.value;
		return false;
		}
		if (form.cat[8].selected == true) {
		window.location = "http://search.philly.com?cat=jobs&q=" + form.q.value;
		return false;
		}
		if (form.cat[9].selected == true) {
		window.location = "http://search.philly.com?cat=cars&q=" + form.q.value;
		return false;
		}
		if (form.cat[10].selected == true) {
		window.location = "http://search.philly.com?cat=homes&q=" + form.q.value;
		return false;
		}
		if (form.cat[11].selected == true) {
		window.location = "http://search.philly.com?cat=apartments&q=" + form.q.value;
		return false;
		}
		if (form.cat[12].selected == true) {
		window.location = "http://phillymarketplace.livedeal.com/search?zip=19101&kbid=3148&query=" + 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=movies&q=" + form.searchWords.value;
		return false;
		}
		else {
		window.location = "http://search.philly.com?cat=movies&q=" + form.searchWords.value + "+" + form.genre.value;
		return false;
		}
		return true;
		}


function getSite(){
	foundSite = false;
    site=document.location.hostname;
    endPos=site.indexOf(".com");
    if (endPos >= 1) {
		foundSite = true;
		site = site.substr(0, endPos);
		startPos = site.lastIndexOf(".");
		site = site.substr(startPos + 1);
	}
	return site;
}
function getPublication(){
	publication=document.location.pathname;
	startPos=publication.indexOf("/mld/");
	publication=publication.substr(startPos+5);
	endPos=publication.indexOf("/");
	publication=publication.substr(0,endPos);
	return publication;
}
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);
}

// Check environment.
function isTestEnv() {
  testHost = document.location.host;
  if (testHost == "" || testHost.match(/(\.(int|qa|stg)\.|localhost)/)) {
    return true;
  }
  return false;
}

var _isTestEnv = isTestEnv();

// Relative URLs
function relPath(path) {

p=document.location.pathname;document.location=p.substring(0,(i=5+p.substring(5).indexOf('/'))>4?i:p.length)+'/'+path;

}


// Display timestamp
function printElapsedTime(startingDateString,numHours,timestampPrefix) {

	var nowtime = new Date();
	var startingDate = new Date(startingDateString);
	var milliseconds1 = startingDate.getTime();
	var milliseconds2 = nowtime.getTime();
	var difference = milliseconds2 - milliseconds1;
	var daysDifference = Math.floor(difference/1000/60/60/24);
	difference = difference - daysDifference*1000*60*60*24
	var hoursDifference = Math.floor(difference/1000/60/60);
	difference = difference - hoursDifference*1000*60*60
	var minutesDifference = Math.floor(difference/1000/60);
	difference = difference - minutesDifference*1000*60
	var secondsDifference = Math.floor(difference/1000);
	//alert('daysDifference = ' + daysDifference + '\nhours diff = ' + hoursDifference + '\nminutesDiff = ' + minutesDifference);
	var dayHoursDifference = daysDifference*24;
	var totalHoursDifference = dayHoursDifference + hoursDifference;
	//document.write('total hoursDiff = ' + totalHoursDifference + '<br />');
	//document.write('numHours = ' + numHours+'<br>');

	var formattedHours = startingDate.getHours();
	if(startingDate.getHours() < 12) {
		var amPm = 'am';
	} else {
		var amPm = 'pm';
	}
	if(startingDate.getHours() > 12) { 
		formattedHours = startingDate.getHours() - 12; 
	}
	else if(startingDate.getHours() == 0) { formattedHours = 12; }
	
	var formattedMinutes = startingDate.getMinutes();
	if(startingDate.getMinutes().toString().length == 1){ 
	formattedMinutes = '0' + startingDate.getMinutes().toString();
	}

	// If a timestamp cutoff has been specified (such as for Headlines Digest), only display the stamp if it falls within indicated # of hours 
	if(!numHours || (numHours && totalHoursDifference < numHours)) {
		if(timestampPrefix){
		document.write(timestampPrefix);
		}
		if (daysDifference >= 1 || nowtime.getDate() != startingDate.getDate()) {
		var monthNum = startingDate.getMonth() + 1;
		document.write(monthNum + '/' +startingDate.getDate()+ '/'+ startingDate.getFullYear()); 
		} else if (daysDifference == 0 && hoursDifference >= 1) {
		document.write(formattedHours +':' + formattedMinutes + amPm);  
		} else {
		document.write(minutesDifference + ' min');
		}
	}

}


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('<fieldset> <legend> <a href="http://searchmarketing.yahoo.com/srch/cm.php?"><span class="minitext"><b>Sponsored Results</b></span></a></legend>');
    document.write('<div class="inline_ad_wide"><table><tr>');
    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('<td width="33%" align=left><dl id="web_results_sponsor">');
      document.write('<dt><a target="_new" href="' + clickURL + '">' + title + '\n');
      document.write('<dd>' + descr + '</dd>\n');
      document.write('<br /><font color="#00000">' + sitehost + '</font></a>\n');
      document.write('</dt></dl></td>\n\n');
    }
    document.write('</tr></table></div></fieldset>');
  } else {
      document.write('<!-- YSM error - no ads returned -->');
  }
}


//---------------- END GLOBAL.JS

