/// <reference path="jquery-1.2.6.js" />

function sifrHeadlineCR(ref, divID) {
	var flashvars = {};
	var params = {};
	var attributes = {};
	ref = ref.replace("'", "\'");
	ref = ref.replace("&", "%26");
	flashvars.titleText = ref;
	params.wmode = 'transparent';
	swfobject.embedSWF("Resources/SWF/sifr_headline_680x49.swf", "flashheadline" + divID, "680", "49", "9.0.0", false, flashvars, params, attributes);
}

function sifrHeadlineC(ref, divID) {
	var flashvars = {};
	var params = {};
	var attributes = {};
	ref = ref.replace("'", "\'");
	ref = ref.replace("&", "&26");
	flashvars.titleText = ref;
	params.wmode = 'transparent';
	swfobject.embedSWF("Resources/SWF/sifr_headline_468x49.swf", "flashheadline" + divID, "468", "49", "9.0.0", false, flashvars, params, attributes);
}

function sifrHeadlinePShadow(ref, divID) {
	var flashvars = {};
	var params = {};
	var attributes = {};
	ref = ref.replace("'", "\'");
	ref = ref.replace("&", "%26");
	flashvars.titleText = ref;
	params.wmode = 'transparent';
	swfobject.embedSWF("Resources/SWF/sifr_headline_444x80.swf", "flashheadline" + divID, "470", "80", "9.0.0", false, flashvars, params, attributes);
}
function sifrHeadlinePShadow600(ref, divID) {
	var flashvars = {};
	var params = {};
	var attributes = {};
	ref = ref.replace("'", "\'");
	ref = ref.replace("&", "%26");
	flashvars.titleText = ref;
	params.wmode = 'transparent';
	swfobject.embedSWF("Resources/SWF/sifr_headline_600x80.swf", "flashheadline" + divID, "600", "80", "9.0.0", false, flashvars, params, attributes);
}

function toggleFAQ(ref) {
	var btnDiv = "btn" + ref;

	$("#" + ref).slideToggle();
	if (document.getElementById(btnDiv).src.indexOf('btn_expanded.gif') != -1) {
		document.getElementById(btnDiv).src = 'Resources/Images/btn_collapsed.gif';
	} else {
		document.getElementById(btnDiv).src = 'Resources/Images/btn_expanded.gif';
	}
}

function showFAQ() {
	var selValue = $('#selFAQ').val();
	if (selValue == "") {
		$('.faqCategory').show('fast');
	}
	else {
		$('.faqCategory').hide('fast', function () { $('#' + selValue).show() });
	}
}

function toggleAcctDetails(ref) {
	if (ref == "hide") {
		document.getElementById("AccountDetailsCollapsed").style.display = "block";
		document.getElementById("AccountDetailsExpanded").style.display = "none";
	} else {
		document.getElementById("AccountDetailsExpanded").style.display = "block";
		document.getElementById("AccountDetailsCollapsed").style.display = "none";
	}
}

function clearInput(ref) {
	$('#' + ref).select();
}

function toggleFilter(ref) {
	var arrow = "arrow" + ref;

	$("#" + ref).slideToggle();
	if (document.getElementById(arrow).src.indexOf('arrowDown.gif') != -1) {
		document.getElementById(arrow).src = '../Resources/Images/arrowUp.gif';
	} else {
		document.getElementById(arrow).src = '../Resources/Images/arrowDown.gif';
	}
}

function changeHomeModuleBG(ref) {
	var bgURL = "Resources/Images/bg_homeModules" + ref + ".jpg";
	document.getElementById('homeModules').style.background = "url(" + bgURL + ")";
}

function changeHomeIdeas(ref) {
	$(".homeCakeIdea").hide();
	$("#" + ref).show();
}

function changeHomeImages(ref) {
	document.getElementById("featured").style.display = "none";
	document.getElementById("new").style.display = "none";
	document.getElementById("popular").style.display = "none";

	document.getElementById(ref).style.display = "block";
}

