function ShowFriendsHelpDialog() {
	eXpress.Web.UI.Website.UiService.GetSmallHelpDialog("Mypages.Friends.Help", RenderSmallDialog);
}
function ShowMyLatestOrderHelpDialog() {
	eXpress.Web.UI.Website.UiService.GetSmallHelpDialog("Mypages.Main.MyLatestOrderHelp", RenderSmallDialog);
}
function ShowMyLatestAlbumsHelpDialog() {
	eXpress.Web.UI.Website.UiService.GetSmallHelpDialog("Mypages.Main.MyLatestAlbumsHelp", RenderSmallDialog);
}
function ShowMyLatestAlbumsFriendsHelpDialog() {
	eXpress.Web.UI.Website.UiService.GetSmallHelpDialog("Mypages.Main.MyLatestAlbumsFriendsHelp", RenderSmallDialog);
}
function ShowMyLatestProjectHelpDialog() {
	eXpress.Web.UI.Website.UiService.GetSmallHelpDialog("Mypages.Main.MyLatestProjectHelp", RenderSmallDialog);
}
function ShowImportFriendsDialog() {
	eXpress.Web.UI.Website.UiService.GetImportFriendsDialog(ShowImportFriendsDialogComplete);
}
function ShowImportFriendsDialogComplete(result) {
	CreateOverlayDialog(result, true, 'dialogSmall importFriend');
}
function ShowDeleteFriendsDialog() {
	if (selectedContacts.length > 0)
		eXpress.Web.UI.Website.UiService.GetDeleteFriendsDialog(selectedContacts, RenderSmallDialog);
	else
		lalert("Mypages.Friends.remove.selectfirst");
}

function OnContactFunctionComplete(obj) {
	if (obj.Result) {
		CloseDialog();
		window.location.reload();
	}
	else {
		alert(obj.Message);
	}
}

function ImportFriends(accountid) {

}

var selectedContacts = new Array();

function SetContactSelected(id, checked) {
	if (!checked) {
		var newCol = new Array();
		for (i = selectedContacts.length - 1; i >= 0; i--) {
			if (selectedContacts[i] != id) {
				newCol[newCol.length] = selectedContacts[i];
			}
		}
		selectedContacts = newCol;
	} else {
		selectedContacts[selectedContacts.length] = id;
	}
}

function DeleteContacts() {
	var object = new eXpress.Web.UI.Website.ContactFunctionResult();
	object.contactids = selectedContacts;
	eXpress.Web.UI.Website.UiService.DeleteContacts(object, OnContactFunctionComplete);
}

// Order functions Invoice & creditnotes

function CallCreditNote(id) {
    url = 'CreditNote.ashx?CreditNoteNumber=' + id;
    window.open(url, 'blank');

}

function CallOrderInvoice(id) {
	url = 'InvoiceOrder.ashx?OrderNumber=' + id;
	window.open(url, 'blank');

}

function HideSaveMessage(messageControlId) {
	var messageControl = $get(messageControlId);
	if (messageControl) {
		messageControl.style.visibility = 'hidden';
	}
}

// city dropdown logic
function ProfileCityChanged() {
	$get(txtCity).value = $get(lstCity).value;
}

function ProfileGetCitiesForZip(zip) {
	getCity = false;
	foundValidator = false;
	if (typeof (zipcodeRegExValidatorId) == "undefined") {
		getCity = true
	}
	else {
		for (i = 0; i < Page_Validators.length; i++) {
			if (Page_Validators[i].id == zipcodeRegExValidatorId) {
				foundValidator = true;
				getCity = Page_Validators[i].isvalid;
				break;
			}
		}
	}
	// When we can't find the validator, we just do it.
	if (getCity || !foundValidator)
		eXpress.Web.UI.Website.UiService.GetCitiesForZip($get(lstCountry).value, zip, ProfileGetCitiesForZipComplete);
	else
		ProfileGetCitiesForZipComplete(''); // Make sure we have a textbox

}
var originalvalue = '';

