/*
	(c) Copyright Mobile Bridges Ltd 2005. All Rights Reserved.

	Project: Project independent
	Version: 1.0
	Date:    04-03-2006

	Description: Eventhandler for ActionForm, generated by Code Generator
*/

function OnFilter() {
	var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Filter";
    theForm.submit();
}

function OnSelect() {
	var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Select";
    theForm.submit();
}

function OnEdit() {
	var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Load";
    theForm.submit();
}

function OnInsert() {
	var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Add";
    theForm.submit();
}

function OnRemove(inConfirmation) {
	var isConfirmed = true;
	if (inConfirmation.length)
		isConfirmed = confirm(inConfirmation);
	if (isConfirmed) {
		var theForm = document.getElementById("ActionForm");
        theForm.theAction.value = "Remove";
        theForm.submit();
    }
}

function OnCancel() {
	var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Load";
    theForm.submit();
}

function OnSave() {
    var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Save";
    theForm.submit();
}

function changeEnter(e) {
    var keynum;
    var keychar;
    var numcheck;

    if(window.event) { // IE 
        keynum = e.keyCode;
    } else if(e.which) { // Netscape/Firefox/Opera
        keynum = e.which;
    }
    if(keynum==13) {
        document.getElementById('Create').focus()
    }
}

function OnAction(inAction) {
	var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = inAction;
    theForm.submit();
}

function OnCreateItem(inAction) {
    var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = inAction;
}

function OnQuickSearch() {   
	var theForm = document.getElementById("SearchForm");
    var search_text = theForm.SearchText.value;
    search_text = search_text.replace(/^\s+|\s+$/g,"");
    if (search_text != "") {
        theForm.submit();
    }
}

function OnAdvancedSearch() {   
	var theForm = document.getElementById("AdvancedSearchForm");
    theForm.theAction.value = "AdvancedSearch";
    theForm.submit();
}

function OnBack(inPage, inAction) {
	var theForm = document.getElementById("ActionForm");
	theForm.Page.value = inPage;
	theForm.theAction.value = inAction;
	theForm.submit();
}

function OnRedirect(inPage, inAction) {
    var theForm = document.getElementById("ActionForm");
    theForm.Page.value = inPage;
    theForm.theAction.value = inAction;
    theForm.submit();
}

function OnRedirectBlog(inPage, inAction, inBlogId) 
{
    var theForm = document.getElementById("ActionForm");
    theForm.Page.value = inPage;
    theForm.theAction.value = inAction;
    theForm.BlogId.value = inBlogId;  
    theForm.submit();
}




function OnRedictEditProfile(inPage, inAction, inCategory)
{
    var theForm = document.getElementById("ActionForm");
    theForm.Page.value = inPage;
    theForm.theAction.value = inAction;
    theForm.CategoryId.value = inCategory;
    theForm.submit();
}

function OnConfirm(inConfirmation, inPage, inAction) {
	var isConfirmed = true;
	if (inConfirmation.length)
		isConfirmed = confirm(inConfirmation);
	if (isConfirmed) {
		var theForm = document.getElementById("ActionForm");
		theForm.Page.value = inPage;
    	theForm.theAction.value = inAction;
    	theForm.submit();
	}
}

function RestoreSelectBox(inName, inValue) {
	var theSelectBox = document.getElementById(inName);
	if (theSelectBox) {
    	var theOptions = theSelectBox.options;
		for (i=0;i<theOptions.length;i++) {
            if (theOptions[i].value == inValue) {
				theOptions[i].selected = true;
				return true;
			}
		}
	}
}

function RestoreCheckBox(inName) {
	var theCheckBox = document.getElementById(inName);
	if (theCheckBox)
		theCheckBox.checked = !theCheckBox.checked;
}

function RestoreRadioButtonGroup(inName, inValue) {
	var theChildNodes = document.getElementsByTagName("input");
	for (i=0;i<theChildNodes.length;i++) 	{
		var theChildNode = theChildNodes.item(i);
		if (theChildNode.getAttribute("id") == inName) {
			theChildNode.checked = true;
			return;
		}
	}
}

function OpenWindow(inPage, inParams) {
    ventana = window.open(inPage,'ventana', inParams);
}

