﻿//open popup win
function open_win(url, name, width, height, property)
{
	this.x = (screen.width - width) / 2; 
	this.y = (screen.height - height - 60) / 2; 
	property = 'top=' + this.y + ',left=' + this.x + ',width=' + width + ',height=' + height + ',' + property;
//	property = "scrollbars=1,resizable=1,menubar=1,status=1,location=1,toolbar=1"
	newwindow = window.open(url,name,property);
	if (window.focus) 
	{
			newwindow.focus();
	}
}

function popup_report(url)
{
	window_report = window.open(url,"report","top=150,left=200,width=600,height=390")
}

function popup_sendtofriend(url)
{
	window_report = window.open(url,"sendtofriend","top=150,left=200,width=600,height=390")
}

//kiem tra so va khong co cac ky tu khac
function CheckNumber(stringIn) 
{
     retval = false
     var i;
     for (i=0;i<=stringIn.length-1;i++) 
	 {
         if ((stringIn.charCodeAt(i) >= 48) && (stringIn.charCodeAt(i) <= 57))
		 {
           	retval = true;
         }
		 else
		 {
			retval = false;
			break;
         }
     }
     return retval;
}
/*
*function CheckPass chi cho phep cac ky tu a-z , A-Z , ._-@
* @param string : string can kiem  tra
* @return true neu dung yeu cau, nguoc lai la false.
*/
function CheckPass(stringIn) 
{
     retval = false;
     var i;
     for (i=0;i<=stringIn.length-1;i++) 
	 {
		mcode = stringIn.charCodeAt(i);
		if(((mcode >=64) && (mcode <=90)) || ((mcode >=97) && (mcode <=122)) || ((mcode >=48) && (mcode <=57)) || (mcode == 45) || (mcode ==95) || (mcode ==46))
		{
           	retval = true;
         }
		 else
		 {
			retval = false;
			break;
         }
     }
     return retval;
}
/*
*function CheckEmail dung de kiem tra co dung kieu email hay khong (chi co 1 dau @, va it nhat 1 dau ".")
*@param email : nhap emial can kiem tra
*@return false khong dung kieu email, true thoa dieu kien.
*/
function CheckEmail(stringIn)
{
	var re = /^([A-Za-z0-9\_\-]+\.)*[A-Za-z0-9\_\-]+@[A-Za-z0-9\_\-]+(\.[A-Za-z0-9\_\-]+)+$/;
	if (stringIn.search(re) == -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}
//cat bo hai dau khoang trang
function trim(val)
{ 
	return val.replace(/^\s+|\s+$/g,"");
}

//---------- khoi tao AJAX ----------
function getHTTPObject() 
{
	var xmlhttp;
	
	if(window.XMLHttpRequest) 
	{
		xmlhttp = new XMLHttpRequest();
	} 
	else if(window.ActiveXObject) 
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		if (!xmlhttp) 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
    if(xmlhttp)
		return xmlhttp;
	else
		alert("Your browser does not permit the use of all of this application's features!");
}
var http = getHTTPObject();
//---------- ket thuc khoi tao AJAX ----------

//function kiem tra co check radio / checkbox
function check_arr(form,type)
{
	elem = form.elements;
 	var tong_chk = 0;
	for(i=0; i < elem.length; i++)
	{
		if(elem[i].type == type && elem[i].checked)
		{
			tong_chk++;
		}
	}
	return tong_chk;
}
//check all checkbox
function chon(form,value)
{
	elem = form.elements;
	for(i=0; i < elem.length; i++)
	{
		if(elem[i].type == "checkbox")
			elem[i].checked = value;
	}
}
