
function PageInit(){
LoopCommanderImages();

}

function LoopCommanderImages(){
var form = document.Main;
var iCounter = form.PersonImageCounter.value;
var iPersonID;

	if (iCounter > 0){
		for (i=1; i<=iCounter; i++) {
			iPersonID = form["PersonImageID"+i].value;
			iCommander1 = form["PersonImageCommander1_"+iPersonID].value;
			iCommander2 = form["PersonImageCommander2_"+iPersonID].value;
			GetCommanderImages(iPersonID, iCommander1, iCommander2);
		}
	}
}

function GetCommanderImages(iPersonID, iCommander1, iCommander2){

var strImage = "PersonImage" + iPersonID;
var oImage = getItem(strImage);

var iWidth = 0;
var iHeight = 0;
var oPictureDiv1;
var oPictureDiv2;

var iCommander1Width = 0;
var iCommander1Height = 0;
var iCommander2Width = 0;
var iCommander2Height = 0;

	iWidth = oImage.width;
	iHeight = oImage.height;

	oPictureDiv1 = getItem(oImage.id + "_Commander1");
	oPictureDiv1.style.zIndex = -50;
	oPictureDiv2 = getItem(oImage.id + "_Commander2");
	oPictureDiv2.style.zIndex = -150;

	iCommander1Width = oPictureDiv1.offsetWidth;
	iCommander1Height = oPictureDiv1.offsetHeight;
	iCommander2Width = oPictureDiv2.offsetWidth;
	iCommander2Height = oPictureDiv2.offsetHeight;

	if (iCommander1 == 1){
		oPictureDiv1.style.top = iHeight - iCommander1Height + "px";
		oPictureDiv1.style.left = iWidth - iCommander1Width + "px";
		oPictureDiv1.style.zIndex = 50;
	}
		
	if (iCommander2 == 1){
		oPictureDiv2.style.top = iHeight - iCommander2Height + "px";
		oPictureDiv2.style.zIndex = 150;
	}

}

function OpenSponsorPage(form, iSponsorID, strLodgeID) {
var	NewURL = "SponsorLink.asp?SponsorID=" + iSponsorID + "&LodgeID=" + strLodgeID;
    NewWin=window.open(NewURL,'','location=0,resizable=1,titlebar=1,directories=0,toolbar=1,menubar=1,scrollbars=1,status=1,width=900,height=600');
    return false;
}

function LostPassword(form) {
var	NewURL = "LostPasswordForm.asp";
    NewWin=window.open(NewURL,'','location=0,resizable=1,titlebar=1,directories=0,toolbar=1,menubar=1,scrollbars=1,status=1,width=740,height=500');
    return false;
}

function WebReload(form) {
	form.action = "WebPage.asp";
	form.submit();
}

function WebReload2(form) {
	form.Searching.value = "1";
	form.action="WebPage.asp";
	form.submit();	
}

function WebReload3(form) {
	form.Searching.value = "0";
	form.action="WebPage.asp";
	form.submit();	
}

function setCalendarMove(form, iYear, iMonth) {
	form.Year.value = iYear;
	form.Month.value = iMonth;
	form.action = "WebPage.asp";
	form.submit();
}

function WebCalendarDaySelect(form, iDay, iMonth, iYear, iLodge) {
var NewURL
var strID = form.ID.value;

	NewURL = "CalendarDay.asp?ID=" + strID + "&LodgeID=" + iLodge + "&CalendarYear=" + iYear + "&CalendarMonth=" + iMonth + "&CalendarDay=" + iDay;
    NewWin=window.open(NewURL,'','location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,width=580,height=400');
    return false;
 
}

function GetMap(form, strStreet, strCity) {
var strMapAddress = strStreet + ", " + strCity;
var positionX =((screen.availWidth / 2) - 750 / 2); 
var positionY =((screen.availHeight / 2) - 700 / 2);

	strMapAddress = escape(strMapAddress);
	
	NewURL = "http://www.hitta.se/SearchCombi.aspx?SearchType=4&z=8&UCSB%3aWflWhite=1a1b&UCSB%3aWflPink=4a&UCSB%3aTextBoxWho=&UCSB%3aTextBoxWhere=" + strMapAddress + "#contactlinks";
    NewWin=window.open(NewURL,'','location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,width=710,height=550,top='+positionY+',left='+positionX);
	return false; 
}

function GetFileData(iDataID, iDataType, iDataOriginType, w, h) {
var NewURL
	if (iDataType == 1){
		NewURL = "DataViewerHolder.asp?DataID=" + iDataID + "&DataType=" + iDataOriginType;
		NewWin=window.open(NewURL,'','location=0,resizable=1,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0,width='+w+',height='+h);
	}else{
		NewURL = "DocumentViewer.asp?DataID=" + iDataID + "&DataType=" + iDataOriginType;
		NewWin=window.open(NewURL,'','location=0,resizable=1,titlebar=1,directories=0,toolbar=0,menubar=1,scrollbars=1,status=0,width='+w+',height='+h);
	}   
    return false;
    
}