function OnChangeLanguage(inLanguageCode){
    var theForm = document.getElementById("BasicForm");
    theForm.Code.value = inLanguageCode;
    theForm.theAction.value = "ChangeLanguage";
    theForm.Location.value = document.location.href; 
    theForm.submit();
}

function OnLogout(){
    var theForm = document.getElementById("BasicForm");
    theForm.theAction.value = "Logout";
    theForm.submit();
}

function AddToFavorites(){
    var theForm = document.getElementById("ActionFavoriteForm");
    theForm.theAction.value = "Save";
    theForm.PageUrl.value = window.location.href;
    theForm.submit();
}

function FavoriteOnSubmit(){ 
    var theForm = document.getElementById("ActionFavoriteForm");
    if(theForm.PageUrl.value == ""){                
        return false;
    }else 
        return true;   
}

function OnLogin()
{
	var theForm = document.getElementById("LoginForm");
    
    var user_text = theForm.Username.value;
    var password_text = theForm.Password.value;
    
    user_text = user_text.replace(/^\s+|\s+$/g,"");
    password_text = password_text.replace(/^\s+|\s+$/g,"");
    
    if ((user_text != "") && (password_text != "")) {
        theForm.Page.value = "Login";
        theForm.theAction.value = "Login";
        return true;
    }
    return false;
}

function SetProfilePhoto(inImageId){
    var isConfirmed = true;
                
    if (isConfirmed){
        var theForm = document.getElementById("ActionForm");
        theForm.theAction.value = "SetProfilePhoto";
        theForm.ImageId.value = inImageId;
        theForm.submit();
    }
}

function SetAlbumPhoto(inImageId){
    var isConfirmed = true;
                
    if (isConfirmed){
        var theForm = document.getElementById("ActionForm");
        theForm.theAction.value = "SetAlbumPhoto";
        theForm.ImageId.value = inImageId;
        theForm.submit();
    }
}

function OnDeleteSelected() {
    var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "DeleteSelected";
    theForm.submit();
}

function SetTypeMobilPhone() {   
    var theForm = document.getElementById("ActionForm"); 
    theForm.TypeSave.value="SaveMobilPhone";
}
        
function SetTypeNewPassword() {
    var theForm = document.getElementById("ActionForm"); 
    theForm.TypeSave.value="SaveNewPassword";
}

function SetTypeNewEmail() {
    var theForm = document.getElementById("ActionForm"); 
    theForm.TypeSave.value="SaveNewEmailAddress";
}

function OnSaveForm() {
    var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = theForm.TypeSave.value;
    theForm.submit();
}

function OnDelete(inEventId, msg){
    var isConfirmed = true;

    inConfirmation = msg;
    if (inConfirmation.length)
        isConfirmed = confirm(inConfirmation);

    if (isConfirmed){
        var theForm = document.getElementById("ActionForm");
        theForm.theAction.value = "Delete";
        if(theForm.EventId != null) {
            theForm.EventId.value = inEventId;
        }
        theForm.submit();
    }
}
        
function showTooltip(id) {
    var msg = document.getElementById(id);
    msg.style.visibility='visible';
}

function hideTooltip(id) {
    var msg = document.getElementById(id);
    msg.style.visibility='hidden';
}

function moveToPage(inPageNr){
    var theForm;
    if(document.getElementById("ActionForm")){
        theForm = document.getElementById("ActionForm");
        theForm.PageNr.value = inPageNr;
        theForm.theAction.value = "Load";
    }             
    theForm.submit();
}

function moveToPageByAction(inPageNr,ActionForm,ActionName){
    var theForm;
    if(document.getElementById("ActionForm")){
        theForm = document.getElementById(ActionForm);
        theForm.PageNr.value = inPageNr;
        theForm.theAction.value = ActionName;
    }             
    theForm.submit();
}

function OnActionPage(ActionForm,Page,ActionName)
{
    var theForm = document.getElementById(ActionForm);
    theForm.Page.value = Page;
    theForm.theAction.value = ActionName;
    theForm.submit();
}

// It's used into AgendaFriendSelectorView
function OnRemoveFriend(inFriendId){
    var theForm = document.getElementById("ActionForm");
    theForm.FriendId.value = inFriendId;
    theForm.theAction.value = "Remove";
    theForm.submit();
}

