// JavaScript Document
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkNumber(ch){
	var len, digit;
	if(ch == " "){ 
		len=0;
	}else{
		len = ch.length;
	}
	if (len == 0)
		return true;
		
	for(var i=0 ; i<len ; i++)
	{ 
		digit = ch.charAt(i)
		if(!(digit >= "0" && digit <= "9")){
			return false;
		}else{
			; 
		} 
	}  // end for
	
	return true;
}// end function

function checkMemberRegister(){
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	if ($('username').value.length == '') {
		alert('กรุณากรอก Username');
		$('username').focus();
		return false;
	} // end if
	
	if ( !checkUsernameForm($('username').value) ) {
		alert('Username ต้องเป็นตัวอักษร A-Z , a-z , _ , - เท่านั้น !');
		$('username').focus();
		return false;
	}
	
	if (!(format_mail.test($('email').value))) {
		alert('กรุณากรอก Email ให้ถูกต้อง!');	
		$('email').focus();
		return false;
	} // end if	
	
	if ($('password').value.length == '') {
		alert('กรุณากรอก Password');
		$('password').focus();
		return false;
	} // end if
	
	if ( ($('c_password').value.length == '') || ($('password').value != $('c_password').value) ) {
		alert('กรุณากรอก ยืนยัน Password');
		$('c_password').focus();
		return false;
	} // end if

	if ($('hidden_code').value != $('security_code').value) {
		alert('กรุณากรอกรหัสที่ปรากฎให้ถูกต้อง!');	
		$('security_code').focus();
		return false;
	} // end if	
	
} // end function

var gSkill = 0;
function addSkill() {
	var li = document.createElement('li');
	li.setAttribute('id', 'other_skill-' + (gSkill+1));
	li.innerHTML = 'จำนวน<input name="price_amount[]" type="text" id="price_amount_'+(gSkill+1)+'" size="5">&nbsp;&nbsp; ราคา<input name="price_value[]" type="text" id="price_value_'+(gSkill+1)+'" size="5">&nbsp;<input type="button" value=" + " onClick="addSkill()"><input type="button" value=" - " onClick="removeSkill(\'other_skill-' + (gSkill+1) + '\')">';
	document.getElementById('files-root').appendChild(li);
	gSkill++;
} // end function

function removeSkill(aId) {
	var obj = document.getElementById(aId);
	obj.parentNode.removeChild(obj);
} // end function

function addCard(productId, value){
		var url = '/ajaxFile/getAddCard.php';
		new Ajax.Request(url,
			{
				method: "POST",
				parameters: "product_id="+productId+'&amount='+value,
				onComplete: callbackAddCard
			}
		);
} // end function

function callbackAddCard(data){
		$("showCurrentCart").innerHTML = data.responseText;
		var text = '';
		if (configLang=='th')
			text = 'ใส่สินค้าลงในรถเข็นเรียบร้อยแล้ว ต้องการไปหน้าชำระเงินหรือไม่';
		else
			text = 'ใส่สินค้าลงในรถเข็นเรียบร้อยแล้ว ต้องการไปหน้าชำระเงินหรือไม่';
		if (confirm(text)) {
			window.location = pathLang+'/checkout/';
		} else {
			return false;	
		}// end if
} // end function

function checkAddCard(productId, value){
	var text = '';
	if (isNaN(value) || (eval(value) <= 0)) {
		if (configLang=='th')
			text = 'กรุณากรอกจำนวนสินค้าเป็นตัวเลขที่มากว่า 0';
		else
			text = 'กรุณากรอกจำนวนสินค้าเป็นตัวเลขที่มากว่า 0';
		alert(text);
		$('productAmount').focus();
	} else {
		addCard(productId, value);
	}// end if
	return false;
} // end function

function getCurrentProductAmount(div) {
	var rand_no = Math.random();
	rand_no = rand_no * 100;
	
	var url = '/ajaxFile/getAddCard.php';
	var params = 'getProductAmount=1';
	var elementID = div;
	//new Ajax.Request (url, {method: "post", parameters: param, onComplete: callback});
	//new Ajax.Updater (div, url, {method: "get", parameters: params});
	pb = new Ajax.PeriodicalUpdater (elementID, url,{
		method: "GET",
		parameters: params,
		frequency: 10.0,
		decay: 1,
		onComplete: callbackGetCurrentProductAmount
	});
} // end function

