// JavaScript Document
//-------------- 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 deleteCompany(id,msg)
{
    if(confirm(msg))
    {
        window.location = "index.php?fa=organisation_management&action=deleteCompany&id="+id;
    }
}
function deleteMember(id,msg)
{
    if(confirm(msg))
    {
        window.location = "index.php?fa=organisation_management&action=deleteMember&id="+id;
    }
}
function showPagesList(lang)
{
	jQuery.facebox("Loading...");
	$.ajax({
		type: "POST",
		url:"views/ajax/show_page_list.php?lang="+lang,
		success: function(html)
		{
			$(document).bind('beforeReveal.facebox', function() {
				$('#facebox .body').width('800px'); 
			});
			jQuery.facebox(html);
		}
	});
}
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 ShowChild(page_id,parent)
//{
//    if(document.getElementById("arrow_shape_"+page_id).value=="0")
//    {
//        $.ajax({
//                type: "POST",
//                url:"views/ajax/showChildren.php?page_id=" + page_id,
//                success: function(html){
//                        $("#child_list_"+page_id).html(html+"<div style='clear:both' />");
//                        document.getElementById("icon_arrow_"+page_id).src = "images/down_arrow.png";
//                        document.getElementById("arrow_shape_"+page_id).value="1";
//                        document.getElementById("child_list_"+page_id).style.display="inline";
//                }
//        });
//    }
//    else
//    {
//        document.getElementById("icon_arrow_"+page_id).src = "images/right_arrow.png";
//        document.getElementById("arrow_shape_"+page_id).value="0";
//        document.getElementById("child_list_"+page_id).style.display="none";
//
//    }
//}

function ShowChild(page_id,parent)
{  
    //alert("Page ID " + page_id + " \nVALUE = " + document.getElementById("arrow_shape_"+page_id).value)
    if(document.getElementById("arrow_shape_"+page_id).value=="0")
    {
        jQuery.facebox("<img src='../scripts/facebox/loading.gif'/>Loading....");
        
        $.ajax({            
                type: "GET",
                url:"views/ajax/showChildren.php?page_id=" + page_id,
                success: function(html)
                {
                        document.getElementById("icon_arrow_"+page_id).src = "images/down_arrow.png";
                        $('#'+page_id+'').after(html);                          
                        document.getElementById("arrow_shape_"+page_id).value="1";
                        
                        jQuery.facebox.close();
                }
        });
    }
    else
    {   
        //alert(page_id);
        document.getElementById("icon_arrow_"+page_id).src = "images/right_arrow.png";
        jQuery.facebox("<img src='../scripts/facebox/loading.gif'/>Loading....");
        $.ajax({
                type: "POST",
                url:"views/ajax/showChildren.php?action=get_children&id=" + page_id,
                success: function(html)
                {
                    
                    var op = html.split(",");
                    //alert(op.toString());
                    for(var i=0;i<op.length;i++)
                    {
                        //alert(op[i]);
                        if(document.getElementById(op[i]) != null)
                            $('#'+op[i]).empty().remove()
                    }
                    //alert(op.length);
                    //if(op.length==1)
//                    {
//                        op.length = 0;
//                    }
                    
                    jQuery.facebox.close();
                }
       });
       
       //if(op.length==1)
//       {
//            op.length = 0;
//       }

        //$('#'+page_id+'_').remove();        
        document.getElementById("arrow_shape_"+page_id).value="0";
        //document.getElementById("child_list_"+page_id).style.display="none";

    }
    
    return;
}
 
//------------ Show Child 2 ------------------------------ 
function ShowChild2(page_id,parent)
{   
    $.ajax({
            type: "POST",
            url:"views/ajax/showChildren.php?page_id=" + page_id,
            success: function(html)
            {
                    document.getElementById("icon_arrow_"+page_id).src = "images/down_arrow.png";
                    $('#'+page_id+'').after(html);                          
                    document.getElementById("arrow_shape_"+page_id).value="1";
            }
    });
    
}

