/// <reference path="jquery/jquery-1.5.min-vsdoc.js" />

function profilewindow(uri) {
    window.open(uri, '_blank', 'width=825,height=700,location=yes,status=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=yes,copyhistory=yes');
}

function sendmessagewindow(uri) {
    window.open(uri, '_blank', 'width=480,height=480,location=yes,status=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=yes,copyhistory=yes');
}

function messagehistorywindow(uri) {
    window.open(uri, 'gaynetworkmessagehistory', 'width=560,height=500,location=yes,status=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=yes,copyhistory=yes');
}

function webtvwindow(uri) {
    window.open(uri, '_blank', 'width=620,height=480,location=yes,status=yes,resizable=no,toolbar=no,menubar=no,scrollbars=no,copyhistory=no');
}

function readmessageswindow(uri) {
    var obj = window.open(uri, 'gaynetworkmessages', 'width=760,height=800,location=no,status=yes,resizable=yes,toolbar=no,scrollbars=yes,copyhistory=yes');
    //window.blur();
    if (obj != null) {
    	obj.focus();
    }
}

function photoviewerwindow(uri) {
    window.open(uri, '_blank', 'width=480,height=400,location=yes,status=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=yes,copyhistory=yes');
}

function termswindow(uri) {
    window.open(uri, '_blank', 'width=825,height=640,location=yes,status=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=yes,copyhistory=yes');
}

function confirmationprompt(message) {
    return confirm(message);
}

function closewindow() {
    window.close();
}

function waitandclosewindow(milliseconds) {
	var intervalMs = milliseconds;
	var jsStatement = "self.close()";
	setTimeout(jsStatement, intervalMs);
}

function waitandclosewindowdefault() {
	waitandclosewindow(3000);
}

function hideelement(elementId) {
	$('#' + elementId).hide();
	//var element = document.getElementById(elementId);
	//element.style.visibility = 'hidden';
}

function showelement(elementId) {
	var element = document.getElementById(elementId);
	if (element != null) {
		element.style.visibility = 'visible';
	}
}

function textCounter(fromElementId, toElementId, maxlimit) {
	var fieldIn = document.getElementById(fromElementId);
	var fieldOut = document.getElementById(toElementId);

	if (fieldIn !=null && fieldIn.value.length > maxlimit) {
		fieldIn.value = fieldIn.value.substring(0, maxlimit);
	}
	else if (fieldOut != null) {
		fieldOut.value = maxlimit - fieldIn.value.length;
	}
}

//show hide Tooltips
function showHelp(elementId) {
	$(elementId).slideToggle();
}

// Adds .click() function to an anchor control if it is not supported (e.g. in Firefox).
// This enables the DefaultButton functionality to work for an ASP.NET LinkButton control.
function addClickToLinkButton(button) {
	if (button && typeof (button.click) == 'undefined') {
		button.click = function() {
			var result = true;
			if (button.onclick) result = button.onclick();
			if (typeof (result) == 'undefined' || result) { eval(button.getAttribute('href')); }
		}
	}
}

// Adds .click() function to any controls with the CSS class "defaultButton"
function addClickToDefaultButtons() {
	var defaultButtons = $('.defaultButton');
	for (i = 0; i < defaultButtons.length; i++) {
		var defaultButton = defaultButtons[i];
		addClickToLinkButton(defaultButton);
	}
}

// Sets validation status of all validators in the specified validation group to true
function resetValidation(validationGroup) {
	if (Page_Validators != null) {
		for (i = 0; i < Page_Validators.length; i++) {
			var validator = Page_Validators[i];
			if ((typeof (validator.enabled) == "undefined" || validator.enabled != false) && IsValidationGroupMatch(validator, validationGroup)) {
				validator.isvalid = true;
				ValidatorUpdateDisplay(validator);
			}
			ValidatorUpdateIsValid();
		}
	}
}

$(document).ready(function() {
	addClickToDefaultButtons();
	if (typeof (Sys) != 'undefined' && typeof (Sys.WebForms) != 'undefined' && typeof (Sys.WebForms.PageRequestManager) != 'undefined' && typeof (endRequestHandler) != 'undefined') {
		Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
	}
});

