function setCookie(name, value, expire)
{
   document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + ";path=/";
}

function getCookie(Name) {
   var search, result;
   result = "";
   if (document.cookie.length > 0) { // if there are any cookies
      var cookies = document.cookie.split(";");
      for (i=0; i < cookies.length;i++) {
         search = unescape(escape(cookies[i]).replace("%20",""));
         if (search.substring(0,search.indexOf("=")) == Name)
         {
            result = cookies[i].substring(cookies[i].indexOf("=")+1,cookies[i].length);
            break;
         }
      }
      return result;
   }
}

function TRIM(str)
{
   str = LTRIM(str);
   str = RTRIM(str);
   return str;
}

function LTRIM(str)
{
   var re = /\s+$/;
   return str.replace(re,"");
}

function RTRIM(str)
{
   var re = /\{2,}/;
   str = str.replace(re," ");
   return str;
}

function validatepwd(name,newpwd)
{
   var msg = "";
   if (newpwd.length < 5)
   {
      msg = "Password must have a minimum length of at least 5 characters";
   }
   else if (name == newpwd)
   {
      msg = "Password can't be the same as username.";
   }
   else if (name == rev(newpwd))
   {
      msg = "Password can't be reversed username.";
   }
   if (!formatcheck(newpwd))
   {
      msg = "Password must contain at least one alphabetic and one numeric.";
   }
   else {
      if (!identicalcheck(newpwd))
      {
         msg = "Password can't contain a string of three consecutive identical characters.";
      }
   }
   return msg;
}

function rev(org_text)
{
   var text= org_text;

   var backwards="";

   for(count=text.length; count >= 0; count--)

      backwards+=text.substring(count,count-1);

      return backwards;
}

function numbercheck(objText, isIntOnly)
{
   var inputExpInt = /[1234567890]/;
   var inputExpNum = /[1234567890.]/;
   var isNum = false;
   var doc_count = 0;
   if (TRIM(objText.value) != "")
   {
		var strPass = objText.value;
		var strLength = strPass.length;
		if (isIntOnly)
		{
				for (var i=1; i < strLength + 1; i++)
				{
					var lchar = objText.value.charAt((strLength) - i);
					if((lchar.search(inputExpInt) != -1)) {
						isNum = true;     
					}
					else {
						isNum = false;
						break;
					}
				}
		}
		else {
				for (var i=1; i < strLength + 1; i++)
				{
					var lchar = objText.value.charAt((strLength) - i);
					if((lchar.search(inputExpNum) != -1)) {
						isNum = true;   
						if (lchar == ".")
						{
							doc_count = doc_count + 1;
						}  
						if (doc_count > 1)
						{
							isNum = false;
							break;
						}
					}
					else {
						isNum = false;
						break;
					}
				}
		}
	}
	else {
		isNum = true;
	}
	if (!isNum)
	{
		objText.focus();
	}
}

function isANumber(obj)
{
   var re  = /\,/g;
   var re1 = /\ /g;
   var str = "";
   var str1 = "";
   var count = 0;
   var val = obj.value;
   val = val.replace(re, '');
   val = val.replace(re1, '');
   var i_decimal = "";
   if (val.indexOf(".") != -1)
   {
		i_decimal = val.substr(val.indexOf("."), val.length - val.indexOf("."))
		val = val.substr(0,val.indexOf("."))
   }
   
   var strLength = val.length;
   for (var i=1; i < strLength + 1; i++)
   {
      var lchar = val.charAt((strLength) - i);
      if (lchar.search(inputExp) == -1) {
        if (i !=1 && lchar == '.') {
			if (str1 == "") {
				str = lchar + str;
			}
			else {
				var len = str.length;
				if (len <= str1.length) {
					str1 = "," + str + str1.substr(str.length+1,str1.length);
					str = "";
				}
			}
			count = 0;
        }
        else {
	        obj.focus();
		    break;
        }
      }
      else {
         if (count > 2) {
            str =  lchar + ','  + str;
            count = 0;
         }
         else {
            str = lchar + str;
         }
         count = count + 1;
      }
   }
   if (str == "") {
      obj.value = str1.substr(1,str1.length) + i_decimal;
   }
   else {
      obj.value = str + str1 + i_decimal;
   }
}

