// ===================================================================
// [UTILITIES]
// ===================================================================

// break frames
if (window != top) top.location.href = location.href;

// utility window function
function newWindow(mypage,myname,w,h,features)
{
	var settings;
	if( screen.width )
	{
		w = Math.min(screen.width, w);
		h = Math.min(screen.height, h);
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;

		settings = 'height=' + h + ',';
		settings += 'width=' + w + ',';
		settings += 'top=' + wint + ',';
		settings += 'left=' + winl + ',';
	}
	else
	{
		settings = 'height=' + h + ',';
		settings += 'width=' + w + ',';
	}
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}

// ===================================================================
// [/UTILITIES]
// ===================================================================

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

function getAnchorPosition(anchorname){var useWindow=false;var coordinates=new Object();var x=0,y=0;var use_gebi=false, use_css=false, use_layers=false;if(document.getElementById){use_gebi=true;}else if(document.all){use_css=true;}else if(document.layers){use_layers=true;}if(use_gebi && document.all){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_gebi){var o=document.getElementById(anchorname);x=AnchorPosition_getPageOffsetLeft(o);y=AnchorPosition_getPageOffsetTop(o);}else if(use_css){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_layers){var found=0;for(var i=0;i<document.anchors.length;i++){if(document.anchors[i].name==anchorname){found=1;break;}}if(found==0){coordinates.x=0;coordinates.y=0;return coordinates;}x=document.anchors[i].x;y=document.anchors[i].y;}else{coordinates.x=0;coordinates.y=0;return coordinates;}coordinates.x=x;coordinates.y=y;return coordinates;}
function getAnchorWindowPosition(anchorname){var coordinates=getAnchorPosition(anchorname);var x=0;var y=0;if(document.getElementById){if(isNaN(window.screenX)){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else{x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}else if(document.all){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else if(document.layers){x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}coordinates.x=x;coordinates.y=y;return coordinates;}
function AnchorPosition_getPageOffsetLeft(el){var ol=el.offsetLeft;while((el=el.offsetParent) != null){ol += el.offsetLeft;}return ol;}
function AnchorPosition_getWindowOffsetLeft(el){return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;}
function AnchorPosition_getPageOffsetTop(el){var ot=el.offsetTop;while((el=el.offsetParent) != null){ot += el.offsetTop;}return ot;}
function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}



// ===================================================================
// [COLLECTION]
// ===================================================================
function styleBoxFocus()
{
	var oBox = document.getElementById(keywordTextBoxId);
	if( oBox.value == keywordPrompt )
	{
		oBox.value = '';
	}
}

function styleBoxBlur()
{
	var oBox = document.getElementById(keywordTextBoxId);
	if( oBox.value == '' )
	{
		oBox.value = keywordPrompt;
	}
}

function showHideMoreOptions()
{
	var checked = document.getElementById(moreOptionsCheckBoxId).checked;
	if( checked && !searchOptionsLoaded )
	{
		document.getElementById(moreOptionsCheckBoxId).disabled = true;
		window[moreOptionsCallbackObjectName].Callback('');
	}
	else
	{
		document.getElementById('moreOptionsRow').style.display = (checked ? '' : 'none');
	}
}

function searchOptionsCallbackComplete()
{
	document.getElementById(moreOptionsCheckBoxId).disabled = false;
	searchOptionsLoaded = true;
	showHideMoreOptions();
}

function showSearchTips()
{
	var searchTipsDiv = document.getElementById('searchTipsDiv');
	var coordinates = getAnchorPosition('searchTipsLink');
	searchTipsDiv.style.left = coordinates.x - 150;
	searchTipsDiv.style.top = coordinates.y - 1;
	searchTipsDiv.style.visibility = 'visible';
}

function hideSearchTips()
{
	document.getElementById('searchTipsDiv').style.visibility = 'hidden';
}

function gotoPage(page)
{
	var url = gotoPageUrl + page + getMoreOptionsParam();
	window.location.href = url;
}

function pageSizeChange(oList)
{
	var pageSize = oList.options[oList.selectedIndex].value;
	var url = pageSizeChangeUrl + pageSize + getMoreOptionsParam();
	window.location.href = url;
}

function viewDress(style)
{
	var url = viewDressUrl + style + getMoreOptionsParam();
	window.location.href = url;
}

function viewStory(id)
{
	var url = viewStoryUrl + id;
	window.location.href = url;
}

function getMoreOptionsParam()
{
	var moreOptionsCheckBox = (typeof moreOptionsCheckBoxId == "undefined") ?
		null :
		document.getElementById(moreOptionsCheckBoxId);
	if( moreOptionsCheckBox )
	{
		return moreOptionsCheckBox.checked ? '&moreOptions=1' : '';
	}
	return '';
}

function printSearchTipsContent()
{
	var searchTips = "" +
		"<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"500\" style=\"margin-top:5px;margin-left: 10px; margin-right:10px;\">" +
		"	<tr>" +
		"		<td>" +
		"			<b>Search Tips</b></td>" +
		"		<td align=\"right\">" +
		"			<a href=\"javascript:hideSearchTips()\">Hide Search Tips</a></td>" +
		"	</tr>" +
		"	<tr>" +
		"		<td colspan=\"2\">" +
		"			<ul>" +
		"				<li><b>Keywords:</b> Enter your search terms into the textbox. Item Name, Number and" +
		"					Description are searched upon. Use the pulldown menu to select the type of keyword" +
		"					search to use." +
		"					<ul>" +
		"						<li><b>Any of the words:</b> If multiple keywords are entered, the search returns items" +
		"							that contain any of those keywords. For instance, if the phrase \"White Corset\" was" +
		"							entered, products that contained the word \"White\" OR the word \"Corset\" would be" +
		"							return. </li>" +
		"						<li><b>All of the words:</b> If multiple keywords are entered, the search returns items" +
		"							that contain any of those keywords. For instance, if the phrase \"White Corset\" was" +
		"							entered, products that contained the word \"White\" AND the word \"Corset\" would be" +
		"							return. </li>" +
		"						<li><b>Exact phrase:</b> If multiple keywords are entered, the search returns items" +
		"							that contain the exact phrase that was entered. For instance, if the phrase \"White" +
		"							Corset\" was entered, products that contained the exact phrase \"White Corset\" would" +
		"							be returned. </li>" +
		"					</ul>" +
		"				</li>" +
		"				<li><b>More Search Options:</b> Clicking this checkbox displays a categorized search" +
		"					to the user. When the additional search options are being displayed, selecting the" +
		"					desired dress attributes and clicking \"Search\" will refersh the page, displaying" +
		"					only those dresses matching the specified serach criteria. </li>" +
		"				<li><b>Page Numbers:</b> Use the page numbers to change which page of dresses to display." +
		"				</li>" +
		"				<!--li><b>Show All:</b> By clicking the \"Show All\" link, every dress matching the specified" +
		"					search criteria will be displayed.<br>" +
		"					NOTE: this may take several minutes to load over a slow connection. </li-->" +
		"				<li><b>Dresses Per Page:</b> By default, 15 dresses are displayed per page. Use the drop-down" +
		"					list to select a different number of dresses to display per page. </li>" +
		"			</ul>" +
		"		</td>" +
		"	</tr>" +
		"</table>";
	document.write(searchTips);
}
// ===================================================================
// [/COLLECTION]
// ===================================================================


// ===================================================================
// [DRESS]
// ===================================================================
function swapLarge(type)
{
	var src = cdnBaseUrl + 'styles/389_x_529_' + type + '/' + safeFileName + '.jpg';
	var large = document.getElementById('large');
	var image = new Image();
	image.onload = function()
	{
		large.style.backgroundImage = 'url(' + src + ')';
	};
	image.src = src;
}

function showSendToFriend()
{
	Recaptcha.create("6LeUVwsAAAAAAAxOcet9VeqHlWi8pWJpFIDpgRmR",
		"recaptcha_div", {
		   theme: "white"
		});
	var sendToFriendDiv = document.getElementById('sendToFriendDiv');
	if( sendToFriendDiv.style.visibility == 'hidden' )
	{
		document.forms[0].reset(); // clear form data
		setCallbackRowVisible(false);
		setSendToFriendElementsDisabled(false);
		var coordinates = getAnchorPosition('button_bar');
		sendToFriendDiv.style.left = coordinates.x + 85;
		sendToFriendDiv.style.top = coordinates.y - 20;
		sendToFriendDiv.style.visibility = 'visible';
		document.getElementById(yourEmailId).focus();
	}
}

function hideSendToFriend()
{
	document.getElementById('sendToFriendDiv').style.visibility = 'hidden';
}

function setCallbackRowVisible(visible)
{
	document.getElementById('callbackRow').style.display = (visible ? '' : 'none');
}

function setSendToFriendElementsDisabled(disabled)
{
	var elemNames = new Array(yourEmailId, friendEmailId, messageToFriendId, sendButtonId, cancelButtonId);
	for( var ix = 0; ix < elemNames.length; ix++ )
	{
		document.getElementById(elemNames[ix]).disabled = disabled;
	}
}

function sendToFriendCallback()
{
	var yourEmail = document.getElementById(yourEmailId).value;
	var friendsEmail = document.getElementById(friendEmailId).value;
	var messageToFriend = document.getElementById(messageToFriendId).value;
	setSendToFriendElementsDisabled(true);
	window[sendToFriendCallbackObjectName].Callback(yourEmail, friendsEmail, messageToFriend, Recaptcha.get_challenge(), Recaptcha.get_response());
}

function sentToFriendCallbackComplete()
{
	var numErrors = parseInt(document.getElementById(callbackResultNumErrorsId).value);
	var focusToId = document.getElementById(callBackResultFocusToId).value;
	if( numErrors == 0 )
	{
		hideSendToFriend();
		Recaptcha.destroy();
		alert('Dress Successfully Sent!');
	}
	else
	{
		Recaptcha.reload();
		setCallbackRowVisible(true);
		setSendToFriendElementsDisabled(false);
		var focusTo = document.getElementById(focusToId);
		if( focusTo )
		{
			focusTo.focus();
		}
	}
}

function printDress()
{
	var mypage = 'printDress.aspx?style=' + styleUrlEncoded;
	var myname = 'print_window'
	var w = 650;
	var h = 725;
	var features = 'scrollbars=1,menubar=0,toolbar=0,location=0,status=0,resizable=1';
	newWindow(mypage,myname,w,h,features);
}

function printBride()
{
	var mypage = 'printBride.aspx?Id=' + storyId;
	var myname = 'print_window'
	var w = 650;
	var h = 725;
	var features = 'scrollbars=1,menubar=0,toolbar=0,location=0,status=0,resizable=1';
	newWindow(mypage,myname,w,h,features);
}

function showLargerView() 
{
	if( swfobject.hasFlashPlayerVersion("6.0.0") )
	{
		var att = { data:"flash/zoomifyViewer.swf", width:"440", height:"560" };
		var par = { flashvars:"zoomifyImagePath=" + cdnBaseUrl + "zoomify_pics/" + style + "/", bgcolor:"#999999" };
		var id = "zoomifyContainer";
		swfobject.createSWF(att, par, id);
	}

	ViewLargerDialog.Show();
}
// ===================================================================
// [/DRESS]
// ===================================================================


// ===================================================================
// [STORES]
// ===================================================================
function zipBoxFocus()
{
	var oBox = document.getElementById(zipTextBoxId);
	if( oBox.value == zipCodePrompt )
	{
		oBox.value = '';
	}
}

function zipBoxBlur()
{
	var oBox = document.getElementById(zipTextBoxId);
	if( oBox.value == '' )
	{
		oBox.value = zipCodePrompt;
	}
}

function showMakeAppointment(linkNum, dealerNum, dealerName)
{
	var makeAppointmentDiv = document.getElementById('makeAppointmentDiv');
	if( (window.selectedDealerNum != dealerNum) || (makeAppointmentDiv.style.visibility == 'hidden') )
	{
		document.forms[0].reset(); // clear form data
		var storeName = document.getElementById(storeNameId);
		while( storeName.hasChildNodes() )
		{
			storeName.removeChild(storeName.firstChild);
		}
		storeName.appendChild(document.createTextNode(dealerName));
		setCallbackRowVisible(false);
		setMakeAppointmentElementsDisabled(false);
		var coordinates = getAnchorPosition('aPremier' + linkNum);
		makeAppointmentDiv.style.left = coordinates.x + 25;
		makeAppointmentDiv.style.top = coordinates.y - 50;
		makeAppointmentDiv.style.visibility = 'visible';
		document.getElementById(firstNameId).focus();
		window.selectedDealerNum = dealerNum;
	}
}

function hideMakeAppointment()
{
	document.getElementById('makeAppointmentDiv').style.visibility = 'hidden';
}

function setCallbackRowVisible(visible)
{
	document.getElementById('callbackRow').style.display = (visible ? '' : 'none');
}

function setMakeAppointmentElementsDisabled(disabled)
{
	var elemNames = new Array(firstNameId, lastNameId, emailId, address1Id, address2Id, cityId, stateId, postalCodeId, phoneId, mobileId, weddingDateId, appointmentDateId, contactPreferenceId, sendButtonIdId, cancelButtonId);
	for( var ix = 0; ix < elemNames.length; ix++ )
	{
		document.getElementById(elemNames[ix]).disabled = disabled;
	}
}

function makeAppointmentCallback()
{
	var firstName = document.getElementById(firstNameId).value;
	var lastName = document.getElementById(lastNameId).value;
	var email = document.getElementById(emailId).value;
	var address1 = document.getElementById(address1Id).value;
	var address2 = document.getElementById(address2Id).value;
	var city = document.getElementById(cityId).value;
	var state = document.getElementById(stateId).value;
	var postalCode = document.getElementById(postalCodeId).value;
	var phone = document.getElementById(phoneId).value;
	var mobile = document.getElementById(mobileId).value;
	var weddingDate = document.getElementById(weddingDateId).value;
	var appointmentDate = document.getElementById(appointmentDateId).value;
	var contactPreference = document.getElementById(contactPreferenceId).value;
	setMakeAppointmentElementsDisabled(true);
	window[makeAppointmentCallbackObjectName].Callback(window.selectedDealerNum, firstName, lastName, email, address1, address2, city, state, postalCode, phone, mobile, weddingDate, appointmentDate, contactPreference);
}

function makeAppointmentCallbackComplete()
{
	var numErrors = parseInt(document.getElementById(callbackResultNumErrorsId).value);
	var focusToId = document.getElementById(callBackResultFocusToId).value;
	if( numErrors == 0 )
	{
		hideMakeAppointment();
		alert('Appointment Request Successfully Submitted!');
	}
	else
	{
		setCallbackRowVisible(true);
		setMakeAppointmentElementsDisabled(false);
		var focusTo = document.getElementById(focusToId);
		if( focusTo )
		{
			focusTo.focus();
		}
	}
}
// ===================================================================
// [/STORES]
// ===================================================================