// It's used into AlbumPanelView
function OnDeleteAlbum(inAlbumId, msg){
    var isConfirmed = true;
    
    inConfirmation = msg;

    if (inConfirmation.length)
        isConfirmed = confirm(inConfirmation);

    if (isConfirmed){
        var theForm = document.getElementById("ActionForm");
        theForm.theAction.value = "Delete";
        theForm.AlbumId.value = inAlbumId;
        theForm.submit();
    }
}

// It's used into AlbumPanelView
function OnProfilePage(inAlbumId,msg){
    var isConfirmed = true;
    
    inConfirmation = msg;

    if (inConfirmation.length)
        isConfirmed = confirm(inConfirmation);

    if (isConfirmed){
        $("#ActionForm #AlbumId").val(inAlbumId);
        AjaxOnAction("SetOnProfilePage", "#ActionForm")
    }
}

// It's used into AlbumPanelView
function showCreateNewAlbum()
{
    var createBox = document.getElementById("createNewAlbum");

    if (createBox.style.display == "none") {
        createBox.style.display = "block";
        document.getElementById("NewAlbumName").focus();    
    }
    else
    {
        document.getElementById("NewAlbumName").value = '';    
        createBox.style.display = "none";
    }    
}

// It's used into AlbumView
function OnDeleteSelectedPictures(msg){
    var isConfirmed = true;
    
    if($("input:checked").length > 0){
        inConfirmation = msg;
        if (inConfirmation.length)
            isConfirmed = confirm(inConfirmation);

        if (isConfirmed){
            var theForm = document.getElementById("ActionForm");
            theForm.theAction.value = "DeleteSelectedPictures";
            theForm.submit();
        }
    }
}

// It's used into AlbumView
function OnMoveAlbum(msg){
    var isConfirmed = false;
    var theForm = document.getElementById("ActionForm");
    var counter = 0;
    if (theForm.NewAlbumId.selectedIndex != 0) {
        theForm.AlbumSelected.value="1";
    }
    for (i=0;i<theForm.elements.length;i++) {
        if (theForm.elements[i].type == "checkbox") {
            if (theForm.elements[i].checked)
                counter++; 
        }                    
    }
    if (counter != 0) {
        theForm.ImageSelected.value="1";
    }
    if(theForm.ImageSelected.value=="1" && theForm.AlbumSelected.value=="1")
    {
        isConfirmed = confirm(msg);
        if (isConfirmed)
        {                                                   
           OnAction('Move');
        }
    }
    else
        OnAction('Move');
   
}

// It's used into BlogFolderPanelView and BlogPanelView
function OnRemoveBlog(inValue,msg){
    var isConfirmed = true;
    isConfirmed = confirm(msg);
    if (isConfirmed)
    {
        document.ActionForm.BlogId.value = inValue;
        document.ActionForm.theAction.value = "Remove";
        document.ActionForm.submit();
    }
}

// It's used into BlogPanelView
function OnRemoveBlogMessage(inValue,msg){
    var isConfirmed = true;
    isConfirmed = confirm(msg);
    if (isConfirmed)
    {
        document.ActionForm.BlogMessageId.value = inValue;
        document.ActionForm.theAction.value = "Remove";
        document.ActionForm.submit();
    }
    
}

// It's used into BlogPanelView
function OnMoveBlog(msg){
    var theForm = document.getElementById("ActionForm");
    var counter = 0;
    if (theForm.NewBlogId.selectedIndex != 0) {
        theForm.BlogSelected.value="1";
    }
    for (i=0;i<theForm.elements.length;i++) {
        if (theForm.elements[i].type == "checkbox") {
            if (theForm.elements[i].checked)
                counter++; 
        }                    
    }
    if (counter != 0) {
        theForm.MessageBlogSelected.value="1";
    }
    if(theForm.MessageBlogSelected.value=="1" && theForm.BlogSelected.value=="1")
    {
        isConfirmed = confirm(msg);
        if (isConfirmed)
        {                                                   
           OnAction('Move');
        }
    }
    else
        OnAction('Move');
    
}

