
// MENU
function admin_add_mainitem(){ //nodig??????????
$("#admin_popin").show();
}

function update_menuorder(amount){
var fieldname_value =  new Array();
var fieldname =  new Array();
	for(var i = 1; i <= amount; i++){
		index= i - 1;
		orderfield= "order_"+i;
		namefield = "field_"+i
		fieldname_value[index] = document.getElementById(orderfield).value;
		fieldname[index] = document.getElementById(namefield).value;
		//alert("Field:"+fieldname[index] +"changed to order"+fieldname_value[index]);
		//debug
		
	}

$.post("admin/todb.php?action=changeorder_menuitem",{'name[]':fieldname,'value[]':fieldname_value}, function(data){
reloadadminwindow("menu");
});
}


function show_add_menu(){
$("#admin_editmenuform").hide();
$("#admin_addmenuform").show();
}

function show_edit_menu(menuid){

	//loadmenu into form
	$("#admin_editmenuform").load("admin/edit_menu.php", { 'menuid': menuid } );
	$("#admin_addmenuform").hide();
	$("#admin_editmenuform").show();
}

function delete_menu(menuid_value){
$.post("admin/todb.php?action=delete_menuitem",{menuid:menuid_value}, function(data){
reloadadminwindow("menu");
//debug
});

}

function edit_menu(menuid){
fieldname_value = document.getElementById("edit_fieldname").value;
NLfield_value = document.getElementById("edit_NLfield").value;
ENfield_value = document.getElementById("edit_ENfield").value;
FRfield_value = document.getElementById("edit_FRfield").value;
DEfield_value = document.getElementById("edit_DEfield").value;
actiontype_value = document.getElementById("edit_actiontype").value;
action_text = document.getElementById("edit_pageactionfield").value;

$.post("admin/todb.php?action=edit_menuitem",{fieldname: fieldname_value, NLfield: NLfield_value, ENfield: ENfield_value, FRfield: FRfield_value, DEfield: DEfield_value, actiontype: actiontype_value, menuid: menuid,action:action_text}, function(data){																																																							
$("#admin_editmenuform").hide();
reloadadminwindow("menu");
//debug
});
}


function add_menu(){
fieldname_value = document.getElementById("fieldname").value;
NLfield_value = document.getElementById("NLfield").value;
ENfield_value = document.getElementById("ENfield").value;
FRfield_value = document.getElementById("FRfield").value;
DEfield_value = document.getElementById("DEfield").value;
actiontype_value = document.getElementById("actiontype").value;
action_value = document.getElementById("pageactionfield").value; 
$.post("admin/todb.php?action=add_menuitem",{fieldname: fieldname_value, NLfield: NLfield_value, ENfield: ENfield_value, FRfield: FRfield_value, DEfield: DEfield_value, actiontype: actiontype_value,action:action_value}, function(data){
																																																				$("#admin_addmenuform").hide();
reloadadminwindow("menu");																																																				 //debug
});
}
//STYLE
function admin_updatestyle(){
	style_value = document.getElementById("admin_style_field").value;
	$.post("admin/todb.php?action=change_style",{style: style_value}, function(data){
location.reload(true);
//debug
});	
	
}

//manage products

function admin_addproduct(){
$("#admin_addproductform").load("admin/addproduct_form.php");
$("#admin_addproductform").show();
}

//manage pages

function menu_formcancel_manage(){
$("#admin_managepagesdiv").show();
$("#admin_editpageform").hide();
$("#admin_addpageform").hide();
}

function product_formcancel(){
$("#admin_addproductform").hide();
}


function show_add_page(){
$("#admin_addpageform").load("admin/createpage.php");
$("#admin_managepagesdiv").hide();
$("#admin_viewpageform").hide();
$("#admin_addpageform").show();
}


function managepage_view(page_id){
var windowHeight = document.documentElement.clientHeight;
windowMin = windowHeight * 0.26;
windowHeight = windowHeight - windowMin;

$("#admin_viewpageform").load("admin/view_page.php", { 'page_id': page_id } );
$("#admin_viewpageform").show();
$("#admin_viewpageform").css({
			"height": windowHeight,
			"overflow-y":"scroll"
		});
}

function managepage_edit(page_id){
$("#admin_managepagesdiv").hide();
$("#admin_viewpageform").hide();
$("#admin_editpageform").load("admin/edit_page.php", { 'page_id': page_id } );
$("#admin_editpageform").show();
}