function deletePage(page_id,message)
{
    if(confirm(message))
    {
        window.location = "index.php?fa=page_management&action=deletepage&id="+page_id;
    }
}

 function createPage(page_id)
 {
    window.location = "index.php?fa=page_management&action=new&parent="+page_id;
 }

 function showContent()
 {
     if(!document.getElementById("redirect").checked)
         document.getElementById("text_editor").style.display='table-row';
     else
         document.getElementById("text_editor").style.display='none';
 }

 function deleteFile(page_id,path,msg1,msg2,msg3,msg4)
 {
     if(confirm(msg1 + path + msg2))
     {
         $.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(msg3);
                    else
                        jQuery.facebox(msg4);

                    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)
{
    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=page_management&action=change_status&fb=1",
            data:"page_id=" + page_id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

function changeInDDL(page_id,status)
{
    var message="";
    if(status==0)
        message = "Remove from Front Page Dropdownlist?";
    else
        message = "Add Page to Front Page Dropdownlist?";

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

function clonePage(page_id)
{
    if(confirm("Clone this Page?"))
        window.location="index.php?fa=page_management&action=clone&id="+page_id+"";
}

//--------------- 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("Are you sure you want to delete this page? (This Action cannot be Undone)"))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=products_management&action=delete&fb=1",
                data:"product_id=" + product_id,
                success: function(html){
                    alert("Product Deleted!");
                    window.location="index.php?fa=products_management";


                }
        });
        
    }
}

function changeProductStatus(product_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=products_management&action=change_status&fb=1",
            data:"product_id=" + product_id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

//---------------- Box Management Functions ----------------------------------------------------
function deleteBox(box_id,path)
{
 if(confirm("Are you sure you want to delete this Advertising Box ?(This Operation will delete the entry and the physical files)"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=box_management&action=delete&fb=1",
            data:"box_id=" + box_id + "&path=" + path,
            success: function(html){
                alert("Advertising Box Deleted!");
                window.location.reload();
            }
    });
 }
}

function changeStatus(box_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=box_management&action=change_status&fb=1",
            data:"box_id=" + box_id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                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 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 changePassword(id)
{
    if(confirm("Reset Password of this User?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=visitors_management&action=change_password&fb=1",
            data:"id=" + id ,
            success: function(html){
                jQuery.facebox(html);
            }
        });
    }

}

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

}

function validatePref()
{
    if(document.getElementById("enablepasswd").checked)
    {
        if(document.getElementById("password").value=="")
        {
            alert("Password Cannot be empty!");
            document.getElementById("password").focus();
        }
        else
            document.frmPref.submit();
    }
    else
        document.frmPref.submit();

}

/*function changePage(path)
{
    index_val = document.getElementById("page").selectedIndex
    page_id = document.getElementById("page").options[index_val].id
    window.location = path+"/"+page_id+".htm";
}*/
 function changePage(path)
{
    index_val = document.getElementById("page").selectedIndex
    page_id = document.getElementById("page").options[index_val].id
    window.location = path+"/"+page_id+".htm";
}


function changeLang(lang)
{
    if(confirm("Change Lang?"))
    {
    $.ajax({
            type: "GET",
            url:"/ometall/lang/"+lang+".htm&fb=1",
            
            success: function(html){
                jQuery.facebox("adsdasf");
            }
        });
    }
}
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 subForm2(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 subFormLight(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 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("This Reference key already exists!");
                    document.getElementById("ref_"+prod_id).value="";
               }
               else
               {
                  alert("Reference Key Updated!"); 
               }
            }
    });
    }
}

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 deleteNewsBanner(news_id,message_confirm,message_ok)
{
    if(confirm(message_confirm))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=news_management&action=delete_banner",
            data:"news_id=" + news_id,
            success: function(html){
                if(html.search('DONE')!=-1)
                    {
                        alert(message_ok);
                        window.location.reload();
                    }
            }
        });
    }
}

