// Trim Function 

String.prototype.trim=function()
{
return this.replace(/^\s*(\b.*\b|)\s*$/,"$1");
}


// Numeric Function

function IsNumeric(strString) 
{ 
	var strValidChars = "0123456789"; // these are alloable chars
	var strChar; 
	var blnResult = true; 
	if (strString.length == 0) return false; 
	for (i = 0; i < strString.length && blnResult == true; i++) 
		{ 
			strChar = strString.charAt(i); 
			if (strValidChars.indexOf(strChar) == -1) 
				{ 
					blnResult = false; 
				} 
		} 
	return blnResult; 
}


// Can  Except decimal values
function IsNumericDecimal(strString) 
{ 
	var strValidChars = "0123456789."; // these are alloable chars
	var strChar; 
	var blnResult = true; 
	if (strString.length == 0) return false; 
	for (i = 0; i < strString.length && blnResult == true; i++) 
		{ 
			strChar = strString.charAt(i); 
			if (strValidChars.indexOf(strChar) == -1) 
				{ 
					blnResult = false; 
				} 
		} 
	return blnResult; 
}



// Email Address Validation

function Validate_String(string, return_invalid_chars)
         {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, $last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }


function isValidEmail(email_address,ss)
         {
         //Assumes that valid email addresses consist of user_name@domain.tld
         at = email_address.indexOf('@');
         dot = email_address.indexOf('.');
         
         if(at == -1 || 
            dot == -1 || 
            dot <= at + 1 ||
            dot == 0 || 
            dot == email_address.length - 1)
            return(false);
            
         user_name = email_address.substr(0, at);
         domain_name = email_address.substr(at + 1, email_address.length);                  
         
         if(Validate_String(user_name) === false || 
            Validate_String(domain_name) === false)
            return(false);                     
         
         return(true);
         }

// Days Between Function in JS
function days_between(date1, date2) 
{

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = (date1_ms - date2_ms)
   // alert(date1_ms);
	   // alert(date2_ms);
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}

// Popup JS
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Scrolling functions 
function scrollObject(objName, main, width, height, bkgcol, direct, deccel, begin, speed, pause, classname) 
{
			  this.objName = objName;
			  this.main = main;
			  this.one = main + "Block1";
			  this.two = main + "Block2";
			  this.block = new Array();
			  this.blockup = 1;
			  this.divup = 1;
			  this.height = height;
			  this.width = width;
			  this.bkgcol = bkgcol;
			  this.direct = direct;
			  this.deccel = Math.max(deccel, 1);
			  this.begin = Math.max(Math.min(begin, (direct == "up" || direct == "down") ? height : width), 1);
			  this.speed = speed;
			  this.pause = pause;
			  this.slide = ((direct == "up" || direct == "down") ? height : width) / this.begin;
			  this.table = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td class=\"" + classname + "\" style=\"width:" + width + "px;height:" + height + "px;\">";
			  this.scroll = scroll;
			  this.scrollLoop = scrollLoop;
}

function scroll() 
{
	if (!document.getElementById) return false;
	  document.getElementById(this.main).innerHTML = "<div id=\"" + this.one + "\"></div><div id=\"" + this.two + "\"></div>";
	  var divList = [document.getElementById(this.main), document.getElementById(this.one), document.getElementById(this.two)];
	  for (var i = 0; i <= 2; i++) {
		if (i > 0) 
		{
		  divList[i].style.position = "absolute";
		  if (this.direct == "up" || this.direct == "down") {
			divList[i].style.left = "0px";
			divList[i].style.top = (i == 1) ? "0px" : ((this.direct == "up") ? "" : "-") + this.height + "px";
		  } else {
			divList[i].style.left = (i == 1) ? "0px" : ((this.direct == "left") ? "" : "-") + this.width + "px";
			divList[i].style.top = "0px";
		  } divList[i].innerHTML = this.table + this.block[i - 1] + "</td></tr></table>";
		} else {
		  divList[i].style.position = "relative";
		  divList[i].style.background = this.bkgcol;
		}
		divList[i].style.width = this.width + "px";
		divList[i].style.height = this.height + "px";
		divList[i].style.overflow = "hidden";
	  } setTimeout(this.objName + ".scrollLoop();", this.pause);
}

function scrollLoop() 
{
  var divList = [document.getElementById(this.main), document.getElementById(this.one), document.getElementById(this.two)];
  this.slide = Math.max(this.slide / this.deccel, 1);
  var slideInc = (this.direct == "up" || this.direct == "left") ? -parseInt(this.slide) : parseInt(this.slide);
  if ((this.direct == "up" && Math.max(parseInt(divList[1].style.top) + slideInc, parseInt(divList[2].style.top) + slideInc) <= 0) ||
      (this.direct == "down" && Math.min(parseInt(divList[1].style.top) + slideInc, parseInt(divList[2].style.top) + slideInc) >= 0) ||
      (this.direct == "left" && Math.max(parseInt(divList[1].style.left) + slideInc, parseInt(divList[2].style.left) + slideInc) <= 0) ||
      (this.direct == "right" && Math.min(parseInt(divList[1].style.left) + slideInc, parseInt(divList[2].style.left) + slideInc) >= 0)) {
    this.slide = ((this.direct == "up" || this.direct == "down") ? this.height : this.width) / this.begin;
    if (++this.blockup >= this.block.length) this.blockup = 0;
    this.divup = (this.divup == 1) ? 2 : 1;
    if (this.direct == "up" || this.direct == "down") {
      divList[3 - this.divup].style.top = ((this.direct == "down") ? "-" : "") + this.height + "px";
      divList[this.divup].style.top = "0px";
    } else {
      divList[3 - this.divup].style.left = ((this.direct == "right") ? "-" : "") + this.width + "px";
      divList[this.divup].style.left = "0px";
    } divList[3 - this.divup].innerHTML = this.table + this.block[this.blockup] + "</td></tr></table>";
    setTimeout(this.objName + ".scrollLoop();", this.pause);
  } else {
    for (var j = 1; j <= 2; j++) {
      if (this.direct == "up" || this.direct == "down") {
        divList[j].style.top = (parseInt(divList[j].style.top) + slideInc) + "px";
      } else divList[j].style.left = (parseInt(divList[j].style.left) + slideInc) + "px";
    } setTimeout(this.objName + ".scrollLoop();", this.speed);
  }
}

