<!--//
//Cross Browser Object Retrieval
function getObject(objectID){
	if (document.all!=null){
		return document.all[objectID];
	} else if (document.getElementById){
		return document.getElementById(objectID);
	}
}

function showDIV(divID){
	var divPop = getObject(divID);
	divPop.style.display = "block";
}

function hideDIV(divID){
	var divPop = getObject(divID);
	divPop.style.display = "none";
}

function swapFlash(hideThis, showThis){
	if (navigator.userAgent.indexOf("Safari") != -1){
		if (getObject(hideThis) != null){
			hideDIV(hideThis);
			showDIV(showThis);
		}
	}
}

//Display Pop Login to Access Secure Areas
function showLogin(){
	swapFlash("flashintro", "nonflashintro");
	showDIV("loginpop");
	document.forms[0].logpop_username.focus();
	hideDIV("welcomepop");
	hideDIV("forgotpwpop");
}

//Hide Pop Login
function hideLogin(){
	hideDIV("loginpop");
	swapFlash("nonflashintro", "flashintro");
}

//Display Pop Login to Access Secure Areas
function showForgotPW(){
	swapFlash("flashintro", "nonflashintro");
	showDIV("forgotpwpop");
	hideDIV("welcomepop");
	hideDIV("loginpop");
}

//Hide Pop Login
function hideForgotPW(){
	hideDIV("forgotpwpop");
	swapFlash("nonflashintro", "flashintro");
}

//Display Pop Login to Access Secure Areas
function showWelcome(){
	swapFlash("flashintro", "nonflashintro");
	showDIV("welcomepop");
	hideDIV("loginpop");
	hideDIV("forgotpwpop");
}

//Hide Pop Login
function hideWelcome(){
	hideDIV("welcomepop");
	swapFlash("nonflashintro", "flashintro");
}

/*Popup Window Functions*/
var popUpWin;
var popDefWidth = 570;
var popDefHeight = 400;
var lastWidth;
var lastHeight;

//Open URL in new window with fixed dimensions
function openWin(url, pixWidth, pixHeight, canScroll){
	var winFeatures = "width=" + pixWidth + ",height=" + pixHeight + "," + getCentered(pixWidth,pixHeight) + ",resizable=no,scrollbars=";
	if (canScroll){
		winFeatures += "yes";
	} else {
		winFeatures += "no";
	}
	if (popUpWin != null){
		if (popUpWin.closed){
			popUpWin = window.open(url, "popwin", winFeatures);
			popUpWin.focus();
		} else if ((lastWidth == pixWidth) && (lastHeight == pixHeight)){
			popUpWin.location.href = url;
			popUpWin.focus();
		} else {
			popUpWin.close();
			var timeDelay = 0;
			if (navigator.userAgent.indexOf("Safari") != -1){
				timeDelay = 1000;
			}
			var winWait = window.setTimeout('popUpWin = window.open("' + url + '", "popwin", "' + winFeatures + '");popUpWin.focus();', timeDelay);
		}	
	} else {
		popUpWin = window.open(url, "popwin", winFeatures);
		popUpWin.focus();
	}
	lastWidth = pixWidth;
	lastHeight = pixHeight;
}

//Get coordinates for centering window
function getCentered(popupWidth, popupHeight){
	var indentNetscapeWidth = 'screenX=' + getIndent(popupWidth, false);
	var indentNetscapeHeight = 'screenY=' + getIndent(popupHeight, true);
	var indentMSIEWidth = 'left=' + getIndent(popupWidth, false);
	var indentMSIEHeight = 'top=' + getIndent(popupHeight, true);
	var centerCoordinates = indentNetscapeWidth + ',' + indentNetscapeHeight + ',' + indentMSIEWidth + ',' + indentMSIEHeight;
	return centerCoordinates;
}

//Determine top and left margins for window
function getIndent (popupDimension, isHeight){
	if (isHeight){
		return ((screen.availHeight - popupDimension) / 2);
	} else {
		return ((screen.availWidth - popupDimension) / 2);
	}
}