function deleteCategoryBanner(product_id,image_id)
{
    if(confirm("Are you sure you want to delete this Banner?"))
    {
        $.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 changeWorkshopStatus(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=workshop_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

function deleteWorkshop(id,msg_confirm,msg_ok)
{
 if(confirm(msg_confirm))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=workshop_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert(msg_ok);
                window.location.reload();
            }
    });
 }
}

function changeArtistsStatus(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=artists_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                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 changeCategoryStatus(cat_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=artwork_category_management&action=change_status&fb=1",
            data:"id=" + cat_id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

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

function deleteAlbum(id)
{
    if(confirm("Confirmez-vous la suppression de cet album ?"))
    {
        $.ajax({
            type: "POST",
            url:"index.php?fa=gallery_management&action=delete_album&fb=1",
            data:"id=" + id ,
            success: function(html){
                alert("Album Deleted!");
                window.location.reload();
            }
    });
    }
}

function deleteLogo(logo_id)
{
    if(confirm("Confirmez-vous la suppression de ce logo ? "))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=logo_management&action=delete&fb=1",
                data:"logo_id=" + logo_id,
                success: function(html){
                    alert("Logo supprimé!");
                    window.location="index.php?fa=logo_management";


                }
        });
        
    }
}

function deleteBoxImage(img_path,id)
{
    if(confirm("Are you sure you want to delete this Image?"))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=box_management&action=delete_image&fb=1",
                data:"id=" + id,
                success: function(html){
                    alert("Image deleted");
                    window.location="index.php?fa=box_management";


                }
        });
        
    }
}

function changeLayout(page_id,layout_id,message)
{
	$.ajax({
		type: "POST",
		url:"index.php?fa=page_management&action=changeLayout&fb=1",
		data:"page_id=" + page_id + "&layout_id=" + layout_id ,
		success: function(html){
			alert(message);
			window.location.reload();
		}
   	});
}

function deleteLink(id,msg1,msg2)
{
 if(confirm(msg1))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=links_management&action=delete",
            data:"id=" + id,
            success: function(html){
                alert(msg2);
                window.location.reload();
            }
    });
 }
}

function changeLinkStatus(link_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=links_management&action=change_status",
            data:"link_id=" + link_id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

function changeArtworkStatus(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=artwork_management&action=change_status",
            data:"id=" + id + "&status=" + status ,
            success: function(html){
                alert("Status Changed!");
                window.location.reload();
            }
    });
    }
}

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

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


function setType(id)
{
    var op = "";
    
    $.ajax({
            type: "POST",
            url:"views/ajax/generateHTML.php?action=new",
            success: function(html){
                op += "<fieldset>"+
                "<center>"+
                "<table width='80' class='xls2'>"+
                "<tr height='50'><td width='50px'>Type&nbsp;&nbsp;</td><td><select id='type'>"+
                    "<option value='1'>Type1</option>"+
                    "<option value='2'>Type2</option>"+
                "</select></td>"+
                "</tr>"+
                html+
                "<tr><td><input type='button' onclick='saveType("+id+")' value='OK'</td></tr>"+
                "</table>";
                
                if(document.getElementById(id).checked==true)
                {
                    jQuery.facebox(op);
                }
            }
    });
    
}

function saveType(id)
{
    document.getElementById("lbl_"+id).innerHTML = "Type("+document.getElementById("type").value+")";
    document.getElementById("type_"+id).value = document.getElementById("type").value;
    
    var lang_array = document.getElementById("var_list").value.split(",");
    lang_array.pop();
    var langs = "";
    
    for(var i=0;i<lang_array.length;i++)
    {
       langs += lang_array[i]+"="+document.getElementById("label_"+lang_array[i]).value+"/";
    }
    
    document.getElementById("labels_"+id).value = langs;
    document.getElementById(id).checked=true;
    jQuery.facebox.close();    
}

