//-------------- Page Management Functions ------------------------------------------
function navigate(location)
{
    window.location='index.php?fa='+location;

}

function submit_form()
{
    document.getElementById("lang_id").value = document.getElementById("page_language").value;
    document.frm2.submit();
}
function subFormClick(fName, arNames, arData,goTo){
		for(i=0;i<arNames.length;i++){
			var newInput = document.createElement('div');
			newInput.innerHTML = "<input type='hidden' name='"+arNames[i]+"' value='"+arData[i]+"'>";
			document.getElementById(fName).appendChild(newInput);
		}

		document.forms[fName].action=goTo;
		document.forms[fName].submit();
}
function processOrder(e,form_id)
{
    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        /*var str = "";

        for(var x=0;x<(document.getElementById("order_size").value-1);x++)
        {
            var order = document.getElementById("order_"+x+"").value;
            var page_id = document.getElementById("order_val_"+x+"").value;
            str += page_id+"-"+order+",";
        }

        document.getElementById("modified_order").value = str;*/

        var page_id = document.getElementById("page_id_"+form_id).value;
        var old_value = document.getElementById("order_"+form_id).value;
		var new_value = document.getElementById("order_"+form_id).value;
        $.ajax({
                type: "POST",
                url:"index.php?fa=page_management&action=change_order&fb=1",
                data:"page_id=" + page_id + "&old_value=" + old_value+ "&new_value=" + new_value,
                success: function(html){
                        jQuery.facebox(html);
                }
        });
    }
}



function deletePage(page_id)
{
    if(confirm("Are you sure you want to delete this page? (This Action cannot be Undone)"))
    {
        window.location = "index.php?fa=page_management&action=deletepage&id="+page_id;
    }
}


function deleteGoodiesAvatar(id)
{
    if(confirm("Confirmez-vous la suppression de la vignette ?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=goodies_management&action=delete_avatar",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert("Vignette supprimée");
				window.location = "index.php?fa=goodies_management&action=change_image&id="+id;
            }
    	});
    }
	
}

 function deleteFile(page_id,path)
 {
     if(confirm("Are you sure you want to delete this file '" + path + "' ?(This Operation will delete the entry and the physical file)"))
     {
         $.ajax({
                type: "POST",
                url:"views/ajax/deleteUserFile.php?fb=1",
                data:"page_id=" + page_id + "&path=" + path,
                success: function(html){
                    if(html == "1")
                        jQuery.facebox("Entry Deleted!");
                    else
                        jQuery.facebox("Entry Deleted, Physical File Deletion Failed!");

                    window.location.reload();
                }
        });
     }
 }

 function showThumb(src)
 {
     jQuery.facebox("<img src="+src+" />");
 }

 function changeMCE()
 {

     if(document.getElementById("product_type").value=="roof")
     {
        document.getElementById("colors").style.display='table-row';
        tinyMCE.execCommand('mceRemoveControl', false, 'elm1');

        tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions",

        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Example content CSS (should be your site CSS)
        //content_css : "css/content.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",

        // Style formats
        style_formats : [
                {title : 'Bold text', inline : 'b'},
                {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
                {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
                {title : 'Example 1', inline : 'span', classes : 'example1'},
                {title : 'Example 2', inline : 'span', classes : 'example2'},
                {title : 'Table styles'},
                {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
        ],

        // Replace values for the template plugin
        template_replace_values : {
                username : "Some User",
                staffid : "991234"
        }
});
     }
     else
     {
         document.getElementById("colors").style.display='none';
         tinyMCE.execCommand('mceRemoveControl', false, 'elm1');
         tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,imagemanager",

        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,insertimage",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Example content CSS (should be your site CSS)
        //content_css : "css/content.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",

        // Style formats
        style_formats : [
                {title : 'Bold text', inline : 'b'},
                {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
                {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
                {title : 'Example 1', inline : 'span', classes : 'example1'},
                {title : 'Example 2', inline : 'span', classes : 'example2'},
                {title : 'Table styles'},
                {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
        ],

        // Replace values for the template plugin
        template_replace_values : {
                username : "Some User",
                staffid : "991234"
        }
});
     }
 }

function changePageStatus(page_id,status,confirm_msg,ok_msg)
{

    if(confirm(confirm_msg))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=page_management&action=change_status&fb=1",
            data:"page_id=" + page_id + "&status=" + status ,
            success: function(html){
                alert(ok_msg);
                window.location.reload();
            }
    });
    }
}