//Close popup and redirect parent to URL
function closeAndGo(url){
	var newWin;
	if (window.opener != null){
		if (window.opener.closed){
			newWin = window.open(url,'newwin','width=' + screen.availWidth + ',height=' + screen.availHeight + ',toolbar=yes,status=yes,directories=yes,location=yes,menubar=yes,personalbar=yes,resizable=yes,scrollbars=yes');
			newWin.focus();
		} else {
			window.opener.location.href = url;
			window.opener.focus();
		}
	} else {
		newWin = window.open(url,'newwin','width=' + screen.availWidth + ',height=' + screen.availHeight + ',toolbar=yes,status=yes,directories=yes,location=yes,menubar=yes,personalbar=yes,resizable=yes,scrollbars=yes');
		newWin.focus();
	}
	window.close();
}

function popWin(theURL){
	openWin(theURL, popDefWidth, popDefHeight);
}

function popImage(imgURL, imgWidth, imgHeight){
	var imgURL = "/popimage.aspx?img=" + imgURL + "&w=" + imgWidth + "&h=" + imgHeight;
	openWin(imgURL, imgWidth, imgHeight);
}

function popRunwayEntry(imgURL, imgWidth, imgHeight) {
	openWin(imgURL, imgWidth, imgHeight);
}

function popPhoto(imgURL, isPortrait){
	if (isPortrait){
		popImage(imgURL, 360, 240);
	} else {
		popImage(imgURL, 240, 360);
	}
}

function popSubmit(theForm){
	popWin("/blank.html");
	setTimeout("document.forms['" + theForm + "'].submit();", 500);
}

function popTellAFriendWithURL(inURL, isGated, pgToDirectTo){
	openWin('/tellafriend.aspx?g=' + isGated + '&pgto=' + pgToDirectTo + '&url=' + inURL, popDefWidth, popDefHeight);
}

function popTellafriend(){
	openWin('/tellafriend.aspx', popDefWidth, popDefHeight);
}

function popSiteOwner(){
	openWin('/site_owner.aspx', popDefWidth, popDefHeight);
}

function popTYDTD(){
	openWin('/events/tydtd/invitations.aspx', popDefWidth, popDefHeight);
}

function popStoreLocator(zip, product){
	/*
	if (validateZip(zip)){
		var qstring = "?clientid=4&template=cesar-b.xsl&productfamilyid=KLKN&producttype=upc&stores=1&storesperpage=8&etailers=0&etailersperpage=8&searchradius=5";
		var theURL = "http://productlocator.infores.com/productlocator/servlet/ProductLocator";
		if (zip != null){
			qstring += "&zip=" + zip;
		}
		if (product != null){
			qstring += "&productid=" + product;
		}
		if ((zip == null) || (product == null)){
			theURL = "/cuisine/store_locator.aspx";
		}
		openWin(theURL + qstring, 590, 490, true);
	}
	*/
	openWin("http://storefinder.mmmars.com/CesarProductLocator/Default.aspx", 590, 490, true);
}

function validateZip(zip){
	if (zip == null){
		return true;
	}
    var found = zip.search(/[^0-9]/);
    if (found != -1){
        alert("Please enter a valid zip code.");
        return false;
    }

    if(zip == ""){
        alert("Please enter a valid zip code.");
        return false;
    }

    return true;
}

/* Article Pagination Scripts */
var currentArticlePage = 1;
var maxArticlePages;
var articlePages;

function displayArticle(){
	var teaser = getObject("teaser");
	teaser.style.display = "none";
	gotoPage(1);
}

// Initialize Article Pagination
function initArticle(numPages, showPagination){
	maxArticlePages = numPages;
	articlePages = new Array(maxArticlePages);
	for (var i = 0; i < maxArticlePages; i++){
		articlePages[i] = new Object();
		articlePages[i].styles = new Array();
	}
	if (showPagination && (maxArticlePages > 1)){
		writePagination();
	}
}

function showInitPage(){
	if (maxArticlePages != null){
		var qPage = getParamValue("page");
		if ((qPage != null) && !isNaN(qPage)){
			qPage = parseInt(qPage);
			if ((qPage >= 1) && (qPage <= maxArticlePages)){
				gotoPage(qPage);
			} else {
				gotoPage(1);
			}
		} else {
			gotoPage(1);
		}
	}
}

// Add Style Swaps/Differences for Multiple Pages
function addPageStyle(pageNumbers, divName, cssText){
	for (var i = 0; i < pageNumbers.length; i++){
		articlePages[pageNumbers[i] - 1].styles[articlePages[pageNumbers[i] - 1].styles.length] = new Array(divName, cssText);
	}
}

