function CreateLookup(url,width,height) {
var mywin;
mywin =window.open(url,"newwin","width="+width+",height="+height+",scrollbars=1");
mywin.focus();
}

function IsValidPhone(PhoneN)
{
    var phoneRE = /^\d{3}-\d{3}-\d{4}$/; 
    return PhoneN.match(phoneRE);  
}


function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function TrimValue(fieldName, fieldValue)

{

 

 

//var valueToPreserve;

//valueToPreserve = pastvalue

var s = new String(fieldValue);

var str = ""

var strSpace = " ";

var i,j,intCount;

//Trimming of Text Values

//to replace the enter pressed with space

      for(intCount=0;intCount<s.length;intCount++)

            if (!((s.charCodeAt(intCount)!=13) && (s.charCodeAt(intCount)!=10)))

            s=s.replace(s.charAt(intCount)," ");

                  for (i=0;i<s.length && s.charAt(i) == strSpace;i++);

                        for (j=s.length; j>=0 && s.charAt(j - 1) == strSpace; j--);

                              for (;i<j;i++)

                              str = str + s.charAt(i);

 

 

      //Replacing blank value with pastvalue

      if (str=="")

      {

      alert("Blank values are not allowed");

      //fieldName.value = valueToPreserve;

      fieldName.select();

      fieldName.focus();    

      return false;

      }

      //Else put the Trimmed value 

      else

      {

      fieldName.value = str;

      return true

      }

}


// JavaScript Document//Common Js for all Pages goes here
 function checkLength(obj,Length,displayName,FixLength)
 {
   var objValue;
   var fldLength=parseInt(Length);
  objValue= trim(obj.value);
  
  if (objValue.length!=Length && FixLength==true)
  {
     alert(displayName+ ' should have '+ Length +' chars');
       return false;
        
  }
  else if (FixLength==false && objValue.length>Length)
  {
        alert(displayName+ ' can have Max '+ Length +' chars');
        return false;
  }
  return true;
 }

function isBlank(obj,displayName)

{

      if(obj != null)
      {
          var str="";
          

          str= trim(obj.value);

          var len=str.length;

          var i;

          for(i=0;i<len;++i)

          {

                if(str.charAt(i)!=" ")

                {

                      return false;

                }

          }

          alert(displayName+" cannot be left blank");

          obj.focus();

          return true;
      }

}

 

 

 

function isNumber(obj,displayName)

{

    if(obj != null)
    {
    
          var str= trim (obj.value);

          for(i=0;i<str.length;i++)

          {

                if(str.charAt(i)<'0'||str.charAt(i)>'9')

                {     

                      if((str.charAt(0))=="-")

                      {

                            i=i+1;

                                  continue;

                      }

                      alert(displayName+" should be numeric.");

                      obj.focus();

                      return true;

                }

          }
          return false;

      }

      
} 

 
//purpose ... to check value of a variable
function isNumberValue(numvalue,displayName)
{


      var str= numvalue;
      //  alert(numvalue.length);
      for(i=0;i<str.length;i++)
      {
            alert(numvalue.charAt(i));
            if(str.charAt(i)<'0'||str.charAt(i)>'9')

            {     
                alert('In if');
                  if((str.charAt(0))=="-")

                  {

                        i=i+1;

                              continue;

                  }

                  alert(displayName+" should be numeric.");
                  return true;

            }

      }

      return false;

} 



function hasNoSplChars(obj,displayName)
{

    if(obj != null)
    {
      var user_text="";
      var quot="'";
      var spchar="";
      user_text=trim(obj.value);
      splChars=new Array('?','!','@','#','$','%','^','&','*',':',';','<','>',quot,'"','(',')','[',']','{','}');
      for(i=0;i<user_text.length;i++)
      {
            for(j=0;j<splChars.length;j++)
            {
                  if(user_text.charAt(i)==splChars[j])
                  {
                  spchar = spchar + splChars[j] + " ";
                   alert(displayName+" can not contain characters like " + spchar );
                   obj.focus();
                   return false;
                  }
            }
      }
      return true;
      //return false;
      }
}     


//purpose..to allow user any special char
function allowSplChar(obj,displayName,splChar)
{
      var user_text="";
      var quot="'";
      user_text=trim(obj.value);
      splChars=new Array('!','@','#','$','%','^','&','*',':',';','<','>',quot,'"','(',')','[',']','{','}');
      for(i=0;i<user_text.length;i++)
      {
            if(user_text.charAt(i)!= splChar)
            {
                for(j=0;j<splChars.length;j++)
                {
                      if(user_text.charAt(i)==splChars[j])
                      {
                        alert("Only special char " + splChar + " is allowed in " + displayName );
                        obj.focus();
                        return false;
                      }
                }
            }
      }
      return true;
} 