function changeArtistStatus(id,status,confirm_msg,ok_msg)
{

    if(confirm(confirm_msg))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=artists_management&action=change_status&fb=1",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert(ok_msg);
                window.location.reload();
            }
    });
    }
}

//--------------- End Page Management Functions -------------------------------------------------

//--------------- Category Management Functions -------------------------------------------------
function ShowChildCategory(product_id,parent)
{    
    if(document.getElementById("arrow_shape_"+product_id).value=="0")
    {       
        $.ajax({
                type: "POST",
                url:"views/ajax/showChildrenCategories.php?product_id=" + product_id+"&fb=1",
                success: function(html){
                     //alert(html)
                        $("#child_list_"+product_id).html(html+"<div style='clear:both'>");
                        document.getElementById("icon_arrow_"+product_id).src = "images/down_arrow.png";
                        document.getElementById("arrow_shape_"+product_id).value="1";
                        document.getElementById("child_list_"+product_id).style.display="inline";
                }
        });
    }
    else
    {
        document.getElementById("icon_arrow_"+product_id).src = "images/right_arrow.png";
        document.getElementById("arrow_shape_"+product_id).value="0";
        document.getElementById("child_list_"+product_id).style.display="none";

    }
}

 function createCategory(product_id)
 {
    window.location = "index.php?fa=category_management&action=new&parent="+product_id;
 }

 function processOrderCategory(e,form_id)
{
    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        /*var str = "";

        for(var x=0;x<(document.getElementById("order_size").value-1);x++)
        {
            var order = document.getElementById("order_"+x+"").value;
            var page_id = document.getElementById("order_val_"+x+"").value;
            str += page_id+"-"+order+",";
        }

        document.getElementById("modified_order").value = str;*/

        var product_id = document.getElementById("product_id_"+form_id).value;
        var order_value = document.getElementById("order_"+form_id).value;

        $.ajax({
                type: "POST",
                url:"index.php?fa=category_management&action=change_order&fb=1",
                data:"product_id=" + product_id + "&page_order=" + order_value,
                success: function(html){
                    jQuery.facebox("Page Order Saved!");
                   
                }
        });
    }
}


//---------------- End Category Management Functions ----------------------------------------------------

function enableThumb(id)
{
    if(document.getElementById("en_"+id).checked)
        document.getElementById(id).disabled=false;
    else
        document.getElementById(id).disabled=true;
    
}

function deleteProduct(product_id)
{
    if(confirm("Etes-vous sûr de vouloir supprimer ce produit? (Cette action ne peut être annulé)"))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=delete&fb=1",
                data:"product_id=" + product_id,
                success: function(html){
                    alert("Produit supprimé!");
                    window.location="index.php?fa=products_management";


                }
        });
        
    }
}

function changeCategoryStatus(cat_id,status)
{
    var message="";
    if(status==0)
        message = "Changer le statut hors ligne?";
    else
        message = "Changer le statut à en ligne?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=artwork_category_management&action=change_status&fb=1",
            data:"id=" + cat_id + "&status=" + status ,
            success: function(html){
                alert("Changement de situation!");
                window.location.reload();
            }
    });
    }
}

function changeProductStatus(id,status)
{
    var message="";
    if(status==0)
        message = "Changer le statut de hors-ligne?";
    else
        message = "Changer le statut à en ligne?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=products_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert("Du changement de situation!");
                window.location.reload();
            }
    });
    }
}

//---------------- Box Management Functions ----------------------------------------------------
function deleteNews(news_id)
{
 if(confirm("Confirmez-vous la suppression de cette actualité ?"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=news_management&action=delete_news",
            data:"news_id=" + news_id,
            success: function(html){
                alert("Actu supprimée!");
                window.location.reload();
            }
    });
 }
}