// Display Specified Page and Swap Styles
function gotoPage(pageNum){
	var teaser = getObject("teaser");
	if (teaser != null){
		teaser.style.display = "none";
	}
	var oldPage = getObject("page" + currentArticlePage);
	var newPage = getObject("page" + pageNum);
	if (newPage.style.display == "none"){
		oldPage.style.display = "none";
		
		for (var i = 0; i < articlePages[pageNum - 1].styles.length; i++){
			var styleDiv = getObject(articlePages[pageNum - 1].styles[i][0]);
			styleDiv.style.cssText = articlePages[pageNum - 1].styles[i][1];
		}
	
		newPage.style.display = "inline";
	}
	currentArticlePage = pageNum;
	if (maxArticlePages > 1){
		writePagination();
	}
}

// Go back one page
function backPage(){
	gotoPage(currentArticlePage - 1);
}

// Go to the next page
function nextPage(){
	gotoPage(currentArticlePage + 1);
}

// Display pagination based on current page number
function writePagination(){
	var pagination = getObject("pagination");
	if (pagination != null){
		var backArrow = '<a href="javascript:backPage();"><img src="/images/arrow_back_gray.gif" width="3" height="6" alt="" border="0"> previous page</a>&nbsp;&nbsp;';
		var pageNum = "page " + currentArticlePage + " of " + maxArticlePages;
		var nextArrow = '&nbsp;&nbsp;<a href="javascript:nextPage();">next page <img src="/images/arrow_next_gray.gif" width="3" height="6" alt="" border="0"></a>';
		var output = "";
		
		if (currentArticlePage > 1){
			output += backArrow;
		}
		output += pageNum;
		if (currentArticlePage < maxArticlePages){
			output += nextArrow;
		}
		pagination.innerHTML = output;
		pagination.style.display = "inline";
	}
}


/* Slideshow Scripts */
var ssPics;
var ssPicsPath;
var ssCaptions;
var ssMaxPics;
var ssNumberDisplay;
var ssCaptionDisplay;
var ssIsPaused;
var ssCurrentImg;
var ssInterval;
var ssWaitTime;
var isMSIE;
var ssFullMode;

function ssInit(isFullMode){
	ssFullMode = isFullMode;
	ssPics = hiddenPics;
	ssPicsPath = hiddenPicsPath;
	ssCaptions = hiddenCaptions;
	ssMaxPics = ssPics.length;
	ssNumberDisplay = getObject("ssnumber");
	ssCaptionDisplay = getObject("sscaption");
	ssIsPaused = true;
	ssCurrentImg = 0;
	if (document.images["ssphoto"].filters != null){
		isMSIE = true;
		ssWaitTime = 2500;
	} else {
		isMSIE = false;
		ssWaitTime = 2000;
	}
	ssShow(0);
}

function ssShow(picNum){
	if (isMSIE && ssFullMode) document.images["ssphoto"].filters.item(0).Apply();
	document.images["ssphoto"].src = ssPicsPath + ssPics[picNum];
	if (isMSIE && ssFullMode) document.images["ssphoto"].filters.item(0).Play();
	ssNumberDisplay.innerHTML = "Photo " + (picNum + 1) + " of " + ssMaxPics;
	if (ssFullMode){
		ssCaptionDisplay.innerHTML = ssCaptions[picNum];
	} else {
		document.getElementById("hdnPhotoID").value = hiddenPhotoIDs[picNum];
	}
	ssCurrentImg = picNum;
}

function ssStart(){
	if (ssCurrentImg = (ssMaxPics - 1)){
		ssShow(0);
	}
	ssInterval = setInterval("ssAutoNext();", ssWaitTime);
	ssIsPaused = false;
	document.images["sspause"].src = "/images/circle/ssbtn_pause.gif";
	document.images["sspause"].alt = "Pause";
}

function ssStop(){
	clearInterval(ssInterval);
	ssIsPaused = true;
	document.images["sspause"].src = "/images/circle/ssbtn_play.gif";
	document.images["sspause"].alt = "Play";
}

function ssFirst(){
	ssStop();
	ssShow(0);
}

function ssBack(){
	if (ssFullMode){
		ssStop();
	}
	if (ssCurrentImg > 0){
		ssShow(ssCurrentImg - 1);
	}
}

function ssNext(){
	if (ssFullMode){
		ssStop();
	}
	if (ssCurrentImg < (ssMaxPics - 1)){
		ssShow(ssCurrentImg + 1);
	}
}