function ProfileGetCitiesForZipComplete(res) {
	ddl = $get(lstCity);
	textboxCity = $get(txtCity);

	for (i = ddl.options.length - 1; i >= 0; i--) {
		ddl.options[i] = null;
	}

	if (res.length > 0) {
		textboxCity.value = res[0];
		textboxCity.style.display = "none";
		ddl.style.display = "";
		for (i = 0; i < res.length; i++) {
			ddl.options[i] = new Option(res[i], res[i]);
			if (originalvalue == res[i]) {
				ddl.options[i].selected = true;
				textboxCity.value = res[i];
			}
		}
	}
	else {
		//textboxCity.value = ""; // do not reset, will reset values if zipcode is incomplete
		textboxCity.style.display = "";
		ddl.style.display = "none";
	}

	originalvalue = '';
}

function ProfileSyncCities(txtZipCode) {
	originalvalue = $get(txtCity).value;
	ProfileGetCitiesForZip($get(txtZipCode).value);
}

// Functions for PersonalDataAddress control
/*
function ForceLoginOnEnter(e, validationGroup) {
if (e.keyCode == 13) {
if (!TriggerValidationCallout(validationGroup)) {
return false;
}        
AutoCompleteSaveForm();
if (typeof (ForceLogin) != "undefined") {
ForceLogin();
}
}
}
*/

function CheckMobilnumberprefix(source, args) {
	if (source) {
		var clientId = source.id.replace("rxvalPrefixMobile", "")
		var val = args.Value.trim();
		var textMobile = $get(clientId + "txtMobile");
		var textMobileText = textMobile.value.trim()

		if (textMobileText.length > 0 && val.length <= 0) {
			args.IsValid = false;
		}
		else {
			args.IsValid = true;
		}
	}
}


function FilterKeyPressNumeric(evt, obj) {
	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) {
		var charCode = (evt.charCode) ? evt.charCode :
                                ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
		var ch = String.fromCharCode(charCode);
		if (charCode >= 48 && charCode <= 57) {
			if (!(charCode == 48 && obj.value.length == 0))
				return;
		}
		if (window.event)
			evt.returnValue = false;
		else
			evt.preventDefault();
	}
}

function limitLength(evt, obj, maxlen) {
	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) {
		if (obj.value.length >= maxlen) {
			evt.returnValue = false;
			return;
		}
	}
}

function BringToTop(position) {
	switch (position) {
		case 'left':
			ChangeDivClassName('myExtraFilmMainLeft', 'bringToBottom', 'bringToTop');
			ChangeDivClassName('myExtraFilmMainRight', 'bringToTop', 'bringToBottom');
			break;
		case 'right':
			ChangeDivClassName('myExtraFilmMainRight', 'bringToBottom', 'bringToTop');
			ChangeDivClassName('myExtraFilmMainLeft', 'bringToTop', 'bringToBottom');
			break;
	}
	if ((typeof (Page_Validators) != "undefined") && (Page_Validators != null)) {
		var i;
		for (i = 0; i < Page_Validators.length; i++) {
			if (Page_Validators[i].ValidatorCalloutBehavior)
				Page_Validators[i].ValidatorCalloutBehavior.hide();
		}
	}
}

function ChangeDivClassName(id, oldcss, newcss) {
	var div = $get(id)
	if (div) {
		Sys.UI.DomElement.removeCssClass(div, oldcss);
		if (!Sys.UI.DomElement.containsCssClass(div, newcss)) {
			Sys.UI.DomElement.addCssClass(div, newcss);
		}
	}
}

function PerformValidation(valgroup) {
	for (var i = 0; i < Page_Validators.length; i++) {
		if (Page_Validators[i].validationGroup == valgroup) {
			var val = Page_Validators[i];
			ValidatorValidate(val, valgroup);
		}
	}
}