function deleteArtist(id)
{
 if(confirm("Are you sure you want to delete this Artist and all his Info?(This Operation cannot be Undone)"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=artists_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert("Artist Deleted!");
                window.location.reload();
            }
    });
 }
}

function deleteCategory(id)
{
 if(confirm("Etes-vous sûr de vouloir supprimer cette catégorie et toutes ses infos? (Cette opération ne peut pas être annulé)"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=category_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert("Catégorie supprimés!");
                window.location.reload();
            }
    });
 }
}

//function deleteProduct(id)
//{
// if(confirm("Are you sure you want to delete this Product and all his Info?(This Operation cannot be Undone)"))
// {
//     $.ajax({
//            type: "POST",
//            url:"index.php?fa=products_management&action=delete",
//            data:"id=" + id,
//            success: function(html){
//                alert("Product Deleted!");
//                window.location.reload();
//            }
//    });
// }
//}

function deleteLink(id)
{
 if(confirm("Etes-vous sûr de vouloir supprimer ce lien définitivement ?"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=links_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert("Données sauvegardées");
                window.location.reload();
            }
    });
 }
}

function deleteGoodie(id)
{
 if(confirm("Etes-vous sûr de vouloir supprimer ce goodie définitivement?"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=goodies_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert("Données sauvegardées");
                window.location.reload();
            }
    });
 }
}

function changeNewsStatus(news_id,status)
{
    var message="";
    if(status==0)
        message = "Placer hors ligne ?";
    else
        message = "Placer en ligne ?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=news_management&action=change_status",
            data:"news_id=" + news_id + "&status=" + status ,
            success: function(html){
                 alert("Statut modifié");
                window.location.reload();
            }
    });
    }
}

function changeLinkStatus(link_id,status)
{
    var message="";
    if(status==0)
        message = "Placer hors ligne ?";
    else
        message = "Placer en ligne ?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=links_management&action=change_status",
            data:"link_id=" + link_id + "&status=" + status ,
            success: function(html){
                alert("Statut modifié");
                window.location.reload();
            }
    });
    }
}

function changeGoodieStatus(id,status)
{
    var message="";
    if(status==0)
        message = "Placer hors ligne ?";
    else
        message = "Placer en ligne ?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=goodies_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert("Statut modifié");
                window.location.reload();
            }
    });
    }
}

function changeArtistsStatus(id,status)
{
    var message="";
    if(status==0)
        message = "Placer hors ligne ?";
    else
        message = "Placer en ligne ?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=artists_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                 alert("Statut modifié");
                window.location.reload();
            }
    });
    }
}

function changeWorkshopStatus(id,status)
{
    var message="";
    if(status==0)
        message = "Placer hors ligne ?";
    else
        message = "Placer en ligne ?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=workshop_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                 alert("Statut modifié");
                window.location.reload();
            }
    });
    }
}

function deleteWorkshop(id)
{
 if(confirm("Etes-vous sûr de vouloir supprimer cet atelier et tous ses info? (Cette opération ne peut être annulée)"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=workshop_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert("Atelier supprimé!");
                window.location.reload();
            }
    });
 }
}

function processList()
{
    var output="";
    for(var i=0;i<document.getElementById("max_value").value;i++)
        {
            if(document.getElementById("checkbox_"+i).checked)
                output += document.getElementById("page_id_"+i).value+",";
        }
    document.getElementById("page_list").value = output;
    document.frmManagePage.submit();
    //alert(document.getElementById("page_list").value);
}

function changeUserStatus(user_id,status)
{
    var message="";
    if(status==0)
        message = "Change the Status to Offline?";
    else
        message = "Change the Status to Online?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=user_management&action=change_status&fb=1",
            data:"user_id=" + user_id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

function deleteUser(user_id)
{
    if(confirm("Are you sure you want to delete this User?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=user_management&action=delete&fb=1",
            data:"user_id=" + user_id ,
            success: function(html){
                alert("User Deleted!");
                window.location.reload();
            }
    });
    }
}