function saveLinks()
{
    var total = document.getElementById("total_count").value
    var val_array = new Array();
    
    for(var i=0;i<total;i++)
    {
       if(document.getElementById(i).checked==true) 
       {
            val_array.push(document.getElementById("id_"+i).value+"-"+document.getElementById("type_"+i).value + "-" + document.getElementById("labels_"+i).value)
       }
    }
    
    document.getElementById("final_array").value = val_array.toString();
    
    var total_ex = parseInt(document.getElementById("total_count_ex").value)
    var del_array = new Array();
    
    var j=parseInt(total);
    
    while(j<total_ex)
    {
        if(document.getElementById(j).checked==false)
            del_array.push(document.getElementById("id_"+j).value);
            
           j++; 
    }
    
    document.getElementById("del_array").value = del_array.toString();
    document.form1.submit();
   
}

function saveExtLinks()
{
    var total = document.getElementById("total_count_ex2").value
    var val_array = new Array();
    
    for(var i=0;i<total;i++)
    {        
        val_array.push(document.getElementById("lang_key_"+i).value+"-"+document.getElementById("lang_val_"+i).value)
    }
    
    document.getElementById("final_array_ex").value = val_array.toString();
    document.frmStatus.submit();
   
}

function setType2(fk_id)
{
    var html = "<fieldset>"+
                "<center>"+
                "<table width='80' class='xls2'>"+
                "<tr height='50'><td width='50px'>Type&nbsp;&nbsp;</td><td><select id='type'>"+
                    "<option value='1'>Type1</option>"+
                    "<option value='2'>Type2</option>"+
                "</select></td>"+
                "</tr>"+
                "<tr><td><input type='button' onclick='saveType2("+fk_id+")' value='OK'</td></tr>"+
                "</table>";
                
    //if(document.getElementById(id).checked==true)
    {
        jQuery.facebox(html);
    }
}

function saveType2(id)
{
    $.ajax({
            type: "POST",
            url:"index.php?fa=page_management&action=save_type",
            data:"id=" + id + "&type="+document.getElementById("type").value,
            success: function(html){
                jQuery.facebox('Saved!');
                
            }
    });
}


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 subFormBanner(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 deleteBanner(banner_id,path)
{
 if(confirm("Are you sure you want to delete this Sponser Banner ?(This Operation will delete the entry and the physical files)"))
 {
     $.ajax({
            type: "POST",
            url:"index.php?fa=sponser_banner_management&action=delete&fb=1",
            data:"banner_id=" + banner_id + "&path=" + path,
            success: function(html){
                alert("Sponser Banner Deleted!");
                window.location.reload();
            }
    });
 }
}

function changeSHLabels(id)
{
    jQuery.facebox("Loading...");
    $.ajax({
            type: "POST",
            url:"views/ajax/generateHTML.php?action=edit",
            data:"id=" + id,
            success: function(html){
                jQuery.facebox(html);
            }
    });
}

function saveEditedLabels(id)
{
    var lang_list = document.getElementById("var_list").value.split(",");
    lang_list.pop();
    var type = document.getElementById("type").options[document.getElementById("type").selectedIndex].value;
    
    var params = "";
    
    for(var i=0;i<lang_list.length;i++)
    {
        params +=  "label"+lang_list[i] + "=" + document.getElementById("label_"+lang_list[i]).value+"##"+"url"+lang_list[i] + "=" + document.getElementById("url_"+lang_list[i]).value+"##";
    }
    
    jQuery.facebox("Loading...");
    $.ajax({
            type: "POST",
            url:"index.php?fa=page_management&action=save_edited_shortcut",
            data:"id=" + id + "&type=" + type+"&params="+params,
            success: function(html){                
                window.location.reload();
            }
    });
}

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

    if(unicode == 13)
    {
        if(isNaN(val.replace(",","")))
        {
            alert("S'il vous plaît entrer un numéro");
            document.getElementById("prod_kw_old_"+prod_id).value=old_val;
        }
        else
        {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=vehicle_management&action=change_kw_old",
                    data:"id=" + prod_id + "&value=" + val,
                    success: function(html){
                        alert("Poids mis à jour!");
                        //window.location.reload();
                    }
            });
        }
    }
}