//purpose ... to count the occurrence of specail char
function numOccurrence(obj,splChar)
{
    var user_text="";
    var occur=0;
    user_text=trim(obj.value);
            for(i=0;i<user_text.length;i++)
            {
                if(user_text.charAt(i)== splChar)
                {
                    occur = occur + 1;
                }
            }
    return occur;
}
 
 

function isDDMMYYYYDate(objFormField)

{

      var lsFieldVal = objFormField.value;

      var lsFieldLength = lsFieldVal.length;

      var thirdchar = lsFieldVal.substring(2,3);

      var sixthchar = lsFieldVal.substring(5,6);

      var separator = '-';

      if    (

            (lsFieldLength == 10) &&

            (thirdchar == separator) &&

            (sixthchar == separator)

            )

            {

            //split the chars

            var liDayPart

            var liMonthPart

            var liYearPart

      /*    if (lsFieldVal.substr(0,1) == 0)

                  liDayPart = parseInt(lsFieldVal.substr(1,2));

            else

                  liDayPart = parseInt(lsFieldVal.substr(0,2));

 

            if (lsFieldVal.substring(3,4) == 0)

                  liMonthPart = parseInt(lsFieldVal.substring(4,5));

            else

                  liMonthPart = parseInt(lsFieldVal.substring(3,5));*/

 

        if (lsFieldVal.substr(0,1) == 0)

                  liMonthPart= parseInt(lsFieldVal.substr(1,2));

            else

                  liMonthPart = parseInt(lsFieldVal.substr(0,2));

 

            if (lsFieldVal.substring(3,4) == 0)

                  liDayPart = parseInt(lsFieldVal.substring(4,5));

            else

                  liDayPart = parseInt(lsFieldVal.substring(3,5));

            liYearPart = parseInt(lsFieldVal.substring(6,10));

 

            //check overall validity

            if (

                  (liDayPart >= 1) &&

                  (liDayPart <= 31) &&

                  (liMonthPart >= 1) &&

                  (liMonthPart <= 12) &&

                  (liYearPart >= 1999) &&

                  (liYearPart <= 2050)

                  )

                  {

                  //check for 30-day months

                  if (

                        (liMonthPart==4) ||

                        (liMonthPart==6) ||

                        (liMonthPart==9) ||

                        (liMonthPart==11) 

                        )

                        {

                        if ( liDayPart <= 30)

                              {

                              retval = true;

                              }

                        else

                              {

                              retval = false;

                              }

                        }

                  else  //not a 30-day month

                        {

                        //if february

                        if (liMonthPart == 2)

                              {

                              //check for leap year

                              if ( (liYearPart % 4) != 0) 

                                    {

                                    liFebDays = 28;

                                    }

                              else

                                    {

                                    if ((liYearPart % 400) == 0)

                                          {

                                          liFebDays = 29;

                                          }

                                    else

                                          {

                                          if ((liYearPart % 100) ==0)

                                                {

                                                liFebDays = 28;

                                                }

                                          else

                                                {

                                                liFebDays = 29;

                                                }

                                          }

                                    }

 

                              if (liDayPart <= liFebDays)

                                    {

                                    retval = true;

                                    }

                              else

                                    {

                                    retval = false;

                                    }

                              }

                        else  //31-day month

                              {

                              retval = true;

                              }

                        }

                  }

            else

                  {

                        retval = false;

                  }

            }

      else

            {

            retval = false;

            }

 

      return retval;

}

 

 

function trim(string)

{

      return string.replace(/^\s*|\s*$/g,"");

} 

 

 

      function showLength(field, countfield,maxLimit) 

      {                 

                  //setting the limit of the textarea to 500

                  if (field.value.length > maxLimit) // if too long...trim it!

                        field.value = field.value.substring(0, maxLimit);

                  // otherwise, update 'characters left' counter

                  else 

                        if (document.all)

                              {eval(countfield).innerText =  field.value.length;}

                              else

                              

                              {                                   

                                    var strCtrlName = new String();

                                    var strtmp = new String();

                                    strCtrlName = countfield;

                                    strtmp = strCtrlName.substr(strCtrlName.lastIndexOf(".")+1,strCtrlName.length - strCtrlName.lastIndexOf("."));      

                                    document.getElementById(strtmp).innerHTML = field.value.length;

                              }

                              

      }

      

      function OnLoadshowLength(field1,field2)

      {

                  var str = new String();

                  str = field1;

                        eval(field2).innerText = str.length ;

      }     

 

function validateKeys(e,act){

if (document.layers)

     Key = "e.which";

else

     Key = "window.event.keyCode";

switch(act) {

   case "alpha":re = /[^a-z]+/i;break;

   case "numeric":re = /[^0-9]+/i;break;

   case "alphanumeric":re = /[^a-z0-9]+/i;break;

   case "Floating":re = /[^0-9.]+/i;break; 

   }

if(re.test(eval("String.fromCharCode("+Key+")")))    

    if((eval(Key))!=32)

    {

    eval(Key+"=null")

   }

}