function validateUser()
{
//    if(document.getElementById("oldpasswd").value=="")
//    {
//        jQuery.facebox("Please enter Old Password");
//        document.getElementById("oldpasswd").focus();
//        return;
//    }

    if(document.getElementById("newpasswd").value=="")
    {
        jQuery.facebox("Please enter New Password");
        document.getElementById("newpasswd").focus();
        return;
    }

    if(document.getElementById("confirmpasswd").value=="")
    {
        jQuery.facebox("Please Confirm New Password");
        document.getElementById("confirmpasswd").focus();
        return;
    }

    if(document.getElementById("newpasswd").value != document.getElementById("confirmpasswd").value)
    {
        jQuery.facebox("Confirm Password do not match!");
        document.getElementById("confirmpasswd").focus();
        return;
    }

    document.fromCHangePasswd.submit();
}


//------------ Visitor Management -------------------------------
function changeUserStatus(user_id,status)
{
    var message="";
    if(status==0)
        message = "Change the Status to Offline?";
    else
        message = "Change the Status to Online?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=visitors_management&action=change_status&fb=1",
            data:"user_id=" + user_id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

function enablePassword()
{
    if(document.getElementById("enablepasswd").checked)
    {
        document.getElementById("password").disabled=false;
        document.getElementById("password").focus();
    }
    else
        document.getElementById("password").disabled=true;

}



function changeReference(prod_id,e)
{
    var unicode=e.keyCode? e.keyCode : e.charCode
    var product_ref = document.getElementById("ref_"+prod_id).value;

    if(unicode == 13)
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=products_management&action=change_ref",
            data:"prod_id=" + prod_id + "&product_ref=" + product_ref,
            success: function(html){
                //alert(html)
               if(html.search('ERROR')!=-1)
               {
                    alert("Cette référence existe déjà");
					
                    document.getElementById("ref_"+prod_id).value="";
               }
               else
               {
				   	alert("Référence mise à jour");
                    window.location.reload();
               }
            }
    });
    }
}

function deletePageBanner(page_id)
{
    if(confirm("Are you sure you want to delete this Banner?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=page_management&action=delete_banner",
            data:"page_id=" + page_id,
            success: function(html){
                if(html.search('DONE')!=-1)
                    {
                        alert("Banner Image Deleted!");
                        window.location.reload();
                    }
            }
        });
    }
}

function deleteCategoryBanner(product_id,image_id)
{
    if(confirm("Etes-vous sûr de vouloir supprimer ce bouton?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=category_management&action=delete_banner",
            data:"product_id=" + product_id + "&image=" + image_id,
            success: function(html){
                if(html.search('DONE')!=-1)
                    {
                        alert("Banner Image Deleted!");
                        window.location.reload();
                    }
            }
        });
    }
}

function deleteProductBanner(product_id,image_id)
{
    if(confirm("Are you sure you want to delete this Banner?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=products_management&action=delete_banner",
            data:"product_id=" + product_id + "&image=" + image_id,
            success: function(html){
                if(html.search('DONE')!=-1)
                    {
                        alert("Banner Image Deleted!");
                        window.location.reload();
                    }
            }
        });
    }
}

function changeArtworkStatus(id,status)
{
    var message="";
    if(status==0)
        message = "Changer le statut hors ligne?";
    else
        message = "Changer le statut à en ligne?";

    if(confirm(message))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=artwork_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert("Changement de situation!");
                window.location.reload();
            }
    });
    }
}

function changePassword(id)
{
    if(confirm("Réinitialiser le mot de cet utilisateur?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=visitors_management&action=change_password&fb=1",
            data:"id=" + id ,
            success: function(html){
                jQuery.facebox(html);
            }
        });
    }

}

function viewMoreVisitorDetails(id)
{
    $.ajax({
        type: "POST",
        url:"index.php?fa=visitors_management&action=more&fb=1",
        data:"id=" + id ,
        success: function(html){
            jQuery.facebox(html);
        }
});

}


function deleteArtwork(id)
{
 if(confirm("Etes-vous sûr de vouloir supprimer cette oeuvre et toutes ses infos? (Cette opération ne peut être annulée)"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=artwork_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert("Artwork supprimé!");
                window.location.reload();
            }
    });
 }
}