function GetGallery(form, iGalleryID, iLodgeID, w, h) {
var NewURL

	NewURL = "GalleryViewer3.asp?GalleryID=" + iGalleryID + "&LodgeID=" + iLodgeID;
    NewWin=window.open(NewURL,'','location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0,width='+w+',height='+h);
    return false;
}

function NewsMove(form, iNewsPosition, iNumber, iDirection) {
var iNewPosition
var iMaxPos = form.StopTot.value;
	if (iDirection == 1){
		iNewPosition = iNewsPosition - iNumber;
		if (iNewPosition < 1){
			iNewPosition = 1;
		}		
	}else{
		iNewPosition = iNewsPosition + iNumber;
		if (iNewPosition > iMaxPos){
			iNewPosition = iMaxPos;
		}
	}
	form.NewsPosition.value = iNewPosition;
	form.action = "WebPage.asp";
	form.submit();
}

function LongNewsMove(form, iLongNewsPosition, iLongNumber, iLongNewsCounter, iLongDirection) {
var iLongNewPosition
var iLongMaxPos = form["LongStopTot"+iLongNewsCounter].value;
	if (iLongDirection == 1){
		iLongNewPosition = iLongNewsPosition - iLongNumber;
		if (iLongNewPosition < 1){
			iLongNewPosition = 1;
		}		
	}else{
		iLongNewPosition = iLongNewsPosition + iLongNumber;
		if (iLongNewPosition > iLongMaxPos){
			iLongNewPosition = iLongMaxPos;
		}
	}
	
	form["LongNewsPosition"+iLongNewsCounter].value = iLongNewPosition;
	form.action = "WebPage.asp";
	form.submit();
}

function NewsArchiveToggle(form) {
var strNewsArchive = form.NewsArchive.value;
	if (strNewsArchive == "0"){
		form.NewsArchive.value = "1";
	}else{
		form.NewsArchive.value = "0";
	}
	form.action = "WebPage.asp";
	form.submit();
}

function MemberLogin(form) {

	form.action = "WebLoginValidation.asp";
	form.submit();
 
}

function Logout(form) {
	form.ID.value = "";
	form.PageID.value = "";
	form.action = "WebPage.asp";
	form.submit();
 
}

function Shield(form, iPersonID, iLodge) {
var positionX =((screen.availWidth / 2) - 750 / 2); 
var positionY =((screen.availHeight / 2) - 700 / 2);
	
	NewURL = "WebShowShield.asp?PersonID=" + iPersonID + "&PersonLodgeID=" + iLodge;
    NewWin=window.open(NewURL,'','location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,width=710,height=550,top='+positionY+',left='+positionX);
	return false; 
}

function Godfathers(form, iPersonID, iLodge) {
var positionX =((screen.availWidth / 2) - 750 / 2); 
var positionY =((screen.availHeight / 2) - 500 / 2);
var strString = "";

	strString = strString + "StartPersonID=" + iPersonID; 	
	strString = strString + "&StartPersonLodgeID=" + iLodge; 
	strString = strString + "&ID=" + form.ID.value;
	
	NewURL = "WebGodfathers.asp?" + strString;
    NewWin=window.open(NewURL,'','location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,width=750,height=600,top='+positionY+',left='+positionX);
	return false; 
}

function FormReset(form) {
	form.SearchFirstname.value="";
	form.SearchLastname.value=""; 
	form.SearchPhoneHome.value=""; 
	form.SearchPhoneJob.value=""; 
	form.SearchMobile.value=""; 
	form.SearchEmail.value="";  
	form.SearchAddress.value=""; 
	form.SearchCity.value="";  
	form.SearchZipCode.value="";  
	form.SearchTeam.selectedIndex=0; 
}

function SortSubmit(form, iSort){
	form.action = "WebPage.asp";
	form.SearchSort.value = iSort;
	form.submit();
}

function SortSubmit2(form, iSort){
	form.action = "WebPage.asp";
	form.MedalSort.value = iSort;
	form.submit();
}

function SearchSubmit(form){
var iType = form.SearchPresentation.value;
	form.action = "WebPage.asp";
	form.Searching.value = 1;
	form.PersonSearchLodgeID.value = form.SearchLodge.value;
	if (iType == 1){
		form.submit();
	}else{
		if (confirm(strSearchMessage)){
			form.submit();
		}
	}
}

function RecepieSearch(form){
	form.action = "WebPage.asp";
	form.Searching.value = 1;
	form.submit();
}

