function open_url(url)
{
	window.open(url);
}

function check_session()
{
	var url = HTTP_PATH+"/ajax-files/verify-image/verify-image-check.php?value="+document.getElementById("txt-verify").value;
	var temp=ajaxLoad2(url);
	//alert(temp);
	return(temp == "true" ? true : false);
}

function re_verify(num)
{
	if(num == 0)
	{
		//alert("55");
		var url = HTTP_PATH+"/ajax-files/verify-image/verify.php?";
		var data = "";
			data += "&action=re_varify_image";
			ajaxLoad1('POST',url,data,'label_verify','label_verify_load',2);

	}
	
}

function open_replecs(url)
{
	document.location.replace(url);
}



function checkStr(val) 
{
  var str = '<>&*/\\|+_-%()!@#$^=.,{}[]฿'; //ตัวอักษรที่ไม่ต้องการให้มี
  if (val.indexOf("'")!= -1) return true //เครื่องหมาย '
  if (val.indexOf('"')!= -1) return true //เครื่องหมาย "
  for (i = 0; i < str.length; i++) {
    if (val.indexOf(str.charAt(i))!= -1) return true
  }
  return false
}		   

function checkStr_comment(val) 
{
  var str = '<>*\\|%#${}[]฿'; //ตัวอักษรที่ไม่ต้องการให้มี
 // if (val.indexOf("'")!= -1) return true //เครื่องหมาย '
  if (val.indexOf('"')!= -1) return true //เครื่องหมาย "
  for (i = 0; i < str.length; i++) {
    if (val.indexOf(str.charAt(i))!= -1) return true
  }
  return false
}	

function len_cm(val)
{
  var count=0;;
  var str = '*/+_-()!@^=.,'; //ตัวอักษรที่ไม่ต้องการให้มี
 // if (val.indexOf("'")!= -1) return true //เครื่องหมาย '
  if (val.indexOf('"')== -1) count++;//เครื่องหมาย "
  for (i = 0; i < str.length; i++) {
    if (val.indexOf(str.charAt(i))== -1) 
		count++;
  }
  if(val.length <= count+1)
  {
  	return false;
  }
  //alert(count);
}

function post_comment(id,cat_id)
{
	var str = document.getElementById("txt-detail");
	var name = document.getElementById("txt-name");
	//alert(str.value.length);
	if(name.value == "" || str.value == " ")
	{
		alert("กรุณากรอกชื่อของท่าน และมีความยาวไม่ต่ำกว่า 3 ตัวอักษร");
		name.focus();
		return false;
	}
	if (checkStr(name.value))
	 { 
		alert('ชื่อไม่ถูกต้อง!!!'); 
		name.focus();
		return false;
	 }
	if (!isNaN(name.value))
	 { 
		alert('ชื่อไม่ถูกต้อง!!!'); 
		name.focus();
		return false;
	 }	 
	if(name.length < 2 )
	{
		alert("ชื่อของท่านสั้นเกินไป!!!!");
		name.focus();
		return false;		
	}
	if(str.value == "" || str.value == null || str.value == " ")
	{
		alert("กรุณากรอกความคิดเห็น");
		str.focus();
		return false;
	}
	if(checkStr_comment(str.value))
	 { 
		alert('ข้อความไม่ถูกต้อง'); 
		str.focus();
		return false;
	 }	
	if(str.length < 3)
	{
		alert("ความคิดเห็นของท่านสั้นเกินไป!!!");
		str.focus();
		return false;		
	}
	if(len_cm(str.value))
	{
		alert("มีอักขระในข้อความมากเกินไป!!");
		str.focus();
		return false;			
	}
	if(!check_session())
	{
		alert("กรุณากรอกรหัสให้ตรงกับภาพด้านซ้ายด้วยค่ะ");
		document.getElementById("txt-verify").focus();
		return false;
	}
	if(confirm("ยืนยันการแสดงความคิดเห็น"))
	{
		
	
		url = HTTP_PATH+"/front-comment/comment-add.php?";
		data = "";
		data += "&txt_name="+encodeURI(name.value);
		data += "&txt_detail="+encodeURI(str.value);
		data += "&content_id="+id;
		data += "&cat_id="+cat_id;
		data += "&value="+encodeURI(document.getElementById("txt-verify").value);
		data += "&action=post";
		
		ajaxLoad1('POST',url,data,'div_post','div_post_load',1);
		
	}
	
}