function deleteArtworkCategory(id)
{
 if(confirm("Etes-vous sûr de vouloir supprimer cette catégorie et toutes ses infos? (Cette opération ne peut être annulée)"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=artwork_category_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert("Catégorie supprimé!");
                window.location.reload();
            }
    });
 }
}

function changeStock(prod_id,e)
{
    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=update_stock",
                data:"id=" + prod_id + "&stock=" + document.getElementById("prod_stock_"+prod_id).value,
                success: function(html){
                    alert("Stock mis à jour!");
                    window.location.reload();
                }
        });
    }
}

function changeDeliveryType(prod_id,elem)
{
   $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=change_delivery_type",
                data:"id=" + prod_id + "&value=" + elem.value,
                success: function(html){
                    alert("Type de prestation changé!");
                    window.location.reload();
                }
        });
}

function changePrice(prod_id, val,e)
{
     var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=change_price",
                data:"id=" + prod_id + "&value=" + val,
                success: function(html){
                    alert("Prix mise à jour!");
                    window.location.reload();
                }
        });
    }
}

function changeDiscountPrice(prod_id, val,e)
{
     var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=change_discount_price",
                data:"id=" + prod_id + "&value=" + val,
                success: function(html){
                    alert("Prix mise à jour!");
                    window.location.reload();
                }
        });
    }
}

function subForm(fName, arNames, arData,goTo,e){
	var unicode=e.keyCode? e.keyCode : e.charCode;
    if(unicode == 13){
		for(i=0;i<arNames.length;i++){
			var newInput = document.createElement('div');
			newInput.innerHTML = "<input type='hidden' name='"+arNames[i]+"' value='"+arData[i]+"'>";
			document.getElementById(fName).appendChild(newInput);
		}

		document.forms[fName].action=goTo;
		document.forms[fName].submit();
	}
}

function changeWeight(prod_id, val,e)
{
     var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=change_weight",
                data:"id=" + prod_id + "&value=" + val,
                success: function(html){
                    alert("Poids mise à jour!");
                    window.location.reload();
                }
        });
    }
}

function changeVAT(prod_id, val,e)
{
     var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=change_vat",
                data:"id=" + prod_id + "&value=" + val,
                success: function(html){
                    alert("TVA mise à jour!");
                    window.location.reload();
                }
        });
    }
}

function deleteJPEG(page_id,lang)
{
    if(confirm("Etes-vous sûr de vouloir supprimer cette image?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=page_management&action=delete_jpeg",
            data:"page_id=" + page_id + "&lang="+lang,
            success: function(html){
                if(html.search('DONE')!=-1)
                    {
                        alert("Image supprimés!");
                        window.location.reload();
                    }
            }
        });
    }
}

function deleteHover(page_id,lang)
{
    if(confirm("Etes-vous sûr de vouloir supprimer cette image?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=page_management&action=delete_hover",
            data:"page_id=" + page_id + "&lang="+lang,
            success: function(html){
                if(html.search('DONE')!=-1)
                    {
                        alert("Image supprimés!");
                        window.location.reload();
                    }
            }
        });
    }
}