function RecepieReset(form) {
	form.RecepieName.value="";
	form.RecepieTalentGroup.selectedIndex=0;  
	form.RecepieTalentSubGroup.selectedIndex=0; 
	form.RecepieMealType.selectedIndex=0; 
	form.RecepieType.selectedIndex=0; 
	form.RecepieMainIngredient.selectedIndex=0; 
	form.RecepieAuthor.selectedIndex=0; 
}

function EditPerson(form, iPersonID, iLodgeID, iPageID) {
	form.action = "WebPage.asp";
	form.PersonSearchID.value = iPersonID;
	form.PersonSearchLodgeID.value = iLodgeID;
	form.PageContentID.value = iPageID;
	form.PageContentOverride.value = "override";
	form.submit(); 
}

function UpdatePerson(form, iLodgeID, iPersonID, w, h) {
var NewURL

	NewURL = "PersonUpdate.asp?PersonID=" + iPersonID + "&LodgeID=" + iLodgeID;
    NewWin=window.open(NewURL,'','location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0,width='+w+',height='+h);
    return false;
}


function UpdatePerson2(form, iLodgeID, iPersonID) {
var strErrorUpdatePersonMessage = CheckSubmit(form);

	if (strErrorUpdatePersonMessage == ""){
		form.action = "WebEditData.asp";
		form.LevelType.value = "EditWebPerson"
		form.PersonSearchID.value = iPersonID;
		form.PersonSearchLodgeID.value = iLodgeID;
		form.PageContentOverride.value = "override";
		form.submit();
	}else{
		alert("Felmeddelande: \n" + strErrorUpdatePersonMessage);
		return false;
	} 
}

function AddressMail(form, iLodgeID, w, h) {
var NewURL

	NewURL = "WebAddressMail.asp?LodgeID=" + iLodgeID + "&ID=" + form.ID.value;
	NewWin=window.open(NewURL,'','location=0,resizable=1,titlebar=1,directories=0,toolbar=0,menubar=1,scrollbars=1,status=0,width='+w+',height='+h);

    return false;
    
}

function CheckSubmit(form) {

var strError = "";
var strEmail
var strEmailHome
var strEmailJob
var strUserIDMessage = "";
var strPasswordMessage = "";

	if (isEmpty(trim(form.FirstName.value))) {
		strError = strError + strFirstNameMessage + "\n";
	}
	if (isEmpty(trim(form.CommonName.value))) {
		strError = strError + strFirstNameMessage + "\n";
	}	
	if (isEmpty(trim(form.LastName.value))) {
		strError = strError + strLastNameMessage + "\n";
	}
	if (isEmpty(trim(form.AddressHome.value))) {
		strError = strError + strAddressHomeMessage + "\n";
	}
	if (isEmpty(trim(form.ZipCodeHome.value))) {
		strError = strError + strZipCodeHomeMessage + "\n";
	}
	if (isEmpty(trim(form.CityHome.value))) {
		strError = strError + strCityHomeMessage + "\n";
	}
	if (isEmpty(trim(form.CountryHome.value))) {
		strError = strError + strCountryHomeMessage + "\n";
	}
	if (!isPhone(trim(form.PhoneHome.value))) {
		strError = strError + strPhoneHomeMessage + "\n";
	}
	if (!isPhone(trim(form.PhoneJob.value))) {
		strError = strError + strPhoneJobMessage + "\n";
	}
	if (!isPhone(trim(form.MobileHome.value))) {
		strError = strError + strMobileHomeMessage + "\n";
	}
	if (!isPhone(trim(form.MobileJob.value))) {
		strError = strError + strMobileJobMessage + "\n";
	}
	if (!isPhone(trim(form.FaxHome.value))) {
		strError = strError + strFaxHomeMessage + "\n";
	}
	if (!isPhone(trim(form.FaxJob.value))) {
		strError = strError + strFaxJobMessage + "\n";
	}
	
	strEmailHome = form.EmailHome.value;
	if (isEmpty(trim(strEmailHome))) {
	
	}else{
		if (!(strEmailHome.indexOf(".") > 0 && strEmailHome.indexOf(String.fromCharCode(64)) > 0)) {
			strError = strError + strEmailHomeMessage + "\n";
		}
	}
	strEmailJob = form.EmailJob.value;
	if (isEmpty(trim(strEmailJob))) {
	
	}else{
		if (!(strEmailJob.indexOf(".") > 0 && strEmailJob.indexOf(String.fromCharCode(64)) > 0)) {
			strError = strError + strEmailJobMessage + "\n";
		}
	}
	
	strUserIDMessage = isPassword(form.UserID.value, 1)
	
	if (strUserIDMessage != "") {
		strError = strError + strUserIDMessage + "\n";
	}
	
	strPasswordMessage = isPassword(form.Password.value, 2)
	
	if (strPasswordMessage != "") {
		strError = strError + strPasswordMessage + "\n";
	}
	
	return strError;
	
}