function ssAutoNext(){
	if (ssCurrentImg < (ssMaxPics - 1)){
		ssShow(ssCurrentImg + 1);
	} 
	if (ssCurrentImg >= (ssMaxPics - 1)){
		ssStop();
	}
}

function ssPause(){
	if (ssIsPaused){
		ssStart();
	} else {	
		ssStop();
	}
}

function ssLast(){
	ssStop();
	ssShow(ssMaxPics - 1);
}

/* Frame Viewer Scripts */
var photoFrames;
var photoFrame;
var maxFrames;
var currentFrame;

function lightSwatch(swatchNum){
	var swatch = getObject("swatch" + swatchNum);
	swatch.style.border = "solid 2px #669933";
}

function dimSwatch(swatchNum){
	if ((swatchNum != currentFrame) && (swatchNum != 0)){
		var swatch = getObject("swatch" + swatchNum);
		swatch.style.border = "solid 2px #FFFFFF";
	}
}

function initFrames(frameFolder, numFrames){
	maxFrames = numFrames;
	photoFrames = new Array(maxFrames);
	for (var i = 0; i < maxFrames; i++){
		photoFrames[i] = new Image();
		photoFrames[i].src = "/images/circle/postcards/" + frameFolder + "/frame" + (i + 1) + ".gif";
	}
	photoFrame = getObject("photoframe");
	currentFrame = 0;
	showFrame(1);
}

function showFrame(frameNum){
	frameNum = parseInt(frameNum);
		photoFrame.style.backgroundImage = "url(" + photoFrames[frameNum - 1].src + ")";
		//document.forms[0].frameurl.value = photoFrames[frameNum - 1].src;
		document.forms[0].frameurl.value = frameNum;
		var lastFrame = currentFrame;
		currentFrame = frameNum;
		dimSwatch(lastFrame);
		lightSwatch(currentFrame);
}

function backFrame(){
	if (currentFrame == 1){
		showFrame(maxFrames);
	} else {
		showFrame(currentFrame - 1);
	}
}

function nextFrame(){
	if (currentFrame == maxFrames){
		showFrame(1);
	} else {
		showFrame(currentFrame + 1);
	}
}

/* Album Delete Photos Scripts */
function confirmDeletePhotos(){
	var photosList = getObject("dppList");
	var deletePhoto = new Array();
	var nameMatch = "chkDelete";
	var content = "";
	for (var i = 0; i < document.forms['frmAlbumBrowse'].elements.length; i++){
		if (document.forms['frmAlbumBrowse'].elements[i].name.indexOf(nameMatch) > 0){
			deletePhoto[deletePhoto.length] = document.forms['frmAlbumBrowse'].elements[i].checked;
		}
	}
	for (var i = 0; i < deletePhoto.length; i++){
		if (deletePhoto[i]){
			if (hiddenCaptions[i] != ""){
				content += '"' + hiddenCaptions[i] + '"';
			} else {
				content += hiddenPics[i];
			}
			content += "<br>";
		}
	}
	if (content != ""){
		photosList.innerHTML = content;
		showDIV("deletephotopop");
	}
}

/* Bold page in subnav -- called from javascript inserted by BasePage */
function boldSection(sectionID){
	var sectionLink = getObject("snlink" + sectionID);
	if (sectionLink != null){
		sectionLink.style.fontWeight = "bold";
	}
}

/* Gets Parameter Values from QueryString */
function getParamValue(paramName){
	paramName += "=";
	var paramLength=paramName.length;
	var start = -1;
	if (location.search.indexOf("?" + paramName) != -1){
		start = location.search.indexOf("?" + paramName) + 1;
	} else if (location.search.indexOf("&" + paramName) != -1){
		start = location.search.indexOf("&" + paramName) + 1;
	}
	if (start != -1){
		if (location.search.indexOf("&",start + 1) != -1){
			tempValue = location.search.substring(start + paramLength, location.search.indexOf("&",start + 1));
		}
		else {
			tempValue = location.search.substring(start + paramLength);
		}
		return tempValue;
	}
	else {
		return null;
	}
}

function popupSDBSRules() {
	url = '/circle/small_dog_big_star/sdbs_rules.html';
	pixWidth = 350; pixHeight = 350;
	canScroll = 1;
	openWin(url, pixWidth, pixHeight, canScroll);
}