function callbackGetCurrentProductAmount(data){
	
} // end function

function checkCalNew(frm,arr){
var message = "";
var text = '';
	for (i = 0; i < frm.elements.length; i++) {
	   try{
		 if(frm.elements[i].id == arr) {
		   if(isNaN(frm.elements[i].value) || (frm.elements[i].value.length == '') ){
				if (configLang=='th')
					message = "กรุณากรอกจำนวนเป็นตัวเลข !";
				else
					message = "กรุณากรอกจำนวนเป็นตัวเลข !";
		   }
		 }
	   } catch(er) {}
	  }
	
	if(message != ""){
		alert(message);
	  	return false;
	}
	else {
		return true;
	}
}

function checkPaymentForm() {
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	var text = '';
	if ($('member_name').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก ชื่อผู้สั่งซื้อ";
		else
			text = "Please fill Name";
		alert(text);
		$('member_name').focus();
		return false;
	} // end if
	
	if ( ($('member_phone').value.length != 10) || (isNaN($('member_phone').value)) ) {
		if (configLang=='th')
			text = "กรุณากรอก เบอร์ติดต่อกลับให้ถูกต้อง";
		else
			text = "Please fill Phone";
		alert(text);
		$('member_phone').focus();
		return false;
	} // end if
	
	if (!(format_mail.test($('member_email').value))) {
		if (configLang=='th')
			text = "กรุณากรอก Email ให้ถูกต้อง!";
		else
			text = "Please fill Email";
		alert(text);	
		$('member_email').focus();
		return false;
	} // end if	
	
	if ($('receive_name').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก ชื่อผู้รับ";
		else
			text = "Please fill Name";
		alert(text);
		$('receive_name').focus();
		return false;
	} // end if
	
	if ($('ship_address').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก ที่อยู่ผู้รับ";
		else
			text = "Please fill Address";
		alert(text);
		$('ship_address').focus();
		return false;
	} // end if
	
	if ($('ship_province').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก จังหวัดผู้รับ";
		else
			text = "Please fill Province";
		alert(text);
		$('ship_province').focus();
		return false;
	} // end if
	
	if ($('ship_zipcode').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก รหัสไปรษณียผู้รับ";
		else
			text = "Please fill zipcode";
		alert(text);
		$('ship_zipcode').focus();
		return false;
	} // end if
	
	if ($('bank_name').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก ธนาคารที่ชำระเงิน";
		else
			text = "Please fill bank name";
		alert(text);
		$('bank_name').focus();
		return false;
	} // end if
	
	if ($('transfer_time').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก เวลาที่โอนเงิน";
		else
			text = "Please fill transfer time";
		alert(text);
		$('transfer_time').focus();
		return false;
	} // end if
	
	if ($('transfer_amount').value.length == 0) {
		if (configLang=='th')
			text = "กรุณากรอก จำนวนเงินที่โอน";
		else
			text = "Please fill money";
		alert(text);
		$('transfer_amount').focus();
		return false;
	} // end if
} // end function

function setPaymentValue(action){
	
	if (action) {
		$('receipt_company').value = $('receive_name').value;
		$('receipt_address').value = $('ship_address').value;
		$('receipt_province').value = $('ship_province').value;
		$('receipt_zipcode').value = $('ship_zipcode').value;
	} else {
		$('receipt_company').value = '';
		$('receipt_address').value = '';
		$('receipt_province').value = '';
		$('receipt_zipcode').value = '';
	}
	
} // end function

function checkOTP(){
	var url = '/ajaxFile/getCheckOTP.php';
		new Ajax.Request(url,
			{
				method: "POST",
				parameters: "check="+$('confirmMember').value,
				onComplete: callbackCheckOTP
			}
		);
} // end function

function callbackCheckOTP(data){
	if (data.responseText == 'Yes') {
		alert('รหัสผ่านชั่วคราว (OTP) ได้ถูกส่ง SMS และ Email ไปถึงคุณแล้ว');
	} else {
		alert('ไม่พบข้อมูลของคุณกรุณาตรวจสอบใหม่');	
		$('confirmMember').focus();
	}
} // end function