function GetNews(form, iNewsID, iPageID) {
	form.action = "WebPage.asp";
	form.NewsID.value = iNewsID;
	form.PageContentID.value = iPageID;
	form.PageContentOverride.value = "override";
	form.submit(); 
}

function GetNewsBack(form, iPageID) {
	form.action = "WebPage.asp";
	form.PageID.value = iPageID;
	form.PageContentOverride.value = "";
	form.submit(); 
}

function EditWebPage(form, iPageID) {

	form.action = "EditPage.asp";
	form.PageID.value = iPageID;
	form.submit();
 
}

function AddWebPage(form, iPageID) {

	form.action = "InsertData.asp";
	form.PageID.value = iPageID;
	form.LevelType.value = "AddPage";
	form.submit();
 
}

function BackAction(form) {

	form.action = "Site.asp";
	form.submit();
 
}

function PersonBackAction2(form) {

	//form.Searching.value = "1";
	//form.Searching.value = form.PersonSearchLodgeID.value;
	//form.action = "WebPage.asp";
	//form.submit();
	history.back();
 
}

function PersonBackAction(iHistoryAdjust) {

	//form.Searching.value = "1";
	//form.Searching.value = form.PersonSearchLodgeID.value;
	//form.action = "WebPage.asp";
	//form.submit();
	history.go(iHistoryAdjust);
 
}

function DeleteWebPage(form, iPageID) {
	if (confirm(strDeleteMessage)){
		form.action = "DeleteData.asp";
		form.PageID.value = iPageID;
		form.LevelType.value = "DeletePage";
		form.submit();
	}
 
}

function MoveWebPage(form, iPageID, iDirection) {

	if (iPageID == 1){
		alert(strMoveMessage);
	}else{
		form.action = "MoveWebPage.asp";
		form.PageID.value = iPageID;
		form.PageMoveDirection.value = iDirection;
		form.submit();
	}
 
}

function GetPage(form, iPageID) {
	form.action = "WebPage.asp";
	form.GalleryPageID.value = iPageID;
	form.submit(); 
}

function GetBulletinText(form, iBulletinID2, iBulletinID, iType) {
	openWin3("BulletinData.asp?BulletinID2="+iBulletinID2+"&BulletinID="+iBulletinID+"&Type="+iType, 500, 400);
}

function GetCalendarBooking(form, strWebNotificationID) {
	openWin3("WebCalendarNotification.asp?ID=" + strWebNotificationID, 660, 750);
}

function GetCalendarBooking2(form, iCalendarID, iLodgeID, iPersonID) {
	openWin3("BookingData.asp?CalendarID=" + iCalendarID + "&LodgeID=" + iLodgeID + "&PersonID=" + iPersonID, 660, 700);
}

function GetBigPicture(form, iGalleryPageGridID) {
var iGalleryItemID = form.GalleryItemID.value;
	openWin3("ImageGallery.asp?GalleryItemID="+iGalleryItemID+"&GalleryPageGridID="+iGalleryPageGridID, 800, 600);
}

function PrintRecepie(iRecepieID, w, h) {
var NewURL
	NewURL = "PrintRecepie.asp?RecepieID=" + iRecepieID;
    NewWin=window.open(NewURL,'','location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0,width='+w+',height='+h);
    return false;    
}

function TreeAction(form, iPageType, iPageID, iOpen){

	form.PageID.value = iPageID;
	form.PageType.value = iPageType;
	//form.PageOpen.value = iOpen;
	form.NewsArchive.value = "";
	form.PageContentOverride.value = "";
	form.action = "webpage.asp";
	form.submit();
}

floatX=60;
floatY=130;
layerwidth=220;
layerheight=100;
halign="right";
valign="top";
delayspeed=0;

function adjust() {
var oObject = getItem('FloatMenu');
	
	lastX=document.body.scrollLeft + floatX;
	lastY=document.body.scrollTop + floatY;
	
	//document.all['FloatMenu'].style.posLeft = lastX;
	//document.all['FloatMenu'].style.posTop = lastY;
	setPos(oObject, lastX, lastY);
	 
	setTimeout('adjust()',1);
}

function define(){

	if (halign=="left") {floatX=ifloatX};
	if (halign=="right") {floatX=document.body.offsetWidth-ifloatX-layerwidth-20}
	if (halign=="center") {floatX=Math.round((document.body.offsetWidth-20)/2)-Math.round(layerwidth/2)}
	if (valign=="top") {floatY=ifloatY};
	if (valign=="bottom") {floatY=document.body.offsetHeight-ifloatY-layerheight}
	if (valign=="center") {floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(layerheight/2)}

}