function popupSDBSPrizes() {
	url = '/circle/small_dog_big_star/sdbs_prizes.html';
	pixWidth = 350; pixHeight = 350;
	canScroll = 1;
	openWin(url, pixWidth, pixHeight, canScroll);
}


// Prepare bio panel and load data/image
function loadDogBio(dogID, filename, disableVote) {
	if (!disableVote) { disableVote = false; }
	$('#Ajax_Bio_Container').load('/circle/small_dog_big_star/ajax_dog_bio.aspx?dogID='+dogID , function() { openDogBio(disableVote); }); // Insert remote content (Ajax!)			
	$('#Ajax_Bio_Container').html('<h1>Loading&hellip;</h1>'); // Display 'Loading...'
	$('#Panel_Pic').attr({src:'/images/circle/smalldogbigstar/photos/imagehandler.ashx?MaxSize=285&imgUrl=' + filename }); // Insert photo
}

// Open bio panel
function openDogBio(disableVote) {
	$('#Dog_Bio').css('opacity',0).modal({overlay:65}); // Open panel, but make invisible until content is loaded
	
	// Declare measurement values
	dogNameMaxWidth = 130;
	dogNameMinWidth = 191;
	dogNameWidth = document.getElementById('Dog_Name_Heading').offsetWidth;
	dogNameWidthDiff = dogNameWidth - dogNameMaxWidth;
	
	// See if panel needs to be expanded if dog's name is too long
	if (dogNameWidth>dogNameMinWidth) {
		panelBioWidth = Number(dogNameWidth) + 50;
	} else {
		panelBioWidth = dogNameMinWidth;
	}
	
	// Resize panel content container
	$('.Panel_Bio').css('width',panelBioWidth+'px');
	
	// Resize panel itself if necessary
	if (dogNameWidthDiff>0) {
		$('.modalContainer').css('width',600+dogNameWidthDiff+'px');
		$('.modalContainer').css('margin-left',-370-(dogNameWidthDiff/2)+'px'); // Recenter
	}
	
	if (disableVote) {
		$('#Panel_Vote_Button').css({display:'none'});
	} else {
		if ($('#regionVoted').val()!='False') {
			$('#Panel_Vote_Button').attr({src:"/images/circle/smalldogbigstar/panel_vote_thanks.gif"});
			$('#Panel_Vote_Link').attr({href:"javascript:alert('Sorry, you have already voted for this region.')"});
			$('#Panel_Vote_Link').css({cursor:"default"});
		} else {
			region = $('#region').val();
			dogID = $('#dogID').val();
			dogName = $('#lblDogName').html();
			$('#Panel_Vote_Link').attr({href:"javascript:confirmSDBSVote("+dogID+",'"+region+"')"});
			$('#Panel_Vote_Confirm_Link').attr({href:"javascript:placeSDBSVote("+dogID+",'"+region+"')"});
			$('#Region_Name').html(region);
			$('#Confirm_Dog_Name').html(dogName);
		}
	}
	
	$("#Dog_Bio").animate({opacity:1},250); // Fade panel in
}

// Prepare bio panel for closing
function closeDogBio() {
	$("#modalOverlay").animate({opacity:0},250); // Fade out overlay
	$("#Dog_Bio").animate({opacity:0},250,undefined,closeModal); // Fade out panel, and close
}

// Close bio panel
function closeModal() {
	$.modal.close(); // Close panel
	$('#Ajax_Bio_Container').empty(); // Clear content
	$('#Panel_Pic').attr({src:''}); // Clear photo
}

function confirmSDBSVote(dogID,region) {
	$('#Panel_Vote_Button').css({display:'none'});
	$('#Panel_Vote_Confirm').css({display:'block'});
}

function cancelVote() {
	$('#Panel_Vote_Confirm').css({display:'none'});
	$('#Panel_Vote_Button').css({display:'block'});
}

function placeSDBSVote(dogID,region) {
	voteLink = "ajax_dog_bio.aspx?voteForDogID="+dogID+"&region="+region;
	$('#Panel_Vote_Button').attr({src:"/images/circle/smalldogbigstar/panel_vote_thanks.gif"});
	$('#Panel_Vote_Link').attr({href:"javascript:alert('Sorry, you have already voted for this region.')"});
	cancelVote();
	$.get(voteLink);
}


function getCookie( name ) {
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
    return null;
  }
  if ( start == -1 ) return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name+"="+escape( value ) +
    ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


window.onload = showInitPage;
//-->