
	var xForm = -1;
/* ----------------------------  */
function updateColorField(fieldName){
	document.getElementById(fieldName).style.background = document.getElementById(fieldName).value;
};

function updatePageTitleFields(){
	document.getElementById("page_title").value = document.getElementById("page_name").value;
	document.getElementById("text_head").value = document.getElementById("page_name").value;	
};

function updateFormBySelect(handle,URL){

	// Determine prefix
	if (URL.indexOf("?") != -1){
		var prefix = "&";
	}else{
		var prefix = "?";
	}

	switch (handle)
  {

    case "ADMIN_EDIT_ARTICLE": { 
		if(URL.match(/aID/)){
			document.location = URL.replace(/aID=\d/, "aID="+document.articleForm.article_id.value);			
		}else{
			document.location = URL + prefix + "aID=" + document.articleForm.article_id.value;
		}
		break;
	}
	
	case "ADMIN_NEW_ARTICLE_EDITION": { 
		if(URL.match(/edition/)){
			document.location = URL.replace(/edition=\d/, "edition="+document.articleForm.editionId.value);			
		}else{
			document.location = URL + prefix + "edition=" + document.articleForm.editionId.value;
		}
		break;
	}

    case "ADMIN_UPDATE_GROUP_CHOOSE_GROUP": { 
		if(URL.match(/gID/)){
			document.location = URL.replace(/gID=\d/, "gID="+document.chooseGroup.gID.value);			
		}else{
			document.location = URL + prefix + "gID=" + document.chooseGroup.gID.value;
		}
		break;
	}

    case "ADMIN_NEW_PAGE_EDITION": { 
		if(URL.match(/edition/)){
			document.location = URL.replace(/edition=\d/, "edition="+document.newPage.editionId.value);			
		}else{
			document.location = URL + prefix + "edition=" + document.newPage.editionId.value;
		}
		break;
	}

    case "ADMIN_UPDATE_PAGE_EDITION": { 
		if(URL.match(/edition/)){
			document.location = URL.replace(/edition=\d/, "edition="+document.updatePage.editionId.value);			
		}else{
			document.location = URL + prefix + "edition=" + document.updatePage.editionId.value;
		}
		break;
	}
	
    case "ADMIN_UPDATE_CHOOSE_PAGE_EDITION": { 
		if(URL.match(/edition/)){
			document.location = URL.replace(/edition=\d/, "edition="+document.choosePage.editionId.value);			
		}else{
			document.location = URL + prefix + "edition=" + document.choosePage.editionId.value;
		}
		break;
	}	
	
    case "ADMIN_UPDATE_USER_CHOOSE_USER": { 
		if(URL.match(/uID/)){
			document.location = URL.replace(/uID=\d/, "uID="+document.chooseUser.userID.value);			
		}else{
			document.location = URL + prefix + "uID=" + document.chooseUser.userID.value;
		}
		break;
	}	
	
    case "ADMIN_UPDATE_DELETE_PAGE_EDITION": { 
		if(URL.match(/edition/)){
			document.location = URL.replace(/edition=\d/, "edition="+document.deletePage.editionId.value);			
		}else{
			document.location = URL + prefix + "edition=" + document.deletePage.editionId.value;
		}
		break;
	}
	
    case "ADMIN_DELETE_USER": { 
		if(URL.match(/uID/)){
			document.location = URL.replace(/uID=\d/, "uID="+document.deleteUser.uID.value);			
		}else{
			document.location = URL + prefix + "uID=" + document.deleteUser.uID.value;
		}
		break;
	}	

    case "ADMIN_NEW_PAGE_PAGE_TYPE": {
	  var theForm	= getFormObject("newPage");
	 if(theForm.pageType.value=="ADMIN_PAGE"){	
		var theObject 		= getHTMLObject("adminPage");
		theObject.style.display 	= "block";
		var theObject 		= getHTMLObject("adminPage_header");
		theObject.style.display 	= "block";
	  }else{
		var theObject 		= getHTMLObject("adminPage");
		theObject.style.display 	= "none";
		var theObject 		= getHTMLObject("adminPage_header");
		theObject.style.display 	= "none";
	  }
	  
	}

    case "ADMIN_UPDATE_PAGE_CHOOSE_PAGE": { 
		if(URL.match(/pageID/)){
			document.location = URL.replace(/pageID=.+/, "pageID="+document.choosePage.pageID.value);			
		}else{
			document.location = URL + prefix + "pageID=" + document.choosePage.pageID.value;
		}
		break;
	}

    case "ADMIN_DELETE_PAGE_CHOOSE_PAGE": { 
		if(URL.match(/pageID/)){
			document.location = URL.replace(/pageID=.+/, "pageID="+document.deletePage.pageID.value);			
		}else{
			document.location = URL + prefix + "pageID=" + document.deletePage.pageID.value;
		}
		break;
	}


    default: {break}
  }
};


/* USER AUTO COMPLETE */
$(function($) { 

	$(".swlUserPicker > input.inputUserAutoComplete").focus(function () {
		if ($(this).val()=="Sök användare här"){
			$(this).val("");
		  	$(this).parent().find("input.destinationField").val("0");
		}
	});

	$(".swlUserPicker > input.inputUserAutoComplete").keyup(function () {
	  userInputStr 	= this.value;
	  userField 	= $(this);
	  destField		= userField.parent().find("input.destinationField").attr("id");
	  valueField	= userField.attr("id");	  
	  
		if(userInputStr.length>2){
			$.ajax({
			url : "/core/coreSrc/ajax/user-picker.asp",
			data : "userSearch="+userInputStr+"&desinationField="+destField+"&valueField="+valueField,
			error : function(data,string) {alert(string);},
			success : function (data) {
				userField.parent().find("div.autoCompleteContainer").slideDown("fast").animate({opacity: "0.8"}, "fast").html(data);
				}		
			});
		}
	});

	$(".swlUserPicker > input.inputUserAutoComplete").change(function () {
		if ($(this).val().length==0){
			$(this).val("Ingen användare vald");
		  	$(this).parent().find("input.destinationField").val("0");
		}
		$("div#autoComplete"+$(this).parent().find("input.destinationField").attr("id")).slideUp("slow");		
	});

});

function userAutoCompleteFill(tempName,tempId,destinationField,valueField){
	$("input#"+destinationField).val(tempId);
	$("input#"+valueField).val(tempName);
	$("div#autoComplete"+destinationField).slideUp("slow");
}