function checkPaymentOTPForm(){
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	var text = '';
	
	if (!(format_mail.test($('confirmMemberEmail').value))) {
		if (configLang=='th')
			text = "กรอกอีเมล์ ที่เคยใช้สมัคร";
		else
			text = "Please fill Email";
		alert(text);
		$('confirmMemberEmail').focus();
		return false;
	} // end if	
	
	if ($('confirmMemberPhone').value.length == 0) {
		if (configLang=='th')
			text = "กรอกเบอร์โทรศัพท์ ที่เคยใช้สมัคร";
		else
			text = "Please fill Phone";
		alert(text);
		$('confirmMemberPhone').focus();
		return false;
	} // end if
} // end function

function sendToCart(actionForm, product_id){

	document.getElementById('form1').action = actionForm;
	document.getElementById('product_id').value = product_id;
	document.getElementById('form1').submit();
	
} // end function


function getUnitName(product_id, fieldLang){
	var url = '/ajaxFile/getUnitName.php';
		new Ajax.Request(url,
			{
				method: "GET",
				parameters: "product_id="+product_id+'&fieldLang='+fieldLang,
				onComplete: callbackGetUnitName,
				onInteractive: waitGetUnitName
			}
		);
} // end function

function callbackGetUnitName(data){
	$('show_unit_name').innerHTML = data.responseText;
} // end function

function waitGetUnitName(){
	$('show_unit_name').innerHTML = '<img src="/images/snake_transparent.gif" />';
} // end function

function checkFormAddCart(configLang){
	if ($('product_id').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณาเลือกสินค้า' : 'Pelect Select Product';
		alert(text);
		$('product_id').focus();
		return false;
	} // end if
	
	if (!checkNumber($('input_qty').value) || ($('input_qty').value.length == 0) ) {
		var text = (configLang == 'th') ? 'กรุณากรอกเป็นตัวเลข' : 'Pelect Fill Number Only';
		alert(text);
		$('input_qty').focus();
		return false;
	} // end if
	
	return true;
} // end function

function setProductPrice(product_id, qty, configLang){
	
	if (!checkNumber(qty) || (qty.length == 0)) {
		var text = (configLang == 'th') ? 'กรุณากรอกเป็นตัวเลข' : 'Pelect Fill Number Only';
		alert(text);
		$('input_qty_'+product_id).value = 1;			
		$('input_qty_'+product_id).focus();
		return false;
	} // end if
	
	var url = '/ajaxFile/setProductPrice.php';
		new Ajax.Request(url,
			{
				method: "GET",
				parameters: "product_id="+product_id+'&qty='+qty,
				onComplete: callbackSetProductPrice,
				onInteractive: waitSetProductPrice
			}
		);
} // end function

function callbackSetProductPrice(data){
	var aData = new Array();
	aData = data.responseText.split('***');
	
	var product_id = aData[0];
	var input_qty = aData[1];
	var unit_price = aData[2];
	var sum_price = aData[3];
	var total_price = aData[4];
	
	//$('input_qty_'+product_id).innerHTML = aData[1];
	$('show_unit_price_'+product_id).innerHTML = aData[2];
	$('show_sum_price_'+product_id).innerHTML = aData[3];
	$('show_total_price').innerHTML = aData[4];

} // end function

function waitSetProductPrice(){
	$('show_unit_price_'+product_id).innerHTML = '<img src="/images/snake_transparent.gif" />';
	$('show_sum_price_'+product_id).innerHTML = '<img src="/images/snake_transparent.gif" />';
	$('show_total_price').innerHTML = '<img src="/images/snake_transparent.gif" />';
} // end function

function checkFormAddOrder(configLang){
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	
	if ($('member_name').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณากรอก ชื่อผู้สั่งซื้อ' : 'Pelect Fill Name';
		alert(text);
		$('member_name').focus();
		return false;
	} // end if
	
	if ($('member_phone').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณากรอก เบอร์ติดต่อกลับ' : 'Pelect Fill Phone';
		alert(text);
		$('member_phone').focus();
		return false;
	} // end if
	
	if (!(format_mail.test($('member_email').value))) {
		var text = (configLang == 'th') ? 'กรุณากรอก อีเมล์ให้ถูกต้อง' : 'Email Invalid';
		alert('กรุณากรอก Email ให้ถูกต้อง!');	
		$('member_email').focus();
		return false;
	} // end if	
	
	if ($('ship_address').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณากรอก ที่อยู่ในการรับสินค้า' : 'Pelect Fill Shipping Address';
		alert(text);
		$('ship_address').focus();
		return false;
	} // end if
	
	return true;
} // end function

