String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function getOs()   
{   
   var OsObject = "";   
   if(navigator.userAgent.indexOf("MSIE")>0) {   
        return "MSIE";       //IE
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){   
        return "Firefox";     //Firefox
   }
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {   
        return "Safari";      //Safan
   }
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){   
        return "Camino";   //Camino
   }
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){   
        return "Gecko";    //Gecko
   }   
} 

function checkIsNaturalNumber(obj)
{
	var s = obj;
	if(/^[0-9]+$/.test(s) && (s > 0))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function   strDateTime(str)
{
	if(strDate(str))
	{
			return true;
	}
	else
	{
		var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;     
		var r = str.match(reg);     
		if(r==null)
			return   false;     
		var d = new Date(r[1],r[3]-1,r[4],r[5],r[6],r[7]);     
		var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()   
        return newStr==str;
	}
}  

function strDate(str)
{
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;     
	var r = str.match(reg);     
	if(r==null)
		return   false;     
	var d = new Date(r[1],r[3]-1,r[4]);     
	var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate();   
	return newStr==str;   
}

function isEmail(str)
{
	var pattern=/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$/;
	if (str.match(pattern))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function CheckIsHttp(Inputname){ 
    if (Inputname == "")return false; 
    else{
   if(Inputname.search(/^http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/)==-1) 
         {
             return false; 
              } 
      else{ 
              return true; 
         } 
      } 
} 

function GetFileExt(str)
{
	if(str.indexOf("."))
	{
		return str.substring(str.lastIndexOf(".")).toLowerCase();
	}
}

function   isDate(s)
{   
	var   re   =   /^(\d{4})(\/|-)(\d{1,2})\2(\d{1,2})$/   ;
	var   m   =   re.exec(s);   
	if   (m   ==   null)   return   false;   
	var   d   =   new   Date(m[1],m[3]-1,m[4]);   
	return   d.getFullYear()==m[1]   &&   d.getMonth()==(m[3]-1)   &&   d.getDate()==m[4];   
}  

function isWorldPhone(str)
{
	var pattern=/\d{2}-\d{2,3}-\d{7,8}/;
	if (str.match(pattern))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkDate(dStr)
{
 dStr=dStr.replace(/-/g,"/")
 if(new Date(dStr).toString()=="NaN")return false;
 else return true;
}

function setCookie(theKey, theValue, expireHours)
{
	cookieString = theKey+"="+theValue+"; expire="+expireHours*3600*1000;

	document.cookie = cookieString;
}

function getCookie(theKey)
{
	// alert(theKey);
	theCookie = document.cookie;

	theValueArray = theCookie.split("; ");

	for(var i=0; i<theValueArray.length; i++)
	{
		if(theKey == (theValueArray[i].split("=")[0]))
		{
			return unescape(theValueArray[i].split("=")[1]);
			break;
		}
		if(i==theValueArray.length-1)
		{
			return "";
		}
	}
}

function replaceTwoUnderline(str)
{
	if(str.indexOf("--") != -1)
	{
		return replaceTwoUnderline(str.replace("--", "-"));
	}
	else
	{
		return str;
	}
}

function generateFileName(str)
{
	if(str != "")
	{
		re_str = "";
		//str = getSpell(str);
		str = str.replace("  ", " ");
		str = str.trim();
		for(var i=0;i<str.length;i++)
		{
			if(
				(str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) 
				|| 
				(str.charCodeAt(i) >=65 && str.charCodeAt(i) <=90) 
				|| 
				(str.charCodeAt(i) >=97 && str.charCodeAt(i) <=122)
			)
			{
				re_str += str.charAt(i).toLowerCase();
			}
			else
			{
				re_str += "-";
			}
		}
		re_str = replaceTwoUnderline(re_str);
		return (re_str).replace("-.",".");
	}
	else
	{
		return '';
	}
}

function replaceTwoBlank(str)
{
	if(str.indexOf("  ") != -1)
	{
		return replaceTwoUnderline(str.replace("  ", " "));
	}
	else
	{
		return str;
	}
}

function generateFolderName(str)
{
	if(str != "")
	{
		re_str = "";
		//str = getSpell(str);
		str = str.replace("  ", " ");
		str = str.trim();
		for(var i=0;i<str.length;i++)
		{
			if(
				(str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) 
				|| 
				(str.charCodeAt(i) >=65 && str.charCodeAt(i) <=90) 
				|| 
				(str.charCodeAt(i) >=97 && str.charCodeAt(i) <=122)
			)
			{
				re_str += str.charAt(i).toLowerCase();
			}
			else
			{
				re_str += "-";
			}
		}
		re_str = replaceTwoBlank(re_str);
		return (re_str).replace("--","-");
	}
	else
	{
		return '';
	}
}