function showPanel()
{
    var html='';
    var val = document.getElementById("option_list").value;
    var count = document.getElementById("total").value;
    
    if(val==1)
    {
        if(confirm('Are you sure you want to delete these Users?'))
        {
            var op = "";
            for(var i=0;i<count;i++)
            {
                if(document.getElementById("count_"+i).checked)
                {
                    op +=document.getElementById("count_"+i).name + ","
                }
            }
            
            $.ajax({
                type: "POST",
                url:"index.php?fa=visitors_management&action=delete_list&fb=1",
                data:"user_ids=" + op ,
                success: function(html){
                    alert("Visitors Deleted!");
                    window.location.reload();
                }
            });
        }
    }
    
    if(val==2)
    {
        html = "<input type='text' name='mail_list' id='mail_list' value='' /><br><br><input type='button' onclick='savePanel()' value='Save' />";
        document.getElementById("contents").innerHTML = html;
    }
    
    if(val==3)
    {
        html = "<select id='status_options'><option value='1'>Dealer</option><option value='2'>Professional</option></select><br><br><input type='button'  onclick='savePanel()' value='Save' />";
        document.getElementById("contents").innerHTML = html;
    }
    
    if(val==4)
    {
        var op = "";
        for(var i=0;i<count;i++)
        {
            if(document.getElementById("count_"+i).checked)
            {
                op +=document.getElementById("count_"+i).name + ","
            }
        }
        
        $.ajax({
            type: "POST",
            url:"index.php?fa=visitors_management&action=flag&fb=1",
            data:"user_ids=" + op ,
            success: function(html){
                alert("Data saved Successfully!");
                window.location.reload();
            }
            });
    }
    
    if(val==5)
    {
        var op = "";
        for(var i=0;i<count;i++)
        {
            if(document.getElementById("count_"+i).checked)
            {
                op +=document.getElementById("count_"+i).name + ","
            }
        }
        
        $.ajax({
            type: "POST",
            url:"index.php?fa=visitors_management&action=flag&fb=0",
            data:"user_ids=" + op ,
            success: function(html){
                alert("Data saved Successfully!");
                window.location.reload();
            }
            });
    }
}

function savePanel()
{
    var val = document.getElementById("option_list").value;
    var count = document.getElementById("total").value;    
    var op="";
    
    if(val==3)
    {
        for(var i=0;i<count;i++)
        {
            if(document.getElementById("count_"+i).checked)
            {
                op +=document.getElementById("count_"+i).name + ","
            }
        }
            
        $.ajax({
            type: "POST",
            url:"index.php?fa=visitors_management&action=define&fb="+document.getElementById("status_options").value,
            data:"user_ids=" + op ,
            success: function(html){
                alert("Data saved Successfully!");
                window.location.reload();
            }
            });
    }
    
    if(val==2)
    {
        for(var i=0;i<count;i++)
        {
            if(document.getElementById("count_"+i).checked)
            {
                op +=document.getElementById("count_"+i).alt + ","
            }
        }
            
        $.ajax({
            type: "POST",
            url:"index.php?fa=visitors_management&action=save_mail_list",
            data:"emails=" + op + "&list_name="+document.getElementById("mail_list").value ,
            success: function(html){
                alert("Data saved Successfully!");
                window.location.reload();
            }
            });
    }
    
}

function viewMoreOrderDetails(id)
{
    $.ajax({
        type: "POST",
        url:"index.php?fa=order_management&action=more&fb=1",
        data:"id=" + id ,
        success: function(html){
            jQuery.facebox(html);
        }
});

}

function subFormImg(fName, arNames, arData,goTo,e){
	var unicode=e.keyCode? e.keyCode : e.charCode;
    if(unicode == 13){
		for(i=0;i<arNames.length;i++){
			var newInput = document.createElement('div');
			newInput.innerHTML = "<input type='hidden' name='"+arNames[i]+"' value='"+arData[i]+"'>";
			document.getElementById(fName).appendChild(newInput);
		}

		document.forms[fName].action=goTo;
		document.forms[fName].submit();
	}
}

function orderArtists(option)
{
	jQuery.facebox("<img src='/scripts/loading.gif'/>");
	 $.ajax({
        type: "POST",
        url:"/admin/views/ajax/order_artists.php",
        data:"option=" + option ,
        success: function(html){
            document.getElementById("scrollDiv").innerHTML = html;
			jQuery.facebox.close();
        }
});
}


function orderProducts(lang,id,url_label,type)
{
	jQuery.facebox("<img src='/scripts/loading.gif'/>");
	 $.ajax({
        type: "POST",
        url:"/admin/views/ajax/ajax_products.php?action=orderProducts",
        data:"lang=" + lang +"&id=" + id +"&url_label=" + url_label+"&type=" + type,
        success: function(html){
            document.getElementById("scrollDiv").innerHTML = html;
			jQuery.facebox.close();
        }
});
}