function changeKWNew(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        if(isNaN(val.replace(",","")))
        {
            alert("S'il vous plaît entrer un numéro");
            document.getElementById("prod_kw_new_"+prod_id).value=old_val;
        }
        else
        {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=vehicle_management&action=change_kw_new",
                    data:"id=" + prod_id + "&value=" + val,
                    success: function(html){
                        alert("Poids mis à jour!");
                        //window.location.reload();
                    }
            });
        }
    }
}


function changeHPOld(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        if(isNaN(val.replace(",","")))
        {
            alert("S'il vous plaît entrer un numéro");
            document.getElementById("prod_hp_old_"+prod_id).value=old_val;
        }
        else
        {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=vehicle_management&action=change_hp_old",
                    data:"id=" + prod_id + "&value=" + val,
                    success: function(html){
                        alert("Poids mis à jour!");
                        //window.location.reload();
                    }
            });
        }
    }
}

function changeHPNew(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        if(isNaN(val.replace(",","")))
        {
            alert("S'il vous plaît entrer un numéro");
            document.getElementById("prod_hp_new_"+prod_id).value=old_val;
        }
        else
        {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=vehicle_management&action=change_hp_new",
                    data:"id=" + prod_id + "&value=" + val,
                    success: function(html){
                        alert("Poids mis à jour!");
                        //window.location.reload();
                    }
            });
        }
    }
}

function changeNMOld(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        if(isNaN(val.replace(",","")))
        {
            alert("S'il vous plaît entrer un numéro");
            document.getElementById("prod_nm_old_"+prod_id).value=old_val;
        }
        else
        {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=vehicle_management&action=change_nm_old",
                    data:"id=" + prod_id + "&value=" + val,
                    success: function(html){
                        alert("Poids mis à jour!");
                        //window.location.reload();
                    }
            });
        }
    }
}

function changeNMNew(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
        if(isNaN(val.replace(",","")))
        {
            alert("S'il vous plaît entrer un numéro");
            document.getElementById("prod_nm_new_"+prod_id).value=old_val;
        }
        else
        {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=vehicle_management&action=change_nm_new",
                    data:"id=" + prod_id + "&value=" + val,
                    success: function(html){
                        alert("Poids mis à jour!");
                        //window.location.reload();
                    }
            });
        }
    }
}

function changeRef(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

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

function changePrixCat(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

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

function changeCatShopPrice(cat, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=prix_cat_management&action=changeCatShopPrice",
                    data:"id=" + cat + "&value=" + val,
                    success: function(html){
                        alert("Prix modifié");
                        window.location.reload();
                    }
            });
    }
}
function changeCatShopIncreasedPrice(cat, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {	
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=prix_cat_management&action=changeCatShopIncreasedPrice",
                    data:"id=" + cat + "&value=" + val,
                    success: function(html){
                        alert("Prix modifié");
                        window.location.reload();
                    }
            });
    }
}

function Paginator_Vehicles(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_vehicles.php?action=show_page&page="+page,
                data:"search_text="+search_string,
                success: function(html)
                {
                    document.getElementById("vehicle_list").innerHTML=html;
                    document.getElementById("search_text").value=search_string;
                    document.getElementById("search_text_top").value=search_string;
                    jQuery.facebox.close();
                }
        });
}

function lookup_vehicles_top(inputString) 
{
    if(inputString.length == 0)
    {
    	// Hide the suggestion box.
    	$('#suggestions').hide();
    }
    else
    {
    	$.post("views/ajax/ajax_vehicles.php?action=search_tooltip&section=top", {queryString: ""+inputString+""}, function(data)
        {
    		if(data.length >0) {
    			$('#suggestions').show();
    			$('#autoSuggestionsList').html(data);
    		}
    	});
    }
}

function fill_vehicles_top(thisValue) 
{
	$('#search_text_top').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}

function lookup_vehicles(inputString) 
{
    if(inputString.length == 0)
    {
    	// Hide the suggestion box.
    	$('#suggestions_bottom').hide();
    }
    else
    {
    	$.post("views/ajax/ajax_vehicles.php?action=search_tooltip&section=bottom", {queryString: ""+inputString+""}, function(data)
        {
    		if(data.length >0) {
    			$('#suggestions_bottom').show();
    			$('#autoSuggestionsList_bottom').html(data);
    		}
    	});
    }
}

