﻿// JScript File
// <summary>
/// <Author				    : Raman Singh       >
///	<Start Date				: 29 August 2008    >
///	<End Date				: 29 August 2008    >
///	<Description			: This file contains common useful methods and Prototype which applied on some object 
///                           whenever this JS loaded  >
///	<Modified Date			: - >
///	<Modified By			: - >
///	<Purpose				: - >
/// </summary>
String.prototype.trim = function () {
  return this.replace(/(^\s+)|(\s+$)/g,'')
}
String.prototype.isEmpty = function () {
  if (!this.length) return true
  if (this.match(/^\s+$/)) return true
  return false
}
String.prototype.truncate = function  (length) {
  if (this.length > length) {
    var truncated = this.substr(0, length - 3);
    truncated = truncated.replace(/[^\w]*[\w]*$/, "...");
    if (truncated.length < 20) truncated = this.substr(0, length - 3)+"...";
    return truncated;
  } 
  else {
    return this;
  }
}
RegExp.prototype.toString = function () {return this.source}
RegExp.EMAIL = /^([\w-_]+\.)*[\w-_]+\@([\w-_]+\.)+[a-zA-Z]{2,12}$/;

String.prototype.isEmail = function () {
  if (this.match(RegExp.EMAIL)) return true
}

//Added By : karuna
//Added On :17/09/2008
//Reason   : To check password length
String.prototype.isPassword = function () {
  if (this.length >= 8) return true
}

//Added By : karuna
//Added On :17/09/2008
//Reason   : To open a popup window
function wopen(url, name, w, h)
{
   window.open(url,null,'width=' + w + ', height=' + h + ', '+'location=no, menubar=no,status=no, toolbar=no, scrollbars=no, resizable=no,minimize=no');
}


//Added By : karuna
//Added On :17/09/2008
//Reason   : To hide and show the description div
function HideShowPanel(obj)
{
    var objDiv = document.getElementById(obj);
    if(objDiv.style.display == "none")
    {
        objDiv.style.display='block';
    }
    else
    {
        objDiv.style.display='none';
    }
}
 
    
    function ValidateControls(obj, type)
    {
        var objClientName = obj.id.split('_')[obj.id.split('_').length-1 ]; 
        var labelObj = document.getElementById("LBL" + objClientName); 
        var flag = false;
        
  
        if(obj.value.toString().isEmpty() && type != 'password' && type !='confirm')
        {
           obj.className = "errorBox";
           labelObj.innerText = "(Required field)";
           labelObj.style.display="inline";
           flag = false;
        }
        else
        {
           obj.className = "NormalText";
           labelObj.style.display="none"
           flag = true;
        }

        if( flag &&  type == 'email')
        {
           if(!obj.value.toString().isEmail())
           {
                obj.className = "errorBox";
                labelObj.style.display="inline"
                labelObj.innerText = "(Invalid email id)";
                flag = false; 
           }
        }

        if(flag &&  type == 'phone')
        {
           if(isNaN(obj.value.toString()))
           {
                obj.className = "errorBox";
                labelObj.style.display="inline"
                labelObj.innerText = "(Invalid phone number)";
                flag = false; 
           }
        } 
        
        if( flag &&  type == 'password')
        {
            if(isNaN(obj.value.isPassword()))
            {
                obj.className = "errorBox";
                labelObj.style.display="inline"
                labelObj.innerText = "(Invalid password)";
                flag = false; 
            }
        } 
        
        
         
        
        return flag;
    }

    
    

    
 