function isNumeric(fieldValue)

{

      var num = '0123456789';

      

      var i,j,found;

      found = false;

      

      for(i=0;i<fieldValue.length;i++)

      {

            for(j=0;j<num.length;j++)

            {

                  if(fieldValue.charAt(i) == num.charAt(j))

                  {

                        found = true; break;

                  }

            }

            if(found == false) {return false;}

            if(found == true) {found=false;}

      }

      

      return true;

}

function isNumericCity(fieldValue)

{

      var num = '0123456789';

      

      var i,j,found;

      found = false;

      var flag = 0;

      for(i=0;i<fieldValue.length;i++)

      {

            for(j=0;j<num.length;j++)

            {

                  if(fieldValue.charAt(i) == num.charAt(j))

                  {
                        flag = 1;
                        found = true; break;

                  }

            }

//            if(found == false) {return false;}

            if(found == true) {break;}

      }
        
        if(flag == 1)
        {
            return true;
        }
        else
        {
            return false;
        }
      

      

}

function isFloating(fieldValue, decPlace, msg)
{
      var num = '0123456789.';
      var dot='.';
      var i,j,found,valid;

      var count=0;
      valid=true;  
      found = false;

      for(i=0;i<fieldValue.length;i++)
      {      
            for(j=0;j<num.length;j++)
            {
                  if(fieldValue.charAt(i) == num.charAt(j))
                  {
                        found = true;
                        break;
                  }
            }

            if(fieldValue.charAt(i) == ".")
            {
                if (fieldValue.length==1)
                {
                    valid=false;
                    break;
                }    
                else    
                  count = parseInt(count) + 1;
            }

            if(count > 1)
            {
                      found=false;
            }

            if(found == false) {valid=false;}

            if(found == true) {found=false;}

      }

    if (valid)
    {
        var T1=fieldValue.split('.');
        
        if (T1.length==2)        
        {
          if (T1[1].length>decPlace)      
          {
            alert(msg + ' should be entered upto '+ decPlace + ' decimal places');
            return false;
          }
          else
            return valid;
        }
        else
            return valid    
    }
    else
    {
        alert(msg + ' should be valid number');
        return false;
    }    
}

function isNum(fieldValue)

{

      var num = '0123456789';

      var dot='.';

      

      var i,j,found;

      var count=0;

      found = false;
      

      for(i=0;i<fieldValue.length;i++)

      {      
      

            for(j=0;j<num.length;j++)

            {

                  if(fieldValue.charAt(i) == num.charAt(j))

                  {

                        found = true;break;
                       

                  }
                  

            }

            if(fieldValue.charAt(i) == ".")

            {

                  count = parseInt(count) + 1;
                  

            }

            if(count > 1)

            {
           

                      found=false;

            }

            if(found == false) {return false;}

            if(found == true) {found=false;}

      }

      

      return true;

} 

///

function emailvalidation(entered, alertbox)

{

if (entered.value !== "")

{

    with (entered)

    {

    apos=value.indexOf("@");
        
    fdotpos=value.indexOf(".",apos+1);
    
    ldotpos=value.lastIndexOf(".");
    
    
    lastpos=value.length-1;

       // if (apos<1 || fdotpos-apos<2 || ldotpos-apos<2 || lastpos-ldotpos>3 || lastpos-ldotpos<2 || fdotpos+1==ldotpos) 
       if (apos<1 || fdotpos-apos<2 || ldotpos-apos<2 ||  lastpos-ldotpos<2 || fdotpos+1==ldotpos) 
        {
            if (alertbox) 

            {

              alert(alertbox);

            } 

              return false;

        }

        else 

        {

            return true;

        }

    }

}

 

}

////

 

function check_email(e) {

ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

 

for(i=0; i < e.length ;i++){

if(ok.indexOf(e.charAt(i))<0){ 

return (false);

}     

} 

 

if (document.images) {

re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;

re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

if (!e.match(re) && e.match(re_two)) {

return (-1);            

} 

 

}

 

}

function isValidPassword(fieldValue)