function fill_vehicles(thisValue) 
{
	$('#search_text').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}

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

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

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

function deleteVehicle(product_id,msg_confirm,msg_ok)
{
    if(confirm(msg_confirm))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=vehicle_management&action=delete&fb=1",
                data:"id=" + product_id,
                success: function(html){
                    alert(msg_ok);
                    window.location="index.php?fa=vehicle_management";


                }
        });
        
    }
}

function deleteType(id)
{
    if(confirm("Supprimer ce type de véhicule?"))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=vehicle_types_management&action=delete",
                data:"id=" + id,
                success: function(html){
                    alert("Véhicule supprimés!");
                    window.location.reload();
                }
        });
        
    }
}

function deleteVehicleImage(id)
{    
    if(confirm("Supprimer cette image?"))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=vehicle_management&action=delete_image",
                data:"id=" + id,
                success: function(html){
                    alert("Image supprimés!");
                    window.location.reload();
                }
        });
        
    }

}

function deleteVehiclePDF(id)
{    
    if(confirm("Supprimer cette PDF?"))
    {
         $.ajax({
                type: "POST",
                url:"index.php?fa=vehicle_management&action=delete_pdf",
                data:"id=" + id,
                success: function(html){
                    alert("Image supprimés!");
                    window.location.reload();
                }
        });
        
    }

}

function orderVehicles(option,order)
{
    
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"views/ajax/ajax_vehicles.php?action=order_vechicles&order="+order+"&option="+option,
                
                success: function(html)
                {
                    document.getElementById("vehicle_list").innerHTML=html;                    
                    jQuery.facebox.close();
                }
        });
}

function changeSystem(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

    if(unicode == 13)
    {
            $.ajax({
                    type: "POST",
                    url:"index.php?fa=vehicle_management&action=change_system",
                    data:"id=" + prod_id + "&value=" + val,
                    success: function(html){
                        alert("Valeur du System changé!");
                        //window.location.reload();
                    }
            });
    }
}

