// JavaScript Document
// JavaScript Document
//member
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function SelectImage(form,folder){	
	window.open("../images_manager.php?folder="+folder+"&form="+form, "logo", "top=100,left=100,height=410,width=570,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes");
}
function update_link(login){
	window.location=login;
}
function del_link(login){
	 str=window.confirm("Are you sure to delete?");
	 if(str==true){
	   window.location=login;					
	 }
}	 	

function check_ID(){
	var str = String(document.forms["frm_register"].txt_user.value);
	if(str=="" || str.length < 6){
		alert("Bạn chưa nhập Username hoặc Username bạn nhập vào nhỏ hơn 6 ký tự!");
		document.forms["frm_register"].txt_user.focus();
		return false;
	}else
		window.open('http://www.diaocthuthiem.vn/form_check.php?user=' + document.forms["frm_register"].txt_user.value ,'check','height=150,width=400');
}

function check_frm_register(theform)
{
	var frm = theform;
	var str = String(document.forms["frm_register"].txt_user.value);
	if(str=="" || str.length < 6){
		alert("Bạn chưa nhập Username hoặc Username bạn nhập vào nhỏ hơn 6 ký tự!");
		document.forms["frm_register"].txt_user.focus();
		return false;
	}	
	if(document.forms['frm_register'].txt_pass.value=="")
	{
		alert("Vui lòng nhập vào password!");
		document.forms['frm_register'].txt_pass.focus();
		return false;
	}
	if(document.forms['frm_register'].txt_verify_pass.value=="")
	{
		alert("PVui lòng nhập lại password!");
		document.forms['frm_register'].txt_verify_pass.focus();
		return false;
	}
	if(document.forms['frm_register'].txt_pass.value!=document.forms['frm_register'].txt_verify_pass.value)
	{
		alert("Mật khẩu và xác nhận mật khẩu bạn nhập vào không đúng. Vui lòng nhập lại!");
		document.forms['frm_register'].txt_verify_pass.focus();
		return false;
	}
	if(document.forms['frm_register'].txt_name.value=="")
	{
		alert("Vui lòng nhập vào tên hoặc công ty!");
		document.forms['frm_register'].txt_name.focus();
		return false;
	}
	if(document.forms['frm_register'].txt_address.value=="")
	{
		alert("Vui lòng nhập vào địa chỉ!");
		document.forms['frm_register'].txt_address.focus();
		return false;
	}
	if(document.forms['frm_register'].txt_phone.value=="")
	{
		alert("Vui lòng nhập vào số điện thoại!");
		document.forms['frm_register'].txt_phone.focus();
		return false;
	}
	if(document.forms['frm_register'].txt_email.value=="")
	{
		alert("Vui lòng nhập vào địa chỉ email!");
		document.forms['frm_register'].txt_email.focus();
		return false;
	}
	if(!CheckEmail(document.forms['frm_register'].txt_email.value))
	{
		alert("Địa chỉ email không hợp lệ. Vui lòng nhập lại!");
		document.forms['frm_register'].txt_email.focus();
		return false;
	}	
	if(document.forms['frm_register'].security_code.value!=document.forms['frm_register'].hid_security_code.value)
	{
		alert("Vui lòng nhập vào mã số bảo vệ ở hình bên dưới!");
		document.forms['frm_register'].security_code.focus();
		return false;
	}
	document.forms['frm_register'].submit();
	return true;
	
}
function check_frm_forgotpassword(theform)
{
	var frm = theform;
	if(frm.txt_user.value=="")
	{
		alert("Please enter your username");
		frm.txt_user.focus();
		return false;
	}
	frm.submit();	
}
function check_frm_signin(theform)
{
	var frm = theform;
	if(frm.txt_user.value=="")
	{
		alert("Vui lòng nhập vào tên đăng nhập!");
		frm.txt_user.focus();
		return false;
	}
	if(frm.txt_pass.value=="")
	{
		alert("Vui lòng nhập vào mật khẩu!");
		frm.txt_pass.focus();
		return false;
	}
	frm.submit();
	return true;	
}
function isInvalid(str) {
	var valid = "0123456789";
	//var valid = "`~!@#$%^&*,./<>?;:'\"[]{}\\|";
	var temp;
	for (var i = 0; i < str.length; i++) {
		temp = "" + str.substring(i, i + 1);
		if (valid.indexOf(temp) == "0" | valid.indexOf(temp) >= 1) 
			return false;
	}
	return true;
}
//------------------------------------------------------------
function KhoaPhim(){
  strTam=String.fromCharCode(event.keyCode);
  if (isInvalid(strTam)) event.keyCode=0;
}
	function add_key(){
		if(document.forms['frm'].txt_key.value!=""){
			if(document.forms['frm'].sl_key.length >= 10){
				alert("Limited 10 keywords!");
				return false;
			}
			
		 for(i=0;i<document.forms['frm'].sl_key.length;i++){
		 	if(document.forms['frm'].sl_key[i].value==document.forms['frm'].txt_key.value){
				alert("Not avaiable. Please choose other keyword!");
				return false;
			}
		 }
			var vaTemp=new Array(2);							
				vaTemp[0] = document.forms['frm'].txt_key.value;							
				vaTemp[1] = document.forms['frm'].txt_key.value;
				
				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
			  	j = document.forms['frm'].sl_key.length;
				document.forms['frm'].sl_key.options[j] = NewOptItem;									
				NewOptItem1 = null;
				document.forms['frm'].txt_key.value = "";
				document.forms['frm'].txt_key.focus();
				
		}else{
			alert("Please enter your keyword!");
			document.forms['frm'].txt_key.focus();
			return false;
		}
	}
	function textLimitCheck(thisArea, showArea)
		{		
			showArea.value = thisArea.value.length;
		}
	function DisplayDelete(){
   		if(document.forms['frm'].sl_key.selectedIndex >-1){
			s = document.forms['frm'].sl_key.selectedIndex;
			document.forms['frm'].sl_key.remove(s);
		}else{
			alert("Please choose your keyword to delete!");
		}
   }	
	function SelectImageProfile(form,id){	
		window.open("../images_profile_manager.php?folder="+id+"&form="+form, "logo", "top=100,left=100,height=410,width=570,scrollbars=yes,status=yes,resize=yes");
	}
	function check_form_profile(){
		if(document.forms['frm'].txt_category_str.value == ""){
			alert("Please choose your category!");
			document.forms['frm'].btn_category.click();
			return false;
		}else if(document.forms['frm'].sl_key.length==0){
			alert("Please choose your keyword for your products and services!");
			document.forms['frm'].txt_key.focus();
			return false;		
		}else if(document.forms['frm'].txt_service.value.length < 20 || document.forms['frm'].txt_service.value.length > 200){
			alert("Please enter 20 to 2000 characters for your services!");
			document.forms['frm'].txt_service.focus();
			return false;		
		}else if(document.forms['frm'].txt_info.value.length < 200 || document.forms['frm'].txt_info.value.length > 4000){
			alert("Please enter 200 to 4000 characters for your introduction information!");
			document.forms['frm'].txt_info.focus();
			return false;
		}
		 for(i=0;i<document.forms['frm'].sl_key.length;i++){
			document.frm.sl_key[i].selected=true;	
	     }	
		 document.forms['frm'].sl_key.name 	= "sl_key[]";
	}		
	function check_form_trade_lead(){
		
		if(frm.sl_type.value == ""){
			alert("Please choose your type trade lead!");
			frm.sl_type.focus();
			return false;
		}else if(frm.txt_subject.value == ""){
			alert("Please enter title!");
			frm.txt_subject.focus();
			return false;
		}else if(frm.txt_category_str.value == ""){
			alert("Please choose category!");
			frm.btn_category.click();
			return false;
		}else if(frm.sl_key.length==0){
			alert("Please choose keyword to support search engine!");
			frm.txt_key.focus();
			return false;		
		}else if(frm.txt_detail.value==""){
			alert("Please enter detail information!");
			frm.txt_detail.focus();
			return false;
		}
		 for(i=0;i<frm.sl_key.length;i++){
			document.frm.sl_key[i].selected=true;	
	     }	
		 frm.sl_key.name 	= "sl_key[]";		 
	}
	function SelectImageLogo(form,id){	
		window.open("../images_logo_manager.php?folder="+id+"&form="+form, "logo", "top=100,left=100,height=410,width=570,scrollbars=yes, resize=yes");
	}
	function check_inquiry(url)
	{
			var check = false;
			for (var i=0; i<document.forms['frm_inquiry'].elements.length;i++){
				var e = document.forms['frm_inquiry'].elements[i];
				if (e.name == 'id_product[]' && e.checked == true){
						check = true;
				}
			}			
			if(check==false){
				alert("Please choose a product!");
				return false;
			}				
			document.forms['frm_inquiry'].action = url;
			document.forms['frm_inquiry'].submit();
	}