// It's used into ExportMessageView
function OnActionOverlayExportMessage(inAction) {
    var theForm = document.getElementById("ActionFormExport");
    theForm.theAction.value = inAction;
    theForm.submit();

   
}

// It's used into FavoriteFolderPanelView
function showCreateNewFolder(){
    var createBox = document.getElementById("createNewFolder");

    if (createBox.style.display == "none") {
        createBox.style.display = "block";
        document.getElementById("NewFolderName").focus();    
    }
    else
    {
        document.getElementById("NewFolderName").value = '';    
        createBox.style.display = "none";
    }    
}

// It's used into FavoriteFolderPanelView
function OnDeleteFavoriteFolder(inFavoriteFolderId,msg){
    var isConfirmed = true;
    
    inConfirmation = msg;

    if (inConfirmation.length)
        isConfirmed = confirm(inConfirmation);

    if (isConfirmed){
        var theForm = document.getElementById("ActionForm");
        theForm.theAction.value = "Delete";
        theForm.FavoriteFolderId.value = inFavoriteFolderId;
        theForm.submit();
    }
}

// It's used into FavoritePanelView
function OnMoveFavorite(msg){            
var theForm = document.getElementById("ActionForm");
    var counter = 0;
    if (theForm.NewFavoriteFolderId.selectedIndex != 0) {
        theForm.FavoriteFolderSelected.value="1";
    }
    for (i=0;i<theForm.elements.length;i++) {
        if (theForm.elements[i].type == "checkbox") {
            if (theForm.elements[i].checked)
                counter++; 
        }                    
    }
    if (counter != 0) {
        theForm.FavoriteSelected.value="1";
    }
    if(theForm.FavoriteSelected.value=="1" && theForm.FavoriteFolderSelected.value=="1")
    {
        isConfirmed = confirm(msg);
        if (isConfirmed)
        {                                                   
           OnAction('Move');
        }
    }
    else
        OnAction('Move');
}

// It's used into FavoritePanelView
function OnChooseAllFavorites(checked){
    var i=0;
    for (i=0; i < document.ActionForm.elements.length; i++)
        if (document.ActionForm.elements[i].type.toLowerCase() == 'checkbox')
            document.ActionForm.elements[i].checked = checked;
}


function OptionButtonSelected(lform){
      var radio1 = document.getElementById("Option1");
      var radio0 = document.getElementById("Option0");
    
         if(radio1.checked == true){
         AjaxDownloadMail(lform);
          
         }else  if(radio0.checked == true){
            OnActionOverlayExportMessage('Download');CloseWindow();
             }   
   
     } 

// It's used into FavoritePanelView
function OnDeleteFavorite(inFavoriteId,msg){
    var isConfirmed = true;

    inConfirmation = msg;

    if (inConfirmation.length)
        isConfirmed = confirm(inConfirmation);

    if (isConfirmed){
        var theForm = document.getElementById("ActionForm");
        theForm.theAction.value = "Delete";
        theForm.FavoriteId.value = inFavoriteId;
        theForm.submit();
    }
}

// It's used into FolderPanelView
function OnChooseAllFolder(checked){
    var i=0;
    for (i=0; i < document.ActionForm.elements.length; i++)
        if (document.ActionForm.elements[i].type.toLowerCase() == 'checkbox')
            document.ActionForm.elements[i].checked = checked;
}

function OnChooseAllFriend(checked){   
    var i=0;
    for (i=0; i < document.OverlayForm.elements.length; i++)
        if (document.OverlayForm.elements[i].type.toLowerCase() == 'checkbox')
            document.OverlayForm.elements[i].checked = checked;
}  

// It's used into FriendRequestView
function OnApproveFriendRequest(inUserId){
    var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Approve";
    theForm.UserId.value = inUserId;
    theForm.submit();
}

// It's used into FriendRequestView
function OnDenyFriendRequest(inUserId){
    var theForm = document.getElementById("ActionForm");
    theForm.theAction.value = "Deny";
    theForm.UserId.value = inUserId;
    theForm.submit();
}

function moveToPage(inPageNr){
    var theForm = document.getElementById("ActionForm");
    theForm.PageNr.value = inPageNr;
    theForm.theAction.value = "Load";
    theForm.submit();                       
}