﻿var currentMainHomePagingPos;
// Removes leading whitespaces
function LTrim( value )
{
 	var re = /\s*((\S+\s*)*)/;
  	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value )
{
 	var re = /((\s*\S+)*)\s*/;
  	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim( value )
{
 	return LTrim(RTrim(value));
}
function CheckSpecialChar(str, checknull)
{
	//alert(str);
	var spChar = new Array();
	spChar[0] = "*";
	spChar[1] = "#";
	spChar[2] = "&";
	spChar[3] = "'";
	spChar[4] = "\"";
	for(var i=0; i<spChar.length;i++)
	{
		if(str.indexOf(spChar[i]) >= 0)
		{
			return true;
		}
	}
	if(checknull)
	{
		str = trim(str);
		if((str.length == 0) || (str == ' '))
		{
			return true;
		}
	}
	return false;
}

function Register_EnableButton(val){
    var el = document.getElementById('register_button');
    if(el != null)
    {
        el.disabled = !val;
    }
}
/**
 *
 * @access public
 * @return void
 **/
function Confirmpass(){
	var el = document.getElementById('pass');
	var el2 = document.getElementById('cofirmpass');
	if(el.value!=el2.value)
	{
    	alert('Confirm password not true!');
        return false;
	}
   	return true;
}
function Register_CheckInput(){
    var el = document.getElementById('email');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input email!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
	var el = document.getElementById('pass');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input password!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
	var el2 = document.getElementById('cofirmpass');
    if(el2 != null)
	{
    	if(el.value!=el2.value)
    	{
        	alert('Confirm password not true!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
	var el = document.getElementById('fullname');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input fullname!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
	var el = document.getElementById('phone');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input phone number!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
	var el = document.getElementById('address');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input address!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
return true;
}
function Contact_CheckInput(){
    var el = document.getElementById('email');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input email!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}

	var el = document.getElementById('fullname');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input fullname!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
	var el = document.getElementById('phone');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input phone number!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
	var el = document.getElementById('content');
    if(el != null)
	{
    	if(el.value=="")
    	{
        	alert('You not yet input content!!');
            return false;
    	}
	}
	else
	{
    	return false;
	}
return true;
}
function ShowCurrentPaging(currPage, totalPage, numPageDis, prefix){
    currentMainHomePagingPos = currPage;
    var lastPos = currPage + numPageDis;
    var el = null;
    for(var i=1; i<=totalPage; i++)
    {
        el = document.getElementById(prefix+i);
        if(el != null)
        {
            if((i<lastPos)&&(i>=currPage))
            {
                el.style.display = '';
            }
            else
            {
                el.style.display = 'none';
            }
        }
    }
}
/**
 *
 * @access public
 * @return void
 **/
function ShowPrePaging(numPageDis, totalPage, prefix){
    tmpPos = currentMainHomePagingPos - numPageDis;
    currPos = (tmpPos > 0) ? tmpPos : 1;
    ShowCurrentPaging(currPos, totalPage, numPageDis, prefix);
}
/**
 *
 * @access public
 * @return void
 **/
function ShowNextPaging(numPageDis, totalPage, prefix){
    tmpPos = currentMainHomePagingPos + numPageDis;
    currPos = (tmpPos > totalPage) ? currentMainHomePagingPos : tmpPos;
    ShowCurrentPaging(currPos, totalPage, numPageDis, prefix);
}

function ConfirmDelete(){

    var answer = confirm("Bạn thực sự muốn xóa thông tin này?");

	if (answer){
		return true;

	}
	else{
		return false;
	}

}
function ShowTypeChildren(name){
	var els = document.getElementById(name);
	els.style.display = '';
}
/**
 *
 * @access public
 * @return void
 **/
function HideTypeChildren(name){
	var els = document.getElementById(name);
	els.style.display = 'none';
}
