﻿function GetTimeZone(){
    var ndate = new Date();
    return 0 - ndate.getTimezoneOffset();
}


function HTMLEnCode(str)   
{   
     var s = "";   
     if (str.length == 0) return "";   
     s = str.replace(/&/g, "&gt;");   
     s = s.replace(/</g, "&lt;");   
     s = s.replace(/>/g, "&gt;");   
     s = s.replace(/ /g, "&nbsp;");   
     s = s.replace(/\'/g, "&#39;");   
     s = s.replace(/\"/g, "&quot;");   
     s = s.replace(/\n/g, "<br>");   
     return s;   
} 

function HTMLDeCode(str)   
{   
     var s = "";   
     if (str.length == 0) return "";   
     s = str.replace(/&gt;/g, "&");   
     s = s.replace(/&lt;/g, "<");   
     s = s.replace(/&gt;/g, ">");   
     s = s.replace(/&nbsp;/g, " ");   
     s = s.replace(/&#39;/g, "\'");   
     s = s.replace(/&quot;/g, "\"");   
     s = s.replace(/<br>/g, "\n");   
     return s;   
} 

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+1,i+3); 
            if(parseInt("0x"+asc)>0x7f)
            { 
                ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
                i+=5; 
            }
            else
            { 
                ret+=asc2str(parseInt("0x"+asc)); 
                i+=2; 
            } 
        }
        else
        { 
            ret+= chr; 
        } 
    } 
    return ret; 
} 

function getCurTime()
{
  var now = new Date();
  var year = now.getYear();
  var month = now.getMonth()+1;
  var day = now.getDate();
  var hour = now.getHours();

  var minute = now.getMinutes();
  var second = now.getSeconds();

  if(minute<10)
  {
    minute = "0" + minute;
  }
  if(second<10)
  {
    second = "0" + second;
  }

  var time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

  return time;
}
function detectBrowser()
{ 
  var ret = "ie6"; // default 
  var user_agent = navigator.userAgent; 
  if(user_agent.indexOf("compatible")>-1)
  {
    if(user_agent.indexOf("MSIE 6.0") > -1)
    {
      ret = "ie6";
    }
    else if(user_agent.indexOf("MSIE 7.0") > -1)
    {
      ret = "ie7";
    }
    else if(user_agent.indexOf("MSIE 8.0") > -1)
    {
      ret = "ie8";
    }
  }
  else if(user_agent.indexOf("Gecko") > -1)
  {
    ret = "firefox";
  }

  return ret;
}

function getStringField(str,deli,pos) {
	arr=str.split(deli);
	if (arr.length>=pos) {
    return arr[pos-1];
  } else {
    return "";
  }
}
Array.prototype.search = function(value)
{
  re = new RegExp(value,[""]);
  return (this.toString().replace(re,"┢").replace(/[^,┢]/g,"")).indexOf("┢");
}

function getTime(){
    var nowtime=new Date();
	var hour=nowtime.getHours();
	if(hour<10)
		hour="0"+hour;
	var minute=nowtime.getMinutes();
	if(minute<10)
		minute="0"+minute;
	var second=nowtime.getSeconds();
	if(second<10)
		second="0"+second;
	var now=hour+':'+minute+':'+second;
    return now;
}

function getDate(){
    var nowtime=new Date();
	var y=nowtime.getFullYear();
	var m=nowtime.getMonth()+1;
	var d=nowtime.getDate();
	var date=y+'-'+m+'-'+d;
    return date;
}

function getDateTime(){ 
 	return(getDate()+' '+getTime());
}

function nowTime(){
    var now=new Date();
    return now.getTime();
}