function checkNotifyPay(configLang) {
	
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	
	if ($('orders_no').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณากรอก เลขใบสั่งซื้อ' : 'Pelect Fill Order No';
		alert(text);
		$('orders_no').focus();
		return false;
	} // end if
	
	if ($('name').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณากรอก ชื่อ-นามสกุล' : 'Pelect Fill Name-Surname';
		alert(text);
		$('name').focus();
		return false;
	} // end if
	
	if (!(format_mail.test($('email').value))) {
		var text = (configLang == 'th') ? 'กรุณากรอก อีเมล์ให้ถูกต้อง' : 'Email Invalid';
		alert('กรุณากรอก Email ให้ถูกต้อง!');	
		$('email').focus();
		return false;
	} // end if	
	
	if ($('tel').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณากรอก เบอร์โทรศัพท์' : 'Pelect Fill Phone Number';
		alert(text);
		$('tel').focus();
		return false;
	} // end if
	
	if ($('bank').value.length == 0) {
		var text = (configLang == 'th') ? 'กรุณาเลือกธนาคารที่ชำระเงิน' : 'Pelect Select Bank Name';
		alert(text);
		$('bank').focus();
		return false;
	} // end if
	
	if ( isNaN($('price').value) || ($('price').value.length == 0) ) {
		var text = (configLang == 'th') ? 'กรุณากรอก จำนวนเงินให้ถูกต้อง' : 'Pelect Fill Price';
		alert(text);
		$('price').focus();
		return false;
	} // end if
	
} // end function

function getConnectSession() {
	var rand_no = Math.random();
	rand_no = rand_no * 100;
	var url = '/ajaxFile/getConnectSession.php';
	var params = 'get=1';
	var elementID = 'connectSession';
	pb = new Ajax.PeriodicalUpdater (elementID, url,{
		method: "GET",
		parameters: params,
		frequency: 10.0,
		decay: 1,
		onComplete: callbackGetConnectSession
	});
} // end function

function callbackGetConnectSession(data){
		
} // end function


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getOrdersDetail(orders_no) {
	
	if (orders_no.length > 0) {
		
		var url = '/ajaxFile/getOrdersDetail.php';
		new Ajax.Request(url,
			{
				method: "POST",
				parameters: "orders_no="+orders_no,
				onComplete: callbackGetOrdersDetail
			}
		);
	
	} // end if (orders_no.length > 0) {
	
} // end function

function callbackGetOrdersDetail(data) {
	
	if (data.responseText.length > 0) {
		
		var aData = new Array();
		
		aData = data.responseText.split('**');
		
		$('name').value = aData[0];
		$('email').value = aData[1];
		$('tel').value = aData[2];
	
	} // end if (data.responseText.length > 0) {
	
} // end function

function setUrlSearch(realPathLang) {
	
	var url = realPathLang + '/search';
	
	url += ($('k_keyword').value.length > 0) ? '/' + $('k_keyword').value : '/all-product';
	
	url += ($('k_category').value.length > 0) ? '/' + $('k_category').value : '/all-category';
	
	window.location = url;
	
} // end function

function setFormCheckout(actionForm, product_id) {
	
	document.getElementById('form1').action = actionForm;
	document.getElementById('product_id').value = product_id;
	document.getElementById('form1').submit();
	
} // end function

function checkUsernameForm(ch){
	var len, digit;
	if(ch == " "){ 
		len=0;
	}else{
		len = ch.length;
	}
	if ( len == 0 )
		return false;
		
	for(var i=0 ; i<len ; i++)
	{
		digit = ch.charAt(i)
		if( (digit >= "A" && digit <= "Z") || (digit >= "a" && digit <= "z") || (digit >="0" && digit <="9") || (digit == "_") || (digit == "-") ){
		; 
		}else{
			return false; 
		} 
	}  // end for
	
	return true;
}// end function

