<!--

// misc jquery functions
$(document).ready(function() {

	$('#output thead th:nth-child(5)').css('padding-right', '2px').append('<div style="position: relative; margin-top: 2px; font-size: 10px; line-height: 1"><input type="checkbox" id="show-hide-checkboxes" checked="checked" style="position: absolute; top: 0; left: 0" /><label for="show-hide-checkboxes" style="margin-left: 20px; float: right; cursor: pointer">include/ exclude all</label></div>');

	$('#download-form-download').html('Download this table (CSV (Excel)) <a id="download-with-reviewers" href="#">with reviewer details</a> or <a id="download-without-reviewers" href="#">without reviewer details</a>');
	$('#download-form-submit').hide();
	//$('#download-form-submit').remove();
	$('#download-form').prepend('<input type="hidden" name="hide_reviewers" id="hide_reviewers" value="Without reviewer details" />');

	// Check/uncheck all checkboxes from single checkbox
	$('#show-hide-checkboxes').change(function() {
		$('#download-form tbody').find(':checkbox').attr('checked', $(this).attr("checked") ? true : false);
	});

	// Show/hide reviewer details when downloading reviews
	$('#download-with-reviewers').click(function() {
		$('#hide_reviewers').attr('value', 'With reviewer details');
window.setTimeout(function(){
		$('#download-form').submit();
}, 300);
		return false;
	});

	$('#download-without-reviewers').click(function() {
		$('#hide_reviewers').attr('value', 'Without reviewer details');
		$('#download-form').submit();
		return false;
	});

	$("#loginform input:text:visible:first").focus();

	// SI.Files.stylizeAll();

	// hide e-mail addresses from spambots
	if (jQuery.isFunction(jQuery.fn.obfuscateRel)) {
		$('a.obfuscate').obfuscateRel();
	}

	// #tribute-form div#usp form#usp_form ul#usp_list li.usp_url label.usp_label
	// Change field labels and visibility on Add Your Tribute form
	// html body#secTributes.inner div#ctrShadow div#subTributes.ctrContainer div.contentInner div#tribute-form div#usp form#usp_form ul#usp_list li.usp_name label.usp_label
	// Move usp_title li element to the top of the containing ul
	$('#tribute-form #usp_form > ul').prepend($('#tribute-form #usp_form li.usp_title'));
	$('#tribute-form #usp_form li.usp_name label.usp_label').html('Your Name:');
	$('#tribute-form #usp_form li.usp_url label.usp_label').html('Your E-mail Address:<span class="note block" style="margin-top: 2px">(for verification only: will not be used or shared)</span>');
	$('#tribute-form #usp_form li.usp_title label.usp_label').html('Your Tribute is For:');
	$('#tribute-form #usp_form li.usp_category').hide();
	$('#tribute-form #usp_form li.usp_content label.usp_label').html('Your Tribute:<span class="note block" style="margin-top: 2px">(up to 50 words)</span>');
	$('#tribute-form #usp_form li.usp_images label.usp_label').html('Upload a Photo (optional):');
	$('#tribute-form #usp_form #usp_success_message').html('Thank you for submitting your tribute. For security reasons, all tributes are reviewed by our editors before being posted to our <span class="nowrap">Tribute Wall</span>.');
	$('#tribute-form #usp_form #usp_add-another').remove();
	$('#tribute-form #usp_form #user-submitted-post').css('width', 'auto').attr('value', 'Submit your Tribute');
	if (location.href.indexOf('submission-error=1') !== -1) {
		$('#usp_form input:text:visible:first').focus();
	}
/*
  $('input[type=file]').each(function(){
    $(this).addClass('file').hide();
    //$(this).addClass('file').addClass('hidden');
    $(this).parent().append($('<div class="fakefile" />').append($('<input type="text" />').attr('id',$(this).attr('id')+'__fake')).append($('<img src="/images/widgets/file-inputs/si-btn-choose-file.gif" alt="" />')));
    $(this).bind('change', function() {
      $('#'+$(this).attr('id')+'__fake').val($(this).val());;
    });
    $(this).bind('mouseout', function() {
      $('#'+$(this).attr('id')+'__fake').val($(this).val());;
    });
  });
 */

	/* VALIDATE TRIBUTE FORM */
	// selector for form to be validated
	var the_form	= '#usp_form';

	// parent elements within form must allow JQuery-created labels to be visible
	$(the_form + ', ' + the_form + ' *').not('input[type="file"]').css('position', 'relative').css('overflow', 'visible');

	if (jQuery.isFunction(jQuery.fn.validate) || ($.fn.validate)) {

/*
		// customise standard error messages
		jQuery.extend($.validator.messages, {
			maxWords: $.validator.format("Your tribute should be no more than {0} words")
		});
 */
		$(the_form).validate({
			debug: false,

			// display error box at top of form if there are errors on submit, and update on blur as errors are corrected
			showErrors: function(errorMap, errorList) {
				var errors = this.numberOfInvalids();
				$(the_form + ' div.error').remove();
				if (errors) {
					var message = errors == 1 ? 'You missed 1 field. It has been highlighted' : 'You missed ' + errors + ' fields. They have been highlighted';
					var $error_msg = $('<div class="error">' + message + '</div>');
					$(the_form).prepend($error_msg);
				} else {
					$(the_form + ' div.error').remove();
				}
				this.defaultShowErrors();
			},

/*
			// insert message box at top of form if there are errors, but don't update on blur
			invalidHandler: function(form, validator) {
				var errors = validator.numberOfInvalids();
				$(the_form + ' div.error').remove();
				if (errors) {
					var message = errors == 1 ? 'You missed 1 field. It has been highlighted' : 'You missed ' + errors + ' fields. They have been highlighted';
					var $error_msg = $('<div class="error">' + message + '</div>');
					$(the_form).prepend($error_msg);
				} else {
					$(the_form + ' div.error').remove();
				}
			},
 */
			// validation rules for each form field
			rules: {
				'user-submitted-name': {
					required: true,
					minlength: 2
				},
				'user-submitted-url': {
					required: true,
					email: true
				},
				'user-submitted-title': {
					required: true,
					minlength: 2
				},
				'user-submitted-content': {
					//maxlength: 300,
					maxWords: 50
				}
			},
			// custom messages for each rule
			messages: {
				'user-submitted-content': {
					maxWords: $.format("Your tribute should be no more than {0} words")
				}
			}
		});

	}

	// doesn't work, probably because labels are created only after validate() runs
	$('label.error').css('border', '1px solid red');

});