function managepage_delete(page_id){
$("#admin_viewpageform").hide();
$.post("admin/todb.php?action=delete_page",{page_id: page_id}, function(data){
reloadadminwindow("page");
});	
}


function add_page(){
var oEditorDE = FCKeditorAPI.GetInstance('DEpage');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('NLpage');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('ENpage');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('FRpage');
FRcontent = oEditorFR.GetHTML(true);

pagename = document.getElementById("managepage_name").value;

$.post("admin/todb.php?action=create_page",{DEpage: DEcontent,NLpage: NLcontent,ENpage: ENcontent,FRpage: FRcontent,page: pagename}, function(data){																																																							
$("#admin_addpageform").hide();
$("#admin_managepagesdiv").show();
reloadadminwindow("page");
//debug
});

}




function edit_page(pageid){
var oEditorDE = FCKeditorAPI.GetInstance('editDEpage');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('editNLpage');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('editENpage');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('editFRpage');
FRcontent = oEditorFR.GetHTML(true);

$.post("admin/todb.php?action=edit_page",{DEpage: DEcontent,NLpage: NLcontent,ENpage: ENcontent,FRpage: FRcontent,page_id: pageid}, function(data){																																																							
$("#admin_editpageform").hide();
$("#admin_managepagesdiv").show();
//debug
});

}


function copyWYSIWYG(source){
var oEditorDE = FCKeditorAPI.GetInstance('DEpage');
var oEditorNL = FCKeditorAPI.GetInstance('NLpage');
var oEditorEN = FCKeditorAPI.GetInstance('ENpage');
var oEditorFR = FCKeditorAPI.GetInstance('FRpage');

	if(source =="NL"){
		NLcontent = oEditorNL.GetHTML(true);	
		oEditorDE.SetHTML(NLcontent);
		oEditorEN.SetHTML(NLcontent);
		oEditorFR.SetHTML(NLcontent);		
	}
	if(source =="FR"){

		FRcontent = oEditorFR.GetHTML(true);
		oEditorDE.SetHTML(FRcontent);
		oEditorEN.SetHTML(FRcontent);
		oEditorNL.SetHTML(FRcontent);			
	}
	if(source =="EN"){

		ENcontent = oEditorEN.GetHTML(true);
		oEditorDE.SetHTML(ENcontent);
		oEditorFR.SetHTML(ENcontent);
		oEditorNL.SetHTML(ENcontent);		
	}
	if(source =="DE"){

		DEcontent = oEditorDE.GetHTML(true);
		oEditorEN.SetHTML(DEcontent);
		oEditorFR.SetHTML(DEcontent);
		oEditorNL.SetHTML(DEcontent);	
	}
}

//general
function reloadadminwindow(windowname){
	if(windowname == "menu"){
		$("#admin_mainwindow").load("admin/adminmenu_addmenu.php");
	}
	if(windowname == "page"){
		$("#admin_mainwindow").load("admin/adminmenu_managepage.php");
	}	
}

function menu_formcancel(){
$("#admin_addmenuform").hide();
$("#admin_editmenuform").hide();
$("#admin_addpageform").hide();
}


//products

function admin_techtoevoegen(prodid){
$("#tech_admindiv").load("admin/prodadmin_techinfo.php", {prodid: prodid} );
$('#tech_admindiv').show()
}