function checkTenderRegister() {
	
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	if ($('username').value.length == '') {
		alert('กรุณากรอก Username');
		$('username').focus();
		return false;
	} // end if
	
	if ( !checkUsernameForm($('username').value) ) {
		alert('Username ต้องเป็นตัวอักษร A-Z , a-z , _ , - เท่านั้น !');
		$('username').focus();
		return false;
	}
	
	if ($('password').value.length == '') {
		alert('กรุณากรอก password');
		$('password').focus();
		return false;
	} // end if
	
	if ( !checkUsernameForm($('password').value) ) {
		alert('Password ต้องเป็นตัวอักษร A-Z , a-z , _ , - เท่านั้น !');
		$('password').focus();
		return false;
	}
	
	if ($('name').value.length == '') {
		alert('กรุณากรอก ชื่อ-นามสกุล');
		$('name').focus();
		return false;
	} // end if
	
	if ($('phone').value.length == '') {
		alert('กรุณากรอก เบอร์ติดต่อกลับ');
		$('phone').focus();
		return false;
	} // end if
	
	if (!(format_mail.test($('email').value))) {
		alert('กรุณากรอก Email ให้ถูกต้อง!');	
		$('email').focus();
		return false;
	} // end if	
	
	if ($('shipping_address').value.length == '') {
		alert('กรุณากรอก ที่อยู่ในการรับสินค้า');
		$('shipping_address').focus();
		return false;
	} // end if
	
	if ($('security_code').value != $('hidden_code').value) {
		alert('กรุณากรอก พิมพ์ตัวเลข 5 ตัวที่คุณเห็นให้ถูกต้อง');
		$('security_code').focus();
		return false;
	} // end if
	
	
	document.getElementById('bSubmit').style.display = 'none';
	document.getElementById('wating').style.display = '';
	
	var url = '/ajaxFile/getCheckTenderRegister.php';
	new Ajax.Request(url,
		{
			method: "POST",
			parameters: "username=" + $('username').value + "&password=" + $('password').value + "&name=" + $('name').value + "&phone=" + $('phone').value + "&email=" + $('email').value + "&shipping_address=" + $('shipping_address').value + "&security_code=" + $('security_code').value + "&hidden_code=" + $('hidden_code').value,
			onComplete: callbackCheckTenderRegister
		}
	);

	
} // end function