function orderLinks(lang,type)
{
	jQuery.facebox("<img src='/scripts/loading.gif'/>");
	 $.ajax({
        type: "POST",
        url:"/admin/views/ajax/ajax_links.php?action=orderLinks",
        data:"lang=" + lang +"&type=" + type,
        success: function(html){
            document.getElementById("scrollDiv").innerHTML = html;
			jQuery.facebox.close();
        }
});
}

function orderGoodies(lang,type)
{
	jQuery.facebox("<img src='/scripts/loading.gif'/>");
	 $.ajax({
        type: "POST",
        url:"/admin/views/ajax/ajax_goodies.php?action=orderGoodies",
        data:"lang=" + lang +"&type=" + type,
        success: function(html){
            document.getElementById("scrollDiv").innerHTML = html;
			jQuery.facebox.close();
        }
});
}


function orderProductsForArtist(lang,id,type)
{
	jQuery.facebox("<img src='/scripts/loading.gif'/>");
	 $.ajax({
        type: "POST",
        url:"/admin/views/ajax/ajax_products.php?action=orderProductsForArtist",
        data:"lang=" + lang +"&id=" + id +"&type=" + type,
        success: function(html){
            document.getElementById("scrollDiv").innerHTML = html;
			jQuery.facebox.close();
        }
});
}

function Paginator_Products(page)
{
    var search_string="";
    
    if(document.getElementById("search_text").value!="")
        search_string=document.getElementById("search_text").value;
    else
        search_string=document.getElementById("search_text_top").value;    
        
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"views/ajax/ajax_products.php?action=show_page&page="+page,
                data:"search_text="+search_string,
                success: function(html)
                {
                    document.getElementById("products_list").innerHTML=html;
                    document.getElementById("search_text").value=search_string;
                    document.getElementById("search_text_top").value=search_string;
                    jQuery.facebox.close();
                }
        });
}

function searchProductsAdmin()
{
    var old_key = "";
    old_key = document.getElementById("search_text").value;
           
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"views/ajax/ajax_products.php?action=search",
                data:"key="+old_key,
                success: function(html)
                {
                    document.getElementById("products_list").innerHTML=html;
                    document.getElementById("search_text").value=old_key;
                    document.getElementById("search_text_top").value=old_key;
                   
                    jQuery.facebox.close();
                }
        });
}

function searchProductsAdmin_Top()
{
    var old_key = "";
    
    old_key = document.getElementById("search_text_top").value; 

           
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"views/ajax/ajax_products.php?action=search",
                data:"key="+old_key,
                success: function(html)
                {
                    document.getElementById("products_list").innerHTML=html;
                    
                    document.getElementById("search_text_top").value=old_key;
                    document.getElementById("search_text").value=old_key;
                  
                    jQuery.facebox.close();
                }
        });
}
function showAllProducts()
{
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"views/ajax/ajax_products.php?action=showAll",
                success: function(html)
                {
                    document.getElementById("products_list").innerHTML=html; 
                    jQuery.facebox.close();
                }
        });
}

function changeApplyVat(id,status,msg_confirm,msg_ok)
{
	
    if(confirm(msg_confirm))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=countries_management&action=change_status&fb=1",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert(msg_ok);
                window.location.reload();
            }
    });
    }
}

function changeCountryStatus(id,status,msg_confirm,msg_ok)
{
	
    if(confirm(msg_confirm))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=countries_management&action=change_country_status&fb=1",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert(msg_ok);
                window.location.reload();
            }
    });
    }
}

function changeDeliveryDefaultFee(id, val,e,old_val,field)
{
     var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {	
        if(isNaN(val.replace(",",".")))
        {
            alert("Veuillez insérer une valeur numérique pour ce champ");
            document.getElementById(id).value=old_val;
        }
        else
        {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=countries_management&action=change_fee",
                    data:"id=" + id + "&value=" + val.replace(",",".")+"&field=" + field,
                    success: function(html){
						document.getElementById(id).value=(document.getElementById(id).value.replace(",",".")*1).toFixed(2);
                        alert("Prix modifié");                        
                    }
            });
        }
    }
}