{

      var val = fieldValue;

      //alert(val);

      var upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

      var lower = 'abcdefghijklmnopqrstuvwxyz';

      var num = '0123456789';

            

      var i, j;

      var foundNum, foundAlpha;

      foundNum = false;

      foundAlpha = false;

      foundConsecutive = false;

            

      for(i=0;i<val.length;i++)

      {

            for(j=0;j<upper.length;j++)

            {

                  if(val.charAt(i) == upper.charAt(j))

                  {

                        foundAlpha = true;

                        //"found upper case letter"

                        break;

                  }

            }

            if(foundAlpha == false)

            {

                  for(j=0;j<lower.length;j++)

                  {

                        if(val.charAt(i) == lower.charAt(j))

                        {

                              foundAlpha = true;

                              //"found lower case letter"

                              break;

                        }     

                  }

            }

            if(foundNum == false)

            {

                  for(j=0;j<num.length;j++)

                  {

                        if(val.charAt(i) == num.charAt(j))

                        {

                              foundNum = true;

                              //"found number"

                              break;

                        }

                  }

            }

                  

      }

      if (foundAlpha == true && foundNum == true)

      

    {

        var k;

            for(k=0;k<val.length;k++)

            {

            

                  if (val.charAt(k) == val.charAt(k+1))

                        

                  {

                        //"Repeat characters"

                        foundConsecutive = true;

                        break;

                  }

                  

            }

            if (foundConsecutive == true)

            {

                return false;

            }

            else

            {

                return true;

            }

            

    }

    else

    {

        return false;

    }

 

}

 

 

function isValidPWD(fieldValue)

{

      var val = fieldValue;

      //alert(val);

      var upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

      var lower = 'abcdefghijklmnopqrstuvwxyz';

      var num = '0123456789';

            

      var i, j;

      var foundNum, foundAlpha;

      foundNum = false;

      foundAlpha = false;

      foundConsecutive = false;

            

      for(i=0;i<val.length;i++)

      {

            for(j=0;j<upper.length;j++)

            {

                  if(val.charAt(i) == upper.charAt(j))

                  {

                        foundAlpha = true;

                        //"found upper case letter"

                        break;

                  }

            }

            if(foundAlpha == false)

            {

                  for(j=0;j<lower.length;j++)

                  {

                        if(val.charAt(i) == lower.charAt(j))

                        {

                              foundAlpha = true;

                              //"found lower case letter"

                              break;

                        }     

                  }

            }

            if(foundNum == false)

            {

                  for(j=0;j<num.length;j++)

                  {

                        if(val.charAt(i) == num.charAt(j))

                        {

                              foundNum = true;

                              //"found number"

                              break;

                        }

                  }

            }

                  

      }

      if (foundAlpha == true && foundNum == true)

      

    {

      return true;

    }

    else

    {

        return false;

    }

 

}

 

function isMoneyValue(obj,fieldName,precision,scale)

{

    var fieldValue = obj.value;

    if(isFloating(fieldValue,2,fieldName)==false)

    {

        alert(fieldName+' should be numercic or floating point value');

        obj.focus();

        return false;

    }

    else

    {

        // variable defines how much value can store before decimal point

        var before_decimal=precision-scale;

            

        // chack for floating point value

        if(fieldValue.indexOf('.')!=-1)

        {

            var field_array=fieldValue.split('.');

            if((field_array[0].length > before_decimal)||(field_array[1].length > scale))

            {

                alert(fieldName+' value can contain maximum of '+ before_decimal +' length before decmial point and '+scale+' length after decimal point');

                obj.focus();

                return false;

            }

            return true;

        }

        else  // for non-floating point value

        {

           // chack for whole number

           if(fieldValue.length>before_decimal)

           {

                alert(fieldName+' value will not be greater than '+ before_decimal +' length');

                obj.focus();

                return false;

           }

           return true;

        }

    }

}

 

function isValidPercentage(obj,fieldName)

{

    var fieldValue = obj.value;

    

    // Chack for numeric value

    if(isFloating(fieldValue,2,fieldName)==false)

    {

        alert(fieldName+'should be numercic or floating point value');

        obj.focus();

        return false;

    }

    else

    {

        if((fieldValue<1)||(fieldValue>100))

        {

            alert(fieldName+' should be exist between 1 to 100');

            obj.focus();

            return false;

        }

        else

        {

            return true;

        }

    }

}

 

function ObjectIsBlank(obj)

{

    var str="";

      str=obj.value;

      var len=str.length;

      var i;

      for(i=0;i<len;++i)

      {

            if(str.charAt(i)!=" ")

            {

                  return false;

            }

      }

      return true;

}

function isAlpha(txt)
{
	return ValidString(txt,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
}

function ValidString(ChkString,ValidString)
{
	for (i=0; i<ChkString.length; i++)
	{
		if (ValidString.indexOf(ChkString.substring(i,i+1)) == -1) return false;
	}
	return true;
}
// JScript File
function ForEmailNoSplChars(obj,displayName)
{
    if(obj != null)
    {
      var user_text="";
      var quot="'";
      user_text=trim(obj.value);
      splChars=new Array('<','>',quot,'"');
      for(i=0;i<user_text.length;i++)
      {
            for(j=0;j<splChars.length;j++)
            {
                  if(user_text.charAt(i)==splChars[j])
                  {
                   alert(displayName+" can not contain special characters.");
                   obj.focus();
                   return false;
                  }
            }
      }

      return true;
    }
} 