function formatcheck(objText) {

   var inputExpNum = /[1234567890]/;
   var inputExpAlph = /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/;
   var isNum = false;
   var isAlph = false;
   var strPass = objText;
   var strLength = strPass.length;
   for (var i=1; i < strLength + 1; i++)
   {
      var lchar = objText.charAt((strLength) - i);
      if((lchar.search(inputExpNum) != -1)) {
         isNum = true;     
      }
      if((lchar.search(inputExpAlph) != -1)) {
         isAlph = true;     
      }
   }
   if (isNum && isAlph)
   {
      return true;
   }
   else {
      return false;
   }
}

function identicalcheck(objText)
{
   var strPass = objText;
   var strLength = strPass.length;
   var strText = objText.charAt((strLength) - 1)
   var icount = 0;
   for (var i=1; i < strLength + 1; i++)
   {
      if (icount >= 2)
      {
         break;
      }
      var lchar = objText.charAt((strLength) - i);
      if(lchar.toLowerCase() == strText.toLowerCase() && i !=1) {
         icount = icount + 1;     
      }
      else {
         strText = lchar;
         icount = 0;
      }
   }
   if (icount >= 2)
   {
      return false;
   }
   else {
      return true;
   }
}

function showcalendar1(obj)
{
   var cal = obj.nextSibling.nextSibling;
   var html = cal.innerHTML;
   var strobj = "";
   var hfield = "";
   var othobj;
   if (html.indexOf("idCalendar") != -1)
   {
		strobj = html.substring(html.indexOf("$idCalendar"),html.indexOf("__doPostBack('") + 14);
   }

   if (cal.className == "hide")
   {
		var divs = document.getElementsByTagName('div');
		for (var loop=0; loop<divs.length; loop++) 
		{
			if (divs[loop].id = 'idCalendar')
			{
				divs[loop].className = 'hide';
			}
		}
		cal.className="show";
		hfield.value = strobj;
   }
   else
   {
		cal.className="hide";
		hfield.value = "";
   }   
}
function clearTextField(text_name)
{
	var objText = document.getElementById(text_name);
	objText.value = "";
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function emaillink(str) {
   var email2 = "bankofny.com"; 

   document.write("<a href=" + "mail" + "to:" + str + "@" + email2 + ">" + str + "@" + email2 + "</a>") 
}

function GetValue(param)
{  
    var xmlHttp, str;
    try
    {    
        // Firefox, Opera 8.0+, Safari    
        xmlHttp=new XMLHttpRequest();    
    }
    catch (e)
    {    
        // Internet Explorer    
        try
        {      
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
        }
        catch (e)
        {      
            try
            {        
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
            }
            catch (e)
            {        
                try
                {        
                    xmlHttp=new ActiveXObject("MSXML2.XMLHttp.5.0");        
                }
                catch (e)
                {        
                    try
                    {        
                        xmlHttp=new ActiveXObject("MSXML2.XMLHttp.4.0");        
                    }
                    catch (e)
                    {        
                        try
                        {        
                            xmlHttp=new ActiveXObject("MSXML2.XMLHttp.3.0");        
                        }
                        catch (e)
                        {        
                            alert("Your browser does not support AJAX!");        
                            str = "";
                        }
                    }
                }        
            }      
        }
    }  
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            str = xmlHttp.responseText;
        }
    }
    xmlHttp.open("GET","ajaxreturn.aspx?name="+param,true);
    xmlHttp.send(null);
}

function launchapplet(type)
{
     var appletFrame = top.document.getElementById("bottomFrame");
     top.string1 = top.footerFrame.document.forms[0].val1.value;
     top.string2 = top.footerFrame.document.forms[0].val2.value;
     var url= "";
     if (type == "poms")
     {
         url=document.location.protocol+"//"+document.location.hostname+"/Poms2/PomsApplet.aspx";
     }
     else if (type == "pomsadmin")
     {
         url=document.location.protocol+"//"+document.location.hostname+"/Poms2/POMSFundAdminApplet.aspx";
     }
     else if (type == 'trader')
     {
        url=document.location.protocol+"//"+document.location.hostname+"/GID2/TraderApplet.aspx";
     }
     else if (type == 'gid')
     {
        url=document.location.protocol+"//"+document.location.hostname+"/GID2/ClientApplet.aspx";
     }
     else if (type == 'gidsysadmin')
     {
        url=document.location.protocol+"//"+document.location.hostname+"/GID2/GIDAdminApplet.aspx";
     }
     else if (type == 'pomssysadmin')
     {
        url=document.location.protocol+"//"+document.location.hostname+"/Poms2/POMSSysAdminApplet.aspx";
     }
     appletFrame.src = url;
}