function changePrice(prod_id, val,e,old_val)
{

    var unicode=e.keyCode? e.keyCode : e.charCode

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

//var checked_items_list = new Array();


function addtoCheckList(id)
{
    //if(document.getElementById("chk_"+id).checked==false)
        //deleteCheckItem(id)
    //else
    {  
        jQuery.facebox("Loading......");
        var op  = "<table id='item_"+id+"'><tr><td>";
        
        op+= "<table><tr><td><input type='checkbox' checked='true' onclick='deleteCheckItem("+id+")'></td><td>Type: "+document.getElementById("type_"+id).innerHTML+"</td></tr>"+
        "<tr><td></td><td>Brand: "+document.getElementById("brand_"+id).innerHTML+"</td></tr>"+
        "<tr><td></td><td>Model: "+document.getElementById("model_"+id).innerHTML+"</td></tr>"+
        "<tr><td></td><td>Power: "+document.getElementById("hp_"+id).innerHTML+"</td></tr>"+
        "<tr><td></td><td>Quantity: <input type='text' style='width:30px' id='qty_"+id+"'></td></tr></table></td>"+
        "<td><table>"+
        "<tr><td>Année: <input type='text' id='year_"+id+"'></td><td>Air Filter: Yes<input type='radio' id='af_yes_"+id+"' name='g"+id+"' />No<input type='radio' id='af_no_"+id+"' name='g"+id+"' /></td></tr>"+
        "<tr><td colspan='2'>Comments: </td></tr>"+
        "<tr><td colspan='2'><textarea rows='5' cols='25' id='comment_"+id+"'></textarea></td></tr></table>"+
        "</td></tr><br><br>";
        
        document.getElementById("check_list").innerHTML += op;
        
        document.getElementById("btnCheckout").style.display='block';
        checked_items_list.push(id);
        
        //--- Add HTML and items to session
        
        
        $.ajax({
        
            type: "POST",
            url:"/index.php?action=add_to_session",
            data:"brand=" + document.getElementById("brand_"+id).innerHTML + "&model="+document.getElementById("model_"+id).innerHTML+"&power="+document.getElementById("hp_"+id).innerHTML+"&type="+document.getElementById("type_"+id).innerHTML+"&id="+id,
            success: function(html){
                jQuery.facebox.close();
            }
        });
    }
}

function deleteCheckItem(item_id)
{
    jQuery.facebox("Loading......");
    var parent = document.getElementsByTagName('body')[0];
    var elem = document.getElementById("item_"+item_id);
	
    if(elem!=null)
        var old = (elem.parentNode).removeChild(elem);
     
    var idx = checked_items_list.indexOf(item_id); 
    
    if(idx!=-1) 
        checked_items_list.splice(idx, 1);  
        
   if(checked_items_list.length==0) 
    document.getElementById("btnCheckout").style.display='none';
    
   if(document.getElementById("chk_"+item_id)!=null)       
      document.getElementById("chk_"+item_id).checked=false;   
      
  $.ajax({
    
        type: "POST",
        url:"/index.php?action=delete_from_cart",
        data:"item_id=" + item_id ,
        success: function(html){
            jQuery.facebox.close();
        }
    });  
}

function checkOut()
{
    var checked_item_details = "";
    
    for(var i=0;i<checked_items_list.length;i++)
    {        
        checked_item_details+=checked_items_list[i]+",";
        checked_item_details+=document.getElementById("qty_"+checked_items_list[i]).value+",";
        checked_item_details+=document.getElementById("year_"+checked_items_list[i]).value+",";
        checked_item_details+=document.getElementById("comment_"+checked_items_list[i]).value+",";
        
        if(document.getElementById("af_yes_"+checked_items_list[i]).checked==true)
            checked_item_details+=1+"__";
        else
            checked_item_details+=0+"__";
     
    }
    
    jQuery.facebox("Loading......");
    $.ajax({
        
            type: "POST",
            url:"/index.php?action=save_order",
            data:"order_details=" + checked_item_details,
            success: function(html){
                jQuery.facebox(html);
            }
    });
}

function updateVisitor()
{
    var fname = document.getElementById("fname").value;
    var lname = document.getElementById("lname").value;
    var address = document.getElementById("address").value;
    var cp = document.getElementById("cp").value;
    var city = document.getElementById("city").value;
    var tel = document.getElementById("tel").value;
    var fax = document.getElementById("fax").value;
    var gsm = document.getElementById("gsm").value;
    var vat = document.getElementById("vat").value;
    var email = document.getElementById("email").value;
    
    jQuery.facebox("Loading......");
    $.ajax({        
            type:"POST",
            url:"/index.php?action=update_visitor",
            data:"fname="+fname+
            "&lname="+lname+
            "&address="+address+
            "&cp="+cp+
            "&city="+city+
            "&tel="+tel+
            "&fax="+fax+
            "&gsm="+gsm+
            "&email="+email+
            "&vat="+vat,
            success: function(html){
                alert("Votre commande est enregistrée et sera traitée dans les meilleurs délais");
                window.location.reload();
            }
    });
}

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

function orderVehiclesPublic(option,order)
{    
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"/admin/views/ajax/ajax_vehicles_public.php?action=order_vechicles&order="+order+"&option="+option,
                
                success: function(html)
                {
                    document.getElementById("vlist_public").innerHTML=html;                    
                    jQuery.facebox.close();
                }
        });
}

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

           
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"/admin/views/ajax/ajax_vehicles_public.php?action=search",
                data:"key="+old_key,
                success: function(html)
                {
                    document.getElementById("vlist_public").innerHTML=html;                    
                    document.getElementById("search_text_top").value=old_key;
                    jQuery.facebox.close();
                }
        });
}
function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]){
			return document.embeds[movieName];
		}
		else{
			return document.getElementById(movieName);
		}
	}
}
function sendTextToFlash(str){
	var flashMovie=getFlashMovieObject("vdo13");
	flashMovie.sendTextToFlash(str);
}
function deletePromocode(id)
{
    if(confirm('Confirmez-vous la suppression de ce code promotionnel ?'))
    {
         $.ajax({
            type: "POST",
            url:"index.php?fa=promocode_management&action=delete&fb=1",
            data:"id=" + id ,
            success: function(html){
                alert("Promocode supprimés!");
                window.location.reload();
            }
    });
    }
}




