	function roll_over(img_name, img_src)
	{
	document[img_name].src = img_src;
	}
	
	
	
function displayInfo(sTag, sText) {
	var divTag = document.getElementById(sTag);
    divTag.innerHTML = sText;
	divTag.style.display = 'block';
	$(sTag).innerHTML = sText;
}

function loadFormToDiv(urlContent, sDivTarget) {
	var div1 = document.getElementById(sDivTarget);
	div1.style.display = 'block';
	
	var oOptions = {
        method: "post",
        parameters: "",
        onSuccess:function (oXHR, oJson) {
			displayInfo(sDivTarget, oXHR.responseText);
        },
        onFailure: function (oXHR, oJson) {
			alert("An error occurred: " + oXHR.statusText);
        }
    };
	var oRequest = new Ajax.Request(urlContent, oOptions);
}

function loadFormToDivWith1Data(urlContent, sDivTarget, data) {
	var div1 = document.getElementById(sDivTarget);
	div1.style.display = 'block';
	var oOptions = {
        method: "post",
		parameters: {
			data :  data
		},
        onSuccess:function (oXHR, oJson) {
			displayInfo(sDivTarget, oXHR.responseText);
        },
        onFailure: function (oXHR, oJson) {
			alert("An error occurred: " + oXHR.statusText);
        }
    };
	var oRequest = new Ajax.Request(urlContent, oOptions);
}	

function showAddBookForm(){
	loadFormToDiv('main_menu.php', 'content');
//	loadFormToDiv('product/add_product_form.php', 'content');
//	loadFormToDiv('news/add_news_form.php', 'content');
//	loadFormToDiv('news/add_news_category_form.php', 'content');
}
	
function show_main_menu(){
	loadFormToDiv('main_menu.php', 'content');
}

function showAddPrdCat(){
	loadFormToDiv('product/add_product_category_form.php', 'div_edit');
}

function showAddPrd(){
	loadFormToDiv('product/add_product_form.php', 'div_edit');
}

function showAddNewsCat(){
	loadFormToDiv('news/add_news_category_form.php', 'div_edit');
}

function showAddNews(){
	loadFormToDiv('news/add_news_form.php', 'div_edit');
}

function process_logout(){
	loadFormToDivWith1Data('logout_process.php', 'div_edit', 1);
}

function validate_login(){
	process_login();
}	
	
function process_login(){
	var _txtUser = $('txtUserName').value;
	var _txtPwd = $('txtPassword').value;
	var oOptions = {
		method: 'post',
		parameters: {
			txtUser :  _txtUser,
			txtPwd :  _txtPwd
		},
		onSuccess: function(oXHR, oJson){
			//resetWaitingImage();
			var responseText = oXHR.responseText;
			//alert(responseText);
			if(Left(responseText , 1) == '1'){
				show_main_menu();
				//alert('yes');
			}else{
				displayInfo('content' , "<center><font size='4'>User หรือ Password ไม่ถูกต้อง<font><br><br><a href='index.php'><font size='3'><b>>>> กลับไปหน้า Login <<<</b></font></a></center>");
				
			}
		},
		onFailure: function(oXHR, oJson){
			alert("An error occurred: " + oXHR.statusText);
		}
	};
	//loadWaitingImage();
	var oRequest = new Ajax.Request("login_process.php", oOptions);	
}


function addPrdCatValidate(){
	if (isEmpty('txtPrdCat', 'กรุณาใส่ข้อมูล Category Name ค่ะ')) {
		addPrdCatProcess();
	}
}

function addPrdCatProcess(){
	var oOptions = {
		method: 'post',
		parameters: {
			txtPrdCat :  $('txtPrdCat').value
		},
		onSuccess: function(oXHR, oJson){
			var responseText = oXHR.responseText;
			alert('บันทึกข้อมูลเรียบร้อยแล้วค่ะ');
			//alert(responseText);
			$('txtPrdCat').value = '';

		},
		onFailure: function(oXHR, oJson){
			alert("An error occurred: " + oXHR.statusText);
		}
	};
	var oRequest = new Ajax.Request("product/add_product_category_process.php", oOptions);	
}

function addPrdValidate(){
	
	$G('txtTitle').addEvent(doKeypress);
/*	
	if(madeSelection('CatID', 'กรุณาเลือก Category ค่ะ')){
		if (isEmpty('txtTitle', 'กรุณาใส่ ชื่อสินค้า ค่ะ')) {
			if (isEmpty('txtAuthor', 'กรุณาใส่ ชื่อนักเขียน ค่ะ')) {
				if (isEmpty('txtPrice', 'กรุณาใส่ ราคาเต็ม ค่ะ')) {
					if (isEmpty('txtRating', 'กรุณาใส่ Rating ค่ะ')) {
						if (isEmpty('txtImageS', 'กรุณาใส่ ชื่อไฟล์รูปปก(เล็ก) ค่ะ')) {
							if (isEmpty('txtImageL', 'กรุณาใส่ ชื่อไฟล์รูปปก(ใหญ่) ค่ะ')) {
								addPrdProcess();
							}
						}
					}
				}
			}
		}
	}*/
}

function addPrdProcess(){
	var oOptions = {
		method: 'post',
		parameters: {
			CatID :  $('CatID').value,
			txtTitle :  $('txtTitle').value,
			txtAuthor :  $('txtAuthor').value,
			txtPrice :  $('txtPrice').value,
			txtRating :  $('txtRating').value,
			txtImageS :  $('txtImageS').value,
			txtImageL :  $('txtImageL').value
		},
		onSuccess: function(oXHR, oJson){
			var responseText = oXHR.responseText;
			//alert(responseText)
			alert('บันทึกข้อมูลเรียบร้อยแล้วค่ะ');
			//alert(responseText);
			//$('txtPrdCat').value = '';

		},
		onFailure: function(oXHR, oJson){
			alert("An error occurred: " + oXHR.statusText);
		}
	};
	var oRequest = new Ajax.Request("product/add_product_process.php", oOptions);	
}