function callbackCheckTenderRegister(data) {
	
	var aData = new Array();
	
	aData = data.responseText.replace(/#new#/gi, "\n").split('::');
	
	if (aData[0] == 'no') {
		
		alert(aData[1]);
		
		document.getElementById('wating').style.display = 'none';
		document.getElementById('bSubmit').style.display = '';
		
	} else if (aData[0] == 'ok') { // end if (aData[0] == 'no') {
		
		alert(aData[1]);
		
		window.location = '/tender-login';
		
	} // end else if (aData[0] == 'ok') {
	
	
} // end function

function checkTenderUpdate() {
	
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	
	if ($('old_password').value.length > 0) {
		
		if ( !checkUsernameForm($('old_password').value) ) {
			alert('Old Password ต้องเป็นตัวอักษร A-Z , a-z , _ , - เท่านั้น !');
			$('username').focus();
			return false;
		}
		
		if ( ($('new_password').value.length == 0) || !checkUsernameForm($('new_password').value) ) {
			alert('New Password ต้องเป็นตัวอักษร A-Z , a-z , _ , - เท่านั้น !');
			$('new_password').focus();
			return false;
		}
		
		if ( $('new_password').value != $('c_password').value ) {
			alert('กรุณายืนยันรหัสผ่านใหม่ !');
			$('c_password').focus();
			return false;
		}
	
	} // end if ($('old_password').value.length > 0) {
	
	if ($('name').value.length == 0) {
		alert('กรุณากรอก ชื่อ-นามสกุล');
		$('name').focus();
		return false;
	} // end if
	
	if ($('phone').value.length == 0) {
		alert('กรุณากรอก เบอร์ติดต่อกลับ');
		$('phone').focus();
		return false;
	} // end if
	
	if (!(format_mail.test($('email').value))) {
		alert('กรุณากรอก Email ให้ถูกต้อง!');	
		$('email').focus();
		return false;
	} // end if	
	
	if ($('shipping_address').value.length == 0) {
		alert('กรุณากรอก ที่อยู่ในการรับสินค้า');
		$('shipping_address').focus();
		return false;
	} // end if
	
	if ($('security_code').value != $('hidden_code').value) {
		alert('กรุณากรอก พิมพ์ตัวเลข 5 ตัวที่คุณเห็นให้ถูกต้อง');
		$('security_code').focus();
		return false;
	} // end if
	
	
	document.getElementById('bSubmit').style.display = 'none';
	document.getElementById('wating').style.display = '';
	
	var url = '/ajaxFile/getCheckTenderUpdate.php';
	var param = '';
	param += "old_password=" + $('old_password').value;
	param += "&new_password=" + $('new_password').value;
	param += "&c_password=" + $('c_password').value;
	param += "&name=" + $('name').value;
	param += "&phone=" + $('phone').value;
	param += "&email=" + $('email').value;
	param += "&shipping_address=" + $('shipping_address').value;
	param += "&hidden_code=" + $('hidden_code').value;
	param += "&security_code=" + $('security_code').value;
	
	new Ajax.Request(url,
		{
			method: "POST",
			parameters: param,
			onComplete: callbackCheckTenderUpdate
		}
	);
	
} // end function


function callbackCheckTenderUpdate(data) {
	
	var aData = new Array();
	
	aData = data.responseText.replace(/#new#/gi, "\n").split('::');
	
	if (aData[0] == 'confirmPass') {
		
		alert(aData[1]);
		
		document.getElementById('old_password').select();
		
		document.getElementById('wating').style.display = 'none';
		document.getElementById('bSubmit').style.display = '';
		
	} else if (aData[0] == 'ok') { // end if (aData[0] == 'confirmPass') {
		
		alert(aData[1]);
		
		window.location = '/tender-profile';
		
	} else if (aData[0] == 'error') { // end if (aData[0] == 'no') {
		
		alert(aData[1]);
		
		window.location = '/tender-login';
		
	} // end else if (aData[0] == 'ok') {
	
	
} // end function


function checkTednerLogin() {
	
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	if ($('username').value.length == '') {
		alert('กรุณากรอก Username');
		$('username').focus();
		return false;
	} // end if
	
	if ( !checkUsernameForm($('username').value) ) {
		alert('Username ต้องเป็นตัวอักษร A-Z , a-z , _ , - เท่านั้น !');
		$('username').focus();
		return false;
	}
	
	if ($('password').value.length == '') {
		alert('กรุณากรอก password');
		$('password').focus();
		return false;
	} // end if
	
	if ( !checkUsernameForm($('password').value) ) {
		alert('Password ต้องเป็นตัวอักษร A-Z , a-z , _ , - เท่านั้น !');
		$('password').focus();
		return false;
	}	
	
	document.getElementById('bSubmit').style.display = 'none';
	document.getElementById('wating').style.display = '';
	
	
	var url = '/getCheckTenderLogin.php';
	var param = "username=" + $('username').value + "&password=" + $('password').value;
	
	if ($('remember').checked) {
		
		param += "&remember=" + $('remember').value	
		
	} // end if ($('remember').checked) {
		
	
	new Ajax.Request(url,
		{
			method: "POST",
			parameters: param,
			onComplete: callbackCheckTednerLogin
		}
	);
	
} // end function

function callbackCheckTednerLogin(data) {
	
	var aData = new Array();
	
	aData = data.responseText.replace(/#new#/gi, "\n").split('::');
	
	if (aData[0] == 'no') {
		
		alert(aData[1]);
		
		document.getElementById('wating').style.display = 'none';
		document.getElementById('bSubmit').style.display = '';
		
	} else if (aData[0] == 'ok') { // end if (aData[0] == 'no') {
		
		alert(aData[1]);
		
		window.location = '/tender';
		
	} // end else if (aData[0] == 'ok') {
	
} // end function

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
} // end function

function checkMemberForgot(){
	var format_mail=/^([a-zA-Z0-9\_\-\.]{3,})+@([a-zA-Z0-9\-]{3,})+.+([a-zA-Z]{2,}|.+([a-zA-Z]{2,}))$/;
	if (!(format_mail.test($('femail').value))) {
		alert('กรุณากรอก Email ให้ถูกต้อง!');	
		$('femail').focus();
		return false;
	} // end if	
	
} // end function