function check_pass_frm_register(theform)
{
	if(document.forms['frm_signin'].txt_pass1.value=="")
	{
		alert("Vui lòng nhập vào password cũ!");
		document.forms['frm_signin'].txt_pass1.focus();
		return false;
	}
	if(document.forms['frm_signin'].txt_pass_new1.value=="")
	{
		alert("Vui lòng nhập vào password!");
		document.forms['frm_signin'].txt_pass_new1.focus();
		return false;
	}
	if(document.forms['frm_signin'].txt_pass_new2.value=="")
	{
		alert("PVui lòng nhập lại password!");
		document.forms['frm_signin'].txt_pass_new2.focus();
		return false;
	}
	if(document.forms['frm_signin'].txt_pass_new1.value!=document.forms['frm_signin'].txt_pass_new2.value)
	{
		alert("Mật khẩu và xác nhận mật khẩu bạn nhập vào không đúng. Vui lòng nhập lại!");
		document.forms['frm_signin'].txt_pass_new2.focus();
		return false;
	}
	return true;
	
}
function check_inforrmation(theform)
{
	var frm = theform;
	
	if(!CheckEmail(document.forms['frm_register'].txt_email.value))
	{
		alert("Địa chỉ email không hợp lệ. Vui lòng nhập lại!");
		document.forms['frm_register'].txt_email.focus();
		return false;
	}	
	frm.submit();
	return true;	
	
}
function check_post_home(theform)
{
	if(document.forms['frm_search2'].title.value=="")
	{
		alert("Vui lòng nhập vào title!");
		document.forms['frm_search2'].title.focus();
		return false;
	}
	if(document.forms['frm_search2'].used_area.value=="")
	{
		alert("Vui lòng nhập vào Diện tích sử dụng!");
		document.forms['frm_search2'].used_area.focus();
		return false;
	}
	
	return true;
	
}
function del_link1(login){
	 str=window.confirm("Bạn thật sự muốn xoá chứ!");
	 if(str==true){
	   window.location=login;					
	 }
}
function del_link2(login){
	 str=window.confirm("Bạn thật sự muốn Phục hồi!");
	 if(str==true){
	   window.location=login;					
	 }
}	
// them moi ngay 16
function SelectImageMember(form)
{	

	window.open("../../Image_Member.php?form="+form, "newImage", "top=100,left=100,height=450,width=570,scrollbars=no");
}
function SelectImageProduct(form)
{	

	window.open("../../Image_product.php?form="+form, "newImage", "top=100,left=100,height=450,width=570,scrollbars=no");
}
function SelectImageProductupdate(form)
{	

	window.open("../../../Image_product.php?form="+form, "newImage", "top=100,left=100,height=450,width=570,scrollbars=no");
}