function searchVisitors()
{
    var old_key = "";
    
   old_key = document.getElementById("search_text").value;

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

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


function orderVisitors(option,order)
{
    var old_key = document.getElementById("search_text").value;
    
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"views/ajax/ajax_visitors.php?order_visitors="+order+"&option="+option,
                data:"key="+document.getElementById("search_text").value,
                success: function(html)
                {
                    document.getElementById("visitor_list").innerHTML=html;
                    document.getElementById("search_text").value=old_key;
                    jQuery.facebox.close();
                }
        });
}

function Paginator(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_visitors.php?action=show_page&page="+page,
                data:"search_text="+search_string,
                success: function(html)
                {
                    document.getElementById("visitor_list").innerHTML=html;
                    document.getElementById("search_text").value=search_string
                    document.getElementById("search_text_top").value=search_string
                    jQuery.facebox.close();
                }
        });
}

function editUser()
{
    if(document.getElementById("visitor").selectedIndex!=0)
    {
      $.ajax({
            type: "POST",			
            url:"views/ajax/ajax_visitors.php?action=edit_for_orders",
            data:"id=" + document.getElementById("visitor").options[document.getElementById("visitor").selectedIndex].value ,
            success: function(html){
                jQuery.facebox(html);
            }
    });  
    }
    else
    {
        alert("Veuillez sélectionner un client");
        document.getElementById("visitor").focus();
    }
    
}

function saveEditedVisitor_Orders()
{
    var news_flag = 0;

    if(document.getElementById("news_flag").checked)
        news_flag=1;
            
    $.ajax({        
            
            type: "POST",
            url:"views/ajax/ajax_visitors.php?action=update_visitor_orders",
            data:"id=" + document.getElementById("visitor").options[document.getElementById("visitor").selectedIndex].value+
            "&first_name=" + document.getElementById("billing_first").value+
            "&last_name=" + document.getElementById("billing_last").value+
            "&address=" + document.getElementById("address").value+
            "&cp=" + document.getElementById("billing_cp").value+
            "&email=" + document.getElementById("email").value+
            "&city= " + document.getElementById("billing_city").value+
            "&pays=" + document.getElementById("billing_country").value+
            "&phone=" + document.getElementById("tel").value+
            "&fax=" + document.getElementById("fax").value+
            "&gsm=" + document.getElementById("gsm").value+
            "&company=" +document.getElementById("billing_company").value+
            "&vat=" + document.getElementById("billing_vat").value+
            "&subs_date=" + document.getElementById("sub_date").value+
            "&note=" + document.getElementById("note").value+
            "&news_letter=" + news_flag,
            success: function(html){
                jQuery.facebox("Mise à jour effectuée");
            }
    });  
}

function showAllVisitors()
{
    jQuery.facebox("Loading...");
     $.ajax({
                type: "POST",
                url:"views/ajax/ajax_visitors.php?action=showAll",
                success: function(html)
                {
                    document.getElementById("visitor_list").innerHTML=html; 
                    jQuery.facebox.close();
                }
        });
}

function changeUserStatus(user_id,status)
{
    var message="";
    if(status==0)
        message = "Autoriser l'accès à cet utilisateur ?";
    else
        message = "Interdire l'accès à cet utilisateur ?";

    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 changeNewsletterFlag(user_id,status)
{
    var message="";
    if(status==0)
        message = "Inclure dans la newsletter ?";
    else
        message = "Exclure de la newsletter ?";

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

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

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();
}