var numPartners;
var currPartner;
var shiftPartner;
var prevPartner;

function initHomePartners () {
	numPartners = 3;
	currPartner = 1;
}
function homePartnerShift (dir) {
	if (currPartner + dir < 1) {
		shiftPartner = numPartners;
	} else if (currPartner + dir > numPartners) {
		shiftPartner = 1;
	} else {
		shiftPartner = currPartner + dir;
	}

	homePartnerGo (shiftPartner);
}
function homePartnerGo (n) {
	// prevPartner = currPartner;
	if (n != currPartner) {
		document.getElementById('homePartnerBtn'+currPartner).style.backgroundPosition = '0px 0px';
		document.getElementById('homePartnerBtn'+n).style.backgroundPosition = '0px -21px';
		toggleDisplay(('homePartner'+currPartner), 0);
		toggleDisplay(('homePartner'+n), 1);
		currPartner = n;
	}
}

function checkDate(yr,mo,dt) {
	var mo=mo-1;
	var today=new Date();
	var userDateAt = location.search.substring().indexOf("today=");
	if (userDateAt > 0) {
		var userDateStr = location.search.substr(userDateAt+6);
		var userDateEnd =  userDateStr.indexOf("&");
		if (userDateEnd > 0) {
			userDateStr = userDateStr.substring (0,userDateEnd);
		}
		userDate = userDateStr.split(",");
		today.setFullYear(userDate[0]);
		today.setMonth(Number(userDate[1])-1);
		today.setDate(userDate[2]);
	}
	today.setMinutes(today.getMinutes()+10);
	var streetDate = new Date();
	streetDate.setFullYear(yr);
	streetDate.setMonth(mo);
	streetDate.setDate(dt);
	if(today >= streetDate) {
		return true;
	}else{
		return false;
	}
}

function loadPage (targURL) { //v2.0
	window.location.replace(targURL);
}

