//****************************************************************************
//Check if s is number
//example: if (!is_number(number)) { error }
//****************************************************************************
function is_number(s) 
{
	var patrn = /^([0-9]{1,})$/;
	if(!patrn.exec(s)) return false;
	return true;
}
//****************************************************************************
//Check if s is letters
//example: if (!is_letter(number)) { error }
//****************************************************************************
function is_letter(s) 
{
	var patrn = /^([A-Z a-z]{1,})$/;
	if(!patrn.exec(s)) return false;
	return true;
}
//****************************************************************************
//Check the email's format
//example: if(!is_email(str)) { error }
//****************************************************************************
function is_email(s) 
{
	var patrn = /^([a-zA-Z0-9]+[_|\-|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(!patrn.exec(s)) return false;
	return true;
}

//****************************************************************************
//Check the date's format
//****************************************************************************
function ToDateFromString(strDate)
{  
	if   (strDate.length   !=   8){  
		return   null   ;  
	} 
		var dtDate =   null   ;  
		var nYear =   parseInt(   strDate.substring(   0,   4   ),   10   )   ;  
		var nMonth =   parseInt(   strDate.substring(   4,   6   ),   10   )   ;  
		var nDay =   parseInt(   strDate.substring(   6,   8   ),   10   )   ;  

	if(   isNaN(   nYear   )   ==   true   ||   isNaN(   nMonth   )   ==   true   ||   isNaN(   nDay   )   ==   true   )  
	{  
		return null   ;  
	}
		dtDate =   new   Date(   nYear,   nMonth   -   1,   nDay   )   ;  

	if(   nYear   !=   dtDate.getFullYear()   ||   (   nMonth   -   1   )   !=   dtDate.getMonth()   ||   nDay   !=   dtDate.getDate()   )  
	{  
		return null   ;  
	}  

	return dtDate   ;  
}

//****************************************************************************
//Check the age if more then limit number
//****************************************************************************

function GetAge(birthdayY , birthdayM , birthdayD , Limit)
{
	var today = new Date();
	var currentDay = today.getDate();
	var currentMonth = today.getMonth() + 1;
	var currentYear = today.getFullYear();
	var YearD = parseInt(currentYear) - parseInt(birthdayY);
	if(YearD < Limit)
	{
		return false;
	}else if (YearD == Limit)
	{
		if(parseInt(currentMonth,10) > parseInt(birthdayM,10))
		{
			return true;
		}else if(parseInt(currentMonth,10) == parseInt(birthdayM,10))
		{
			if(parseInt(currentDay,10) >= parseInt(birthdayD,10))
			{
				return true;
			}else
			{
				return false;
			}
		}
	}else
	{
		return true;
	}
}

//****************************************************************************
//Switch the URL between https and http
//****************************************************************************
function switchHttp(param)
{
	/*
	var theURL = location.pathname + location.search;	
	var splitArray = location.href.split(":");
	var httpdomain = "http://test.thesingleton.com";
	var httpsdomain = "https://secure.test.thesingleton.com";
	
	if(splitArray[0] != param)
	{
		switch (param)
		{
			case "http":
				location.href = httpdomain + theURL;
				break;
			case "https":					
				location.href = httpsdomain + theURL;
				break;
		}
	}
	*/
	
}
//****************************************************************************
//onclick for bookmark
//****************************************************************************
function saveBookmark()
{
	var sURL = document.location.href;
	var sTitle = document.title;
	if (document.all)
	{
	  window.external.addFavorite(sURL, sTitle);
	}
	else if (window.sidebar)
	{
	  window.sidebar.addPanel(sTitle, sURL, "");
	}
	return false;

}
/****************************
function : urlencode 
*****************************/
function UrlEncode(str){ 
  var ret=""; 
  var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%"; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    var c=escape(chr); 
      if(chr==" ") 
        ret+="+"; 
      else if(strSpecial.indexOf(chr)!=-1) 
        ret+=c.toString(16); 
      else 
        ret+=chr; 

  } 
  return ret; 
} 
function UrlDecode(str){ 
  var ret=""; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    if(chr == "+"){ 
      ret+=" "; 
    }else if(chr=="%"){ 
     var asc = str.substring(i,i+3); 
      ret+=unescape(asc); 
      i+=2; 
    }else{ 
      ret+= chr; 
    } 
  } 
  return ret; 
}