function addtechinfo(prodid){
var oEditorDE = FCKeditorAPI.GetInstance('techinfoDE');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('techinfoNL');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('techinfoEN');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('techinfoFR');
FRcontent = oEditorFR.GetHTML(true);

imagepath = document.getElementById("upload_path").value;

$.post("admin/todb.php?action=add_techinfo",{DEtechinfo: DEcontent,NLtechinfo: NLcontent,ENtechinfo: ENcontent,FRtechinfo: FRcontent,image: imagepath, prodid: prodid}, function(data){																																																							
$('#tech_admindiv').hide();
$("#technicalinformation").load("source/techinfo.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function delete_techinfo(prodtechid,prodid){
$.post("admin/todb.php?action=delete_techinfo",{prodid: prodtechid}, function(data){																																																							
//reload
$("#technicalinformation").load("source/techinfo.php", { 'db': "true", lang: current_lang,prodid: prodid } );
});
}


function admin_techedit(prodtechid,prodid){
$('#tech_admindiv_edit').show();
$("#tech_admindiv_edit").load("admin/prodadmin_techinfoedit.php", {prodid: prodid, prodtechid:prodtechid } );
}

function edittechinfo(prodtechid,prodid){
var oEditorDE = FCKeditorAPI.GetInstance('techinfoDEedit');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('techinfoNLedit');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('techinfoENedit');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('techinfoFRedit');
FRcontent = oEditorFR.GetHTML(true);

imagepath = document.getElementById("edit_upload_path").value;

$.post("admin/todb.php?action=edit_techinfo",{DEtechinfo: DEcontent,NLtechinfo: NLcontent,ENtechinfo: ENcontent,FRtechinfo: FRcontent,image: imagepath, prodid: prodtechid}, function(data){																																																							
$('#tech_admindiv_edit').hide();
$("#technicalinformation").load("source/techinfo.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

//demensions
function show_dem_add(prodid){
$('#dem_admindiv_add').show();
$("#dem_admindiv_add").load("admin/product_dem_add.php", {prodid: prodid} );
}

function show_dem_edit(demid,prodid){
$('#dem_admindiv_add').show();
$("#dem_admindiv_add").load("admin/product_dem_edit.php", {demid: demid,prodid: prodid} );
}

function dem_add_todb(prodid){
nameNL = document.getElementById("nameNL").value;	
nameEN = document.getElementById("nameEN").value;	
nameDE = document.getElementById("nameDE").value;	
nameFR = document.getElementById("nameFR").value;	
section = document.getElementById("section").value;	
sizemm = document.getElementById("sizemm").value;	

	
$.post("admin/todb.php?action=add_demension",{prodid: prodid, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR, section: section, sizemm:sizemm}, function(data){
	$("#demensioninformation").load("source/demension.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function dem_edit_todb(demid,prodid){
nameNL = document.getElementById("nameNLedit").value;	
nameEN = document.getElementById("nameENedit").value;	
nameDE = document.getElementById("nameDEedit").value;	
nameFR = document.getElementById("nameFRedit").value;	
section = document.getElementById("sectionedit").value;	
sizemm = document.getElementById("sizemmedit").value;	

	
$.post("admin/todb.php?action=edit_demension",{prodid: prodid, demid: demid, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR, section: section, sizemm:sizemm}, function(data){
	$("#demensioninformation").load("source/demension.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function dem_remove_todb(demid,prodid){
	$.post("admin/todb.php?action=delete_demension",{demid: demid}, function(data){																																																							
	//reload
	$("#demensioninformation").load("source/demension.php", { 'db': "true", lang: current_lang,prodid: prodid } );
	});
}

//specs

function show_spec_add(prodid){
$('#spec_admindiv_add').show();
$("#spec_admindiv_add").load("admin/product_spec_add.php", {prodid: prodid} );
}

function show_spec_edit(specid,prodid){
$('#spec_admindiv_edit').show();
$("#spec_admindiv_edit").load("admin/product_spec_edit.php", {prodid: prodid, specid: specid} );
}

function show_spec_add_cat(prodid){
$('#spec_admindiv_addcat').show();
$("#spec_admindiv_addcat").load("admin/product_spec_add_cat.php", {prodid: prodid} );

}

function show_spec_editcat(catid,prodid){
$('#spec_admindiv_editcat').show();
$("#spec_admindiv_editcat").load("admin/product_spec_edit_cat.php", {catid: catid,prodid:prodid} );
}

function spec_add_cat_todb(prodid){
nameNL = document.getElementById("catnameNL").value;	
nameEN = document.getElementById("catnameEN").value;	
nameDE = document.getElementById("catnameDE").value;	
nameFR = document.getElementById("catnameFR").value;		

$.post("admin/todb.php?action=add_spec_cat",{prodid: prodid,nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR}, function(data){
	$("#specwindow").load("source/spec.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function spec_edit_cat_todb(catid,prodid){
nameNL = document.getElementById("editcatnameNL").value;	
nameEN = document.getElementById("editcatnameEN").value;	
nameDE = document.getElementById("editcatnameDE").value;	
nameFR = document.getElementById("editcatnameFR").value;		

$.post("admin/todb.php?action=edit_spec_cat",{prodid: prodid,catid:catid,nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR}, function(data){
	$("#specwindow").load("source/spec.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}


function spec_add_todb(prodid){
nameNL = document.getElementById("nameNL").value;	
nameEN = document.getElementById("nameEN").value;	
nameDE = document.getElementById("nameDE").value;	
nameFR = document.getElementById("nameFR").value;	
fieldvalue = document.getElementById("fieldvalue").value;	
cat = document.getElementById("cat").value;	
	
$.post("admin/todb.php?action=add_spec",{prodid: prodid, catid: cat, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR, field: fieldvalue}, function(data){
	$("#specwindow").load("source/spec.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function spec_edit_todb(specid,prodid){
nameNL = document.getElementById("nameNLedit").value;	
nameEN = document.getElementById("nameENedit").value;	
nameDE = document.getElementById("nameDEedit").value;	
nameFR = document.getElementById("nameFRedit").value;	
fieldvalue = document.getElementById("fieldvalueedit").value;	
cat = document.getElementById("catedit").value;	
	
$.post("admin/todb.php?action=edit_spec",{prodid: prodid, catid: cat, specid:specid, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR, field: fieldvalue}, function(data){
	$("#specwindow").load("source/spec.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function spec_remove_todb(specid,prodid){
	$.post("admin/todb.php?action=delete_spec",{specid: specid}, function(data){																																																							
	//reload
	$("#specwindow").load("source/spec.php", { 'db': "true", lang: current_lang,prodid: prodid } );
	});
}

function spec_removecat_todb(catid,prodid){
	$.post("admin/todb.php?action=delete_speccat",{catid: catid}, function(data){																																																							
	//reload
	$("#specwindow").load("source/spec.php", { 'db': "true", lang: current_lang,prodid: prodid } );
	});	
}

//desc
function intextedit(prodid){
$.post("admin/todb.php?action=get_desc_edit",{prodid: prodid,lang: current_lang}, function(data){																																																							

	//reload
	$("#desc_textfield").html(data);

	});	
}

function reload_intextedit(prodid){
$.post("admin/todb.php?action=get_desc",{prodid: prodid,lang: current_lang}, function(data){																																																							

	//reload
	$("#desc_textfield").html("<a onclick='intextedit("+prodid+");'>"+data+"</a>");

	});	
}

function reload_shorttextedit(prodid){
$.post("admin/todb.php?action=get_shortdesc",{prodid: prodid,lang: current_lang}, function(data){																																																							

	//reload
	$("#smalltext"+prodid).html("<a onclick='smalltext_intextedit("+prodid+");'>"+data+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>");

	});	
}

function save_intextedit(prodid){
var oEditor = FCKeditorAPI.GetInstance('desc_textfield');
content = oEditor.GetHTML(true);

$.post("admin/todb.php?action=save_desc",{prodid: prodid,lang: current_lang, content: content}, function(data){																																																							
	//reload
	$("#desc_textfield").html(data);
	});	
}

//opties
function show_options_edit(opid,prodid){
$('#opties_admindiv_edit').show();
$("#opties_admindiv_edit").load("admin/product_options_edit.php", {opid: opid,prodid:prodid} );
}

function show_options_add(prodid){
$('#opties_admindiv_add').show();
$("#opties_admindiv_add").load("admin/product_options_add.php", {prodid:prodid} );
}

function options_add_todb(prodid){
	nameNL = document.getElementById("optionsnameNL").value;	
	nameEN = document.getElementById("optionsnameEN").value;	
	nameDE = document.getElementById("optionsnameDE").value;	
	nameFR = document.getElementById("optionsnameFR").value;	
	priceeuro = document.getElementById("priceeuro").value;	
	priceeuro_btw = document.getElementById("priceeuro_btw").value;	
	
	
$.post("admin/todb.php?action=add_option",{prodid: prodid, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR, priceeuro: priceeuro,priceeuro_btw:priceeuro_btw}, function(data){
	$("#productopties").load("source/opties.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function options_edit_todb(opid,prodid){
	nameNL = document.getElementById("nameNLedit").value;	
	nameEN = document.getElementById("nameENedit").value;	
	nameDE = document.getElementById("nameDEedit").value;	
	nameFR = document.getElementById("nameFRedit").value;	
	priceeuro = document.getElementById("editpriceeuro").value;	
	priceeuro_btw = document.getElementById("editpriceeuro_btw").value;	
	
$.post("admin/todb.php?action=edit_option",{prodid: prodid,opid:opid, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR, priceeuro: priceeuro,priceeuro_btw:priceeuro_btw}, function(data){
	$("#productopties").load("source/opties.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}

function options_remove_todb(opid,prodid){
	$.post("admin/todb.php?action=delete_options",{opid: opid}, function(data){																																																							
	//reload
	$("#productopties").load("source/opties.php", { 'db': "true", lang: current_lang,prodid: prodid } );
	});
}

//standard options

function show_standard_edit(opid,prodid){
$('#standard_admindiv_edit').show();
$("#standard_admindiv_edit").load("admin/product_standard_edit.php", {opid:opid,prodid:prodid} );
}

function show_standard_add(prodid){
$('#standard_admindiv_add').show();
$("#standard_admindiv_add").load("admin/product_standard_add.php", {prodid:prodid} );
}

function standard_add_todb(prodid){
	nameNL = document.getElementById("standardnameNL").value;	
	nameEN = document.getElementById("standardnameEN").value;	
	nameDE = document.getElementById("standardnameDE").value;	
	nameFR = document.getElementById("standardnameFR").value;	
	
	$.post("admin/todb.php?action=add_standard",{prodid: prodid, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR}, function(data){
	$("#standard_div").load("source/standard_options.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});	
}

function standard_edit_todb(opid,prodid){
	nameNL = document.getElementById("standardNLedit").value;	
	nameEN = document.getElementById("standardENedit").value;	
	nameDE = document.getElementById("standardDEedit").value;	
	nameFR = document.getElementById("standardFRedit").value;	
	
$.post("admin/todb.php?action=edit_standard",{prodid: prodid,opid:opid, nameNL: nameNL, nameEN: nameEN, nameDE: nameDE, nameFR: nameFR}, function(data){
	$("#standard_div").load("source/standard_options.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
});
}


function standard_remove_todb(opid,prodid){
	$.post("admin/todb.php?action=delete_standard",{opid: opid}, function(data){																																																							
	//reload
	$("#standard_div").load("source/standard_options.php", { 'db': "true", prodid:prodid, lang: current_lang  } );
	});
}

//downloads

function show_download_add(prodid){
	$("#download_admindiv_add").load("admin/product_download_add.php", {prodid:prodid} );
	$('#download_admindiv_add').show();
}

function download_remove_todb(downid,prodid){
	$.post("admin/todb.php?action=delete_download",{downid: downid}, function(data){																																																							
	//reload
	$("#downloads").load("source/downloads.php", { 'db': "true", lang: current_lang,prodid: prodid } );
	});
}

function product_setschema(prodid){
	schema = document.getElementById("kfm_schema").value;
	$.post("admin/todb.php?action=set_schema",{prodid: prodid,schema:schema}, function(data){																																																							
	//reload
	picture1= new Image(); 
	picture1.src=schema 
	document.getElementById("schemaimageholder").src = picture1.src;
	//$("#downloads").load("source/downloads.php", { 'db': "true", lang: current_lang,prodid: prodid } );
	});
}

function showlogin(){
$('#logindiv').show();
$("#logindiv").load("login.php", {} );
}

function processlogin(){
sublogin = document.getElementById("sublogin").value;	
user = document.getElementById("user").value;	
pass = document.getElementById("pass").value;

	$.post("process.php",{sublogin: sublogin,user:user,pass:pass}, function(data){																																																							
	//reload
	//$("#logindiv").hide();
	//$("#mainmenudiv").load("source/mainmenu.php", {lang:current_lang} );
	//$("#adminframe").load("admin/admin.php", {session:"yes"} ); //used to reinclude the session in the file which otherwise uses the session from index.
	
	window.location="http://webportal.internbv.nl";
	});

}

function loadloginadmin(){
$("#logindiv").load("loginadmin/admin.php"); 
}

function useredit(){
	$("#logindiv").load("useredit.php"); 
}

//news
function show_addnewsitem(){
	$("#admindiv_addnews").addClass("admin_minipopup");
	$("#admindiv_addnews").show();
	$("#admindiv_addnews").load("admin/addnews.php");
}

function addnewstodb(){
var oEditorDE = FCKeditorAPI.GetInstance('newsDE');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('newsNL');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('newsEN');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('newsFR');
FRcontent = oEditorFR.GetHTML(true);

newsNL = document.getElementById("newstitleNL").value;
newsFR = document.getElementById("newstitleFR").value;
newsDE = document.getElementById("newstitleDE").value;
newsEN = document.getElementById("newstitleEN").value;

$.post("admin/todb.php?action=addnews",{FRcontent:FRcontent,ENcontent:ENcontent,NLcontent:NLcontent,DEcontent:DEcontent,newsNL:newsNL,newsFR:newsFR,newsDE:newsDE,newsEN:newsEN}, function(data){
//action
$("#main_news_preview").load("source/news.php",{session:"yes",lang:current_lang});
});
}

function deletenews_todb(newsid){
	$.post("admin/todb.php?action=delete_news",{newsid: newsid}, function(data){																																																							
	//reload
	$("#main_news_preview").load("source/news.php",{session:"yes",lang:current_lang});
	});
}

function show_editnews(newsid){
	$("#admindiv_addnews").addClass("admin_minipopup");
	$("#admindiv_addnews").show();
	$("#admindiv_addnews").load("admin/edit_news.php",{newsid:newsid});
}

function editnewstodb(newsid){
var oEditorDE = FCKeditorAPI.GetInstance('newsDE');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('newsNL');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('newsEN');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('newsFR');
FRcontent = oEditorFR.GetHTML(true);

newsNL = document.getElementById("editnewstitleNL").value;
newsFR = document.getElementById("editnewstitleFR").value;
newsDE = document.getElementById("editnewstitleDE").value;
newsEN = document.getElementById("editnewstitleEN").value;

$.post("admin/todb.php?action=editnews",{newsid:newsid,FRcontent:FRcontent,ENcontent:ENcontent,NLcontent:NLcontent,DEcontent:DEcontent,newsNL:newsNL,newsFR:newsFR,newsDE:newsDE,newsEN:newsEN}, function(data){
//action
$("#main_news_preview").load("source/news.php",{session:"yes",lang:current_lang});
});
}

//product overview

function smalltext_intextedit(prodid){
$.post("admin/todb.php?action=get_smalltext_edit",{prodid: prodid,lang: current_lang}, function(data){																																																							

	//reload
	$("#smalltext"+prodid).html(data);

	});	
}

function save_shorttextedit(prodid){
	var oEditor = FCKeditorAPI.GetInstance('short_textfield');
	content = oEditor.GetHTML(true);

$.post("admin/todb.php?action=save_shorttext",{prodid: prodid,lang: current_lang, content: content}, function(data){																																																							
	//reload
	$("#smalltext"+prodid).html("<a onclick='smalltext_intextedit("+prodid+")' style='width: 20px;'>"+content+"</a><BR>");
	});	
}

//welcome
function intextedit_welcome(){
	$.post("admin/todb.php?action=get_welcome_edit",{lang: current_lang}, function(data){																																																							

	//reload
	$("#welcometextdiv").html(data);

	});	
}


function reload_welcome(){
$.post("admin/todb.php?action=reloadwelcome",{lang: current_lang}, function(data){																																																							

	//reload
	$("#welcometextdiv").html("<a onclick='intextedit_welcome()'>"+data+"</a>");

	});	
}

function save_welcometext(){
	var oEditor = FCKeditorAPI.GetInstance('welcome_text');
	content = oEditor.GetHTML(true);

	$.post("admin/todb.php?action=save_welcome",{lang: current_lang, content: content}, function(data){																																																							
	//reload
	$("#welcometextdiv").html("<a onclick='intextedit_welcome()'>"+data+"</a>");
	});	
}

//news overview

function overview_show_editnews(newsid){
	$("#admindiv_addnews").addClass("admin_minipopup");
	$("#admindiv_addnews").show();
	$("#admindiv_addnews").load("admin/overview_edit_news.php",{newsid:newsid});
}

function overview_editnewstodb(newsid){
var oEditorDE = FCKeditorAPI.GetInstance('newsDE');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('newsNL');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('newsEN');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('newsFR');
FRcontent = oEditorFR.GetHTML(true);

newsNL = document.getElementById("editnewstitleNL").value;
newsFR = document.getElementById("editnewstitleFR").value;
newsDE = document.getElementById("editnewstitleDE").value;
newsEN = document.getElementById("editnewstitleEN").value;

$.post("admin/todb.php?action=editnews",{newsid:newsid,FRcontent:FRcontent,ENcontent:ENcontent,NLcontent:NLcontent,DEcontent:DEcontent,newsNL:newsNL,newsFR:newsFR,newsDE:newsDE,newsEN:newsEN}, function(data){
//action
$("#maincontent").load("source/newsoverview.php",{session:"yes",lang:current_lang});
});
}

function overview_deletenews_todb(newsid){
	$.post("admin/todb.php?action=delete_news",{newsid: newsid}, function(data){																																																							
	//reload
	$("#maincontent").load("source/newsoverview.php",{session:"yes",lang:current_lang});
	});
}


function show_addnewsitem_overview(){
	$("#admindiv_addnews").addClass("admin_minipopup");
	$("#admindiv_addnews").show();
	$("#admindiv_addnews").load("admin/overview_addnews.php");
}

function overview_addnewstodb(){
var oEditorDE = FCKeditorAPI.GetInstance('newsDE');
DEcontent = oEditorDE.GetHTML(true);

var oEditorNL = FCKeditorAPI.GetInstance('newsNL');
NLcontent = oEditorNL.GetHTML(true);

var oEditorEN = FCKeditorAPI.GetInstance('newsEN');
ENcontent = oEditorEN.GetHTML(true);

var oEditorFR = FCKeditorAPI.GetInstance('newsFR');
FRcontent = oEditorFR.GetHTML(true);

newsNL = document.getElementById("newstitleNL").value;
newsFR = document.getElementById("newstitleFR").value;
newsDE = document.getElementById("newstitleDE").value;
newsEN = document.getElementById("newstitleEN").value;

$.post("admin/todb.php?action=addnews",{FRcontent:FRcontent,ENcontent:ENcontent,NLcontent:NLcontent,DEcontent:DEcontent,newsNL:newsNL,newsFR:newsFR,newsDE:newsDE,newsEN:newsEN}, function(data){
//action
$("#maincontent").load("source/newsoverview.php",{session:"yes",lang:current_lang});
});
}

function show_edit_price(prodid){
$("#admin_product_editprice").show();
$("#admin_product_editprice").load("admin/edit_price.php",{'prodid':prodid});
}

function product_pricetodb(prodid){
eurobtw = document.getElementById("euro_btw_field").value;
euro = document.getElementById("euro_field").value;


$.post("admin/todb.php?action=updateprice",{eurobtw:eurobtw,euro:euro,prodid:prodid}, function(data){
//action
$("#pricediv").load("source/productprice.php",{"products[]":ProductOptions,lang:current_lang,prodid:prodid,action:"acc"});
});
}

function vieworder(orderid){
	$("#admin_mainwindow").load("admin/vieworder.php",{orderid:orderid});
}

function veranderstatus(stat,prodid){
$("#bestellingstatus").html("<select id='statusoptions' name='status'><option value='Open'>Open</option><option value='Wordt Verwerkt'>Wordt Verwerkt</option><option value='Afgesloten'>Afgesloten</option><option value='Afgekeurd'>Afgekeurd</option></select> <a class='admin_link_black' onclick='updatestatus("+prodid+")'>Update</a>");
}

function updatestatus(orderid){
index = document.getElementById("statusoptions").options.selectedIndex;
status = document.getElementById("statusoptions").getElementsByTagName("option")[index].value;
//alert(status);

$.post("admin/todb.php?action=updatestatus",{"status":status,"orderid":orderid}, function(data){
//action
$("#bestellingstatus").html(""+status)
});

}

function send_order_email(orderid){

$.post("admin/mailconfirm.php",{"status":"mail","orderid":orderid}, function(data){
//action
alert("Email Verzonden");
});
}

function imageviewer_manage(prodid){
	$('#imageviewer_admindiv').show();
	$("#imageviewer_admindiv").load("admin/admin_imageviewer.php", {prodid: prodid} );
}

function add_imageviewer_todb(prodid){
	
	imagepath = document.getElementById("imagepath_imageviewer").value;
	$.post("admin/todb.php?action=add_imgpath",{'imagepath':imagepath,'prodid':prodid}, function(data){
		$("#imageviewer_admindiv").load("admin/admin_imageviewer.php", {prodid: prodid} );
	});
}

function imageviewer_remove_todb(imgid,prodid){

	$.post("admin/todb.php?action=delete_imgpath",{'imgid':imgid}, function(data){
		$("#imageviewer_admindiv").load("admin/admin_imageviewer.php", {prodid: prodid} );
	});
}	

function product_cattoevoegen(){
	$('#addprodcat_form').show();
	$("#addprodcat_form").load("admin/addproductcat.php");
}

function add_cat_todb(){

NL = document.getElementById("catname_NL").value;
EN = document.getElementById("catname_EN").value;
FR = document.getElementById("catname_FR").value;
DE = document.getElementById("catname_DE").value;
img1 = document.getElementById("img1").value;
img2 = document.getElementById("img2").value;
img3 = document.getElementById("img3").value;

$.post("admin/todb.php?action=add_prod_cat",{"catlangNL":NL,"catlangEN":EN,"catlangFR":FR,"catlangDE":DE,"img1":img1,"img2":img2,"img3":img3}, function(data){
//reload
			$("#admin_mainwindow").load("admin/add_product.php");
});
}

function edit_cat_todb(catid){
NL = document.getElementById("catname_NL").value;
EN = document.getElementById("catname_EN").value;
FR = document.getElementById("catname_FR").value;
DE = document.getElementById("catname_DE").value;
img1 = document.getElementById("img1").value;
img2 = document.getElementById("img2").value;
img3 = document.getElementById("img3").value;

$.post("admin/todb.php?action=edit_prod_cat",{"catlangNL":NL,"catlangEN":EN,"catlangFR":FR,"catlangDE":DE,"img1":img1,"img2":img2,"img3":img3,catid:catid}, function(data){
//reload
			$("#admin_mainwindow").load("admin/add_product.php");
});
}

function product_formcancel(){
	$('#admin_addproductform').hide();
}

function add_product_todb(){
img = document.getElementById("prodimage").value;
catoptions = document.getElementById("category");
cat = catoptions.options[catoptions.options.selectedIndex].value;
productname = document.getElementById("productname").value;

$.post("admin/todb.php?action=add_product_todb",{"cat":cat,"productname":productname,"img":img}, function(data){
//reload
			$("#admin_mainwindow").load("admin/add_product.php");
});
}

function edit_product_todb(prodid){
img = document.getElementById("prodimage").value;
catoptions = document.getElementById("category");
cat = catoptions.options[catoptions.options.selectedIndex].value;
productname = document.getElementById("productname").value;

$.post("admin/todb.php?action=edit_product_todb",{"cat":cat,"productname":productname,"img":img,"prodid":prodid}, function(data){
//reload		
			$("#admin_mainwindow").load("admin/add_product.php");
});
}

function admin_editproduct(prodid){
$("#admin_addproductform").load("admin/editproduct_form.php", {prodid: prodid} );
}

function admin_delproduct(prodid){
	$.post("admin/todb.php?action=delete_product_todb",{"prodid":prodid}, function(data){
	//reload		
			$("#admin_mainwindow").load("admin/add_product.php");
	});
}

function managecategory(){
	$('#admin_addproductform').show();
	$("#admin_addproductform").load("admin/managecat.php");
}

function admin_editcat(catid){
	$('#addprodcat_form').show();
	$("#addprodcat_form").load("admin/editcat.php",{catid:catid});
}

function admin_deletecat(catid){
$.post("admin/todb.php?action=delete_productcat_todb",{"catid":catid}, function(data){
//reload		
	$("#admin_mainwindow").load("admin/add_product.php");
	$("#admin_addproductform").load("admin/managecat.php");
});
}

function productaddkleur(prodid){
$("#opties_kleur").show();
$("#opties_kleur").load("admin/add_kleur.php",{prodid:prodid,lang:current_lang});
}

function productdeletekleur(prodid){
$("#opties_kleur").show();
$("#opties_kleur").load("admin/delete_kleur.php",{prodid:prodid,lang:current_lang});
}

function cancelkleur(){
$("#opties_kleur").hide();
}

function deletekleur_todb(klid,prodid){
$.post("admin/todb.php?action=delete_kleurfromprod_todb",{"klid":klid}, function(data){
//reload		
	$("#opties_kleur").load("admin/delete_kleur.php",{prodid:prodid,lang:current_lang});
});
}

function addkleurtoproduct(prodid){
kleuroptions = document.getElementById("kleuradd");
klid = kleuroptions.options[kleuroptions.options.selectedIndex].value;

$.post("admin/todb.php?action=add_kleurtoprod_todb",{"klid":klid,"prodid":prodid}, function(data){
//reload		
	$("#opties_kleur").load("admin/add_kleur.php",{prodid:prodid,lang:current_lang});
});
}