function newWindow(targURL, disclaimer) { //v2.0
	// alert ('js: disclaimer=='+disclaimer);
	if (disclaimer=='true') {
		MRCWin = window.open(redirectPageLoc+ targURL,'MRCWin');
	} else {
		MRCWin = window.open(targURL,'MRCWin');
	}
	MRCWin.window.focus();
}
function popup(targURL, w, h) { //v2.0
	var winl = (screen.width - w) / 3;
	var wint = (screen.height - h) / 3;
	coords = 'width='+w+',height='+h+',top='+wint+',left='+winl;

	MRCWin = window.open(targURL,'MRCPop', coords,'scrollbars=no,resizable=yes');
	MRCWin.window.focus();
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/****  BROWSER DETECTION  ****/
var chProtocol=window.location.protocol.toString(), chromeLocation=window.location.toString(), chAppVersion=navigator.appVersion.split("MSIE"), chBrwsrVer=parseFloat(chAppVersion[1]), chBrwsrAgnt=navigator.userAgent, chIsIE6=false, chIsIE7=false, chIsFirefox=false, chIsOpera=false, chIsSafari=false, chIsMac=false, chIsPC=false, chromeDebug=false;

/*
alert ("chBrwsrVer: "+chBrwsrVer+"; "+navigator.userAgent);
*/

if(navigator.userAgent.indexOf("MSIE")!=-1&&chBrwsrVer>7){
	chIsIE8=true;
} else if(navigator.userAgent.indexOf("MSIE")!=-1&&chBrwsrVer>6){
	chIsIE7=true;
} else if (navigator.userAgent.indexOf("MSIE")!=-1) {
	chIsIE6=true;
}
if(navigator.userAgent.indexOf("Firefox")!=-1){chIsFirefox=true;}
if(navigator.userAgent.indexOf("Opera")!=-1){chIsOpera=true;}
if(navigator.userAgent.indexOf("Safari")!=-1){chIsSafari=true;}
if(navigator.userAgent.indexOf("Macintosh")!=-1){chIsMac=true;}
if(navigator.userAgent.indexOf("Windows")!=-1){chIsPC=true;}
/****  END BROWSER DETECTION  ****/

/****  APPLY BROWSER-SPECIFIC STYLES  ****/
if (chIsIE6) {
	document.write('<link rel="stylesheet" href="http://marsharivkin.org/styles/c_ie6.css" type="text/css">');
} else if (chIsIE7) {
	document.write('<link rel="stylesheet" href="http://marsharivkin.org/styles/c_ie7.css" type="text/css">');
	document.write('<link rel="stylesheet" href="http://marsharivkin.org/styles/c_var.css" type="text/css">');
} else if (chIsSafari) {
	document.write('<link rel="stylesheet" href="http://marsharivkin.org/styles/c_var.css" type="text/css">');
} else {
	document.write('<link rel="stylesheet" href="http://marsharivkin.org/styles/c_var.css" type="text/css">');
}
/****  END BROWSER-SPECIFIC STYLES  ****/


/**** SWFObject ****/
function writeSWFObject (targ, swf, id, w, h, ver, bgClr) {
	// alert ("writeSWFObject ("+targ+", "+swf+", "+id+", "+w+", "+h+", "+ver+", "+bgClr+")");
	if (location.search) {
    	var queryString = "?"+location.search.substring(1, location.search.length);
	} else {
		var queryString = "";
	}
	var so = new SWFObject(swf, id, w, h, ver, bgClr);
	so.write(targ);
}


function toggleDisplay(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)    //NN4+
    {
       document.layers[szDivID].display = iState ? "block" : "none";
    }
    else if(document.getElementById)      //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.display = iState ? "block" : "none";
    }
    else if(document.all)       // IE 4
    {
        document.all[szDivID].style.display = iState ? "block" : "none";
    }
}

function submenuToggle (divID, force) // 1 visible, 0 hidden
{
    var menuObj = document.getElementById('navInner'+divID);
    var iconObj = document.getElementById('ctrl'+divID);
	if(menuObj.style.display == 'block')
    {
       menuObj.style.display = 'none'
       iconObj.style.background = 'url(http://marsharivkin.org/images/nav_inner_btn_expand.gif)';
    }
    else if (menuObj.style.display == 'none')
    {
       menuObj.style.display = 'block'
	   iconObj.style.background = 'url(http://marsharivkin.org/images/nav_inner_btn_contract.gif)';
    }
	  else if (force)
    {
       menuObj.style.display = 'none'
       iconObj.style.background = 'url(http://marsharivkin.org/images/nav_inner_btn_expand.gif)';
    } else {
       menuObj.style.display = 'block'
	   iconObj.style.background = 'url(http://marsharivkin.org/images/nav_inner_btn_contract.gif)';
	}
}


/****  adjust height of scrolling div in response to window height  ****/
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
				obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
		return curtop;
}


function initPage () {
	$("div.contentInner p:last").addClass("pLast");
	checkBgHeight ();
	checkBgHeight ();
	$("#mainNav li ul").hide();
	$("#mainNav li").hover(
        function () {
		$(this).children("ul").show();
		$(this).css('z-index', 1001);
        },function(){
		$(this).children("ul").hide();
		$(this).css('z-index', 1);
	});
}
function loadBgHeight () {
	$("div.contentInner p:last").addClass("pLast");
	checkBgHeight ();
	checkBgHeight ();
}
function checkBgHeight () {
	var marginDefault = 16;
	var winHt = $(window).height();
	var objSh = $('#ctrShadow');
	var objFooter = $('#footer');
	var objContainer = $('div.ctrContainer');
	var cntHt = $('div.ctrContainer').height();
	var footerMargin;
	var footerHt = objFooter.height();
	var footerTop = objFooter.offset().top;
	var footerY = (footerTop + footerHt);
	var adjustY = 0;
	if (footerY < winHt) {

		if (objFooter.margin().top > 0) {
			// footer already expanded, user resizing; adjust accordingly
			// alert ("objFooter.margin().top > 0: "+objFooter.margin().top)
			addMargin = (winHt - footerY);
			objFooter.margin({top:objFooter.margin().top + addMargin});
		} else {
			// expand footer margin-top
			// alert ("objFooter.margin().top <= 0: "+objFooter.margin().top)
			footerMargin = (winHt - footerY);
			objFooter.margin({top:footerMargin});
		}

		objSh.height(objFooter.height() + objFooter.offset().top);

	} else {


		if (objFooter.margin().top > 0) {
			// alert (objFooter.margin().top);

			// footer already expanded, user resizing; adjust accordingly
			footerMargin = (objFooter.margin().top + winHt - footerY);
			if (footerMargin<0) {
				footerMargin = 0;
			}
			objFooter.margin({top:footerMargin});

		}

		objSh.height(objFooter.height() + objFooter.offset().top);

	}
}


//-->
