// JavaScript Document
var hinttimeout = 1500;

function highlight(obj) {
	$("#"+obj).effect("highlight", { color: "#FFFFCC" }, 1000);
};

function openpanel(openthis) {
	$("#"+openthis).slideToggle(300);
};

function expandtextarea(textarea) {
	if(navigator.appName.indexOf("Microsoft Internet Explorer") == 0) {
		textarea.rows = 10;
		textarea.style.overflow = 'visible';
		return;
	}
	while(textarea.rows > 1 && textarea.scrollHeight < textarea.offsetHeight) {
		textarea.rows--;
	}
	while(textarea.scrollHeight > textarea.offsetHeight) {
		textarea.rows++;
		textarea.rows++;
	}	
	return;
};

function checkemail(mail,button) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(mail)) {
		document.getElementById(button).disabled = false;
	} else {
		document.getElementById(button).disabled = true;
	}
};


function insertproduct(page, subpage) {
	var s = "status_"+page+"_"+subpage;
	var status = document.getElementById(s);
	
	status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />Arbetar...';
	//"<img src=\"assets/graphics/icons/loading.gif\" alt=\"".$loading."\" class=\"icon\" />".$loading."";
	$("#"+s).fadeIn("fast");
	
	$.post("operator.php", { mode: "insertproduct", p: page, sp: subpage }, function(data){ 
		if(data.substr(0, 6) == "#DONE#") {
			status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />'+data.substr(6);
			function hidehint() {
				$("#"+s).fadeOut("slow", function callback() { 
					window.location.reload(); 
				});
			}
			setTimeout(hidehint, hinttimeout);		
		} else {
			status.innerHTML = data;
		}
	});
};
function insertdata(page,area) {
	var s = "status_"+area;
	var status = document.getElementById(s);
	
	var h = document.getElementById("head_"+area).value;
	h.replace(/\n/g, '<br>');
	h.replace(/([.*+?'^${}()|[\]\/\\])/g, '\\$1');
	
	var b = document.getElementById("body_"+area).value;
	b.replace(/\n/g, '<br>');
	b.replace(/([.*+?'^${}()|[\]\/\\])/g, '\\$1');
	
	status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />Arbetar...';
	//"<img src=\"assets/graphics/icons/loading.gif\" alt=\"".$loading."\" class=\"icon\" />".$loading."";
	$("#"+s).fadeIn("fast");
	
	$.post("operator.php", { mode: "insert", p: page, a: area, h: h, b: b }, function(data){ 
		if(data.substr(0, 6) == "#DONE#") {
			status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />'+data.substr(6);
			function hidehint() {
				$("#"+s).fadeOut("slow", function callback() { 
					window.location.reload(); 
				});
			}
			setTimeout(hidehint, hinttimeout);		
		} else {
			status.innerHTML = data;
		}
	});
};
function deleteproduct(area, id) {
	var s = "deletestatus_"+area+"_"+id;
	var status = document.getElementById(s);
	
	status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />Arbetar...';
	//"<img src=\"assets/graphics/icons/loading.gif\" alt=\"".$loading."\" class=\"icon\" />".$loading."";
	$("#"+s).fadeIn("fast");
	
	$.post("operator.php", { mode: "deleteproduct", k: area, i: id }, function(data){ 
		if(data.substr(0, 6) == "#DONE#") {
			status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />'+data.substr(6);
			function hidehint() {
				$("#"+s).fadeOut("slow", function callback() { 
					window.location.reload(); 
				});
			}
			setTimeout(hidehint, hinttimeout);		
		} else {
			status.innerHTML = data;
		}
	});
};
function deletedata(area, id) {
	var s = "deletestatus_"+area+"_"+id;
	var status = document.getElementById(s);
	
	status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />Arbetar...';
	//"<img src=\"assets/graphics/icons/loading.gif\" alt=\"".$loading."\" class=\"icon\" />".$loading."";
	$("#"+s).fadeIn("fast");
	
	$.post("operator.php", { mode: "delete", i: id }, function(data){ 
		if(data.substr(0, 6) == "#DONE#") {
			status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />'+data.substr(6);
			function hidehint() {
				$("#"+s).fadeOut("slow", function callback() { 
					window.location.reload(); 
				});
			}
			setTimeout(hidehint, hinttimeout);		
		} else {
			status.innerHTML = data;
		}
	});
};
function updatedata(area, id) {
	var s = "status_"+area+"_"+id;
	var status = document.getElementById(s);
	
	var h = document.getElementById("head_"+area+"_"+id).value;
	h.replace(/\n/g, '<br>');
	h.replace(/([.*+?'^${}()|[\]\/\\])/g, '\\$1');
	
	var b = document.getElementById("body_"+area+"_"+id).value;
	b.replace(/\n/g, '<br>');
	b.replace(/([.*+?'^${}()|[\]\/\\])/g, '\\$1');
	
	status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />Arbetar...';
	//"<img src=\"assets/graphics/icons/loading.gif\" alt=\"".$loading."\" class=\"icon\" />".$loading."";
	$("#"+s).fadeIn("fast");
	
	$.post("operator.php", { mode: "update", i: id, h: h, b: b }, function(data){ 
		if(data.substr(0, 6) == "#DONE#") {
			status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />'+data.substr(6);
			function hidehint() {
				$("#"+s).fadeOut("slow", function callback() { 
					window.location.reload(); 
				});
			}
			setTimeout(hidehint, hinttimeout);		
		} else {
			status.innerHTML = data;
		}
	});
};
function updateproperty(property, id) {
	var s = "status_"+property+"_"+id;
	var status = document.getElementById(s);
	
	var p = document.getElementById(property+"_"+id).value;
	p.replace(/\n/g, '<br>');
	p.replace(/([.*+?'^${}()|[\]\/\\])/g, '\\$1');
	
	status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />Arbetar...';
	//"<img src=\"assets/graphics/icons/loading.gif\" alt=\"".$loading."\" class=\"icon\" />".$loading."";
	$("#"+s).fadeIn("fast");
	
	$.post("operator.php", { mode: "updateproperty", update: property, i: id, p: p }, function(data){ 
		if(data.substr(0, 6) == "#DONE#") {
			status.innerHTML = '<img src="assets/graphics/icons/loading.gif" alt="Arbetar" class="icon" />'+data.substr(6);
			function hidehint() {
				$("#"+s).fadeOut("slow", function callback() { 
					window.location.reload(); 
				});
			}
			setTimeout(hidehint, hinttimeout);		
		} else {
			status.innerHTML = data;
		}
	});
};