var ua = navigator.userAgent.toLowerCase();
if ((ua.indexOf("firefox/2.0") != -1) || (ua.indexOf("firefox/3.0") != -1)) {
	alert("Your browser seems to be out of date.\n\nIn order to have the best experience on PhotoCake.com\nyou'll need to upgrade your browser to a newer version.\n\nUpgrade now for free at www.firefox.com.")
}

function TinyBoxValue(x) {
	var retVal = "";

	for (var i = 0; i < x.length; i++) {
		if ($(x[i]).val().length > 0) {
			retVal = $(x[i]).val();
			break;
		}
	}
	return retVal;
}

function viewAcctReport(ref) {
	document.getElementById("ViewByDate").style.display = "none";
	document.getElementById("ViewByImage").style.display = "none";

	document.getElementById("ViewBy" + ref).style.display = "block";
}

function confirmNewPassword() {
	if (document.getElementById("newPassword").value != document.getElementById("newPasswordConfirm").value) {
		$(".errChangePassword").hide();
		$("#changePasswordDontMatch").show();
		ClearPasswordFields();
	}
}

function checkNewPassword() {
	$(".errChangePassword").hide();

	var err = false;
	var password = $("#newPassword").val();

	if (password.length < 8) {
		err = true;
		$("#changePassword8Chars").show();
	}
	if (password.search(/[0-9]+/) == -1) {
		err = true;
		$("#changePassword1Numeric").show();
	}
	if (password.search(/[A-Z]+/) == -1) {
		err = true;
		$("#changePassword1Cap").show();
	}
	if (password != $("#newPasswordConfirm").val()) {
		err = true;
		$("#changePasswordDontMatch").show();
	}

	if (err == false) {
		DecoPac.Authentication.UpdatePassword($("#currentPassword").val(), password, UpdatePassword_callback);
	} else {
		$("#changePasswordNotFormattedCorrectly").show();
		ClearPasswordFields();
	}
}
function UpdatePassword_callback(res) {
	if (res.error && res.error.Message != 'Unknown')
		alert(res.error.Message)
	else {
		var x = res.value;
		if (x == true)
			$("#changePasswordConfirmation").show();
		else
			$("#changePasswordError").show();
	}
}

function ClearPasswordFields() {
	$("#newPassword").val("");
	$("#newPasswordConfirm").val("");
	$("#newPassword").focus();
}
function checkNumber(evt) {

	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && ((charCode < 48 || charCode > 57)) && charCode != 37 && charCode != 39)
		return false;
	else
		return true;
}

function ImageSearch() {
	var keyword = $('#keyword').val();
	window.location.href = 'ImageLibrary.aspx?keyword=' + keyword;
}

function queryItem(key) {
	var re = new RegExp("[?&]" + key + "=([^&$]*)", "i");
	var offset = location.search.search(re);
	if (offset == -1) return null;
	return RegExp.$1;
}

function watchDemo() {
	TINY.box.show($('#WatchDemo').html(), 0, 868, 576, 1);
}

function watchDemo2() {
	TINY.box.show($('#WatchDemo2').html(), 0, 868, 576, 1);
}

function searchKeyUp(evt, delegate) {
	// If it’s Mozilla/FF use evt; else use window.event
	evt = evt ? evt : event;

	var keyCode = evt.keyCode;

	if (keyCode == 13) {
		// do this if it IS the enter key
		delegate();
		return false;
	}
}

function appUnlockMoreImageCredits(sessionToken) {
	window.location.href = '/OrderForm.aspx';
}

function appUnlockMorePrintCredits(sessionToken) {
	window.location.href = '/ConsumableMedia.aspx';
}

function appSignOut(sessionToken) {
	signOut();
}

function appReportProblem(sessionToken) {
	window.location.href = '/ContactUs.aspx?subject=techsupport';
}

function appImageLibrary(sessionToken) {
	window.location.href = '/ImageLibrary.aspx';
}

function appImageLibraryFrame(sessionToken) {
	window.location.href = '/ImageLibrary.aspx?IsFrame=1';
}
