﻿// JScript File


var intMaxLimit=150;
var intMediumLimit=11;
//var positionStr='';
//var npa=null;
  function noTrim(text)
  {
    
    text=text.split(" ");
    if (text.length==1)
    {
        return true;
    }
    else
    {
        return false;
    }
  }	  
  function CheckLength(lengthValue)
  {
  if (lengthValue<=intMaxLimit)
      {
        return true;
      }
  else
      {
        return false;
      }
  }
   function CheckMediumLength(lengthValue)
  {
  if (lengthValue<=intMediumLimit)
      {
        return true;
      }
  else
      {
        return false;
      }
  }
  //for blank entry check........................
  function isNotBlank(text)
  {
      if(text=="" || text==null)
    {
    
        //return false as there is no value entered
               return false;
    }
    return true;
  }
  //check for decimal number...........................
  function isDecimal(text)
  {
    if(isNaN(text))
    {
       //the number entered is not in decimal format
        return false;
    }
    return true;
  }
   //check for the number value decimal and integer
    function isABCD(text)
  {
     if(isNaN(text))
    {
        //the number entered is not in decimal format
        return false;
    }
    return true;
  }
  //to check the integer number.....................
  function isNumber(text)
  {
   if (isDecimal(text)==true)
   {
       var a;
       a=text.split(".");
       if (a.length!=1)
        {
            //the entered value is not in number format
            return false;
        }
        return true;
   }
    else
    {
        return false;
    }
  }
  //to set the focus to relative control.................
  function setFocus(obj)
  {
  obj.focus();
  return true;
  }
  //to check non-zero number..............
  function isNotZero(text)
  {
    if(isDecimal(text)==true)
    {
        if(text==0)
        {
            //entered value is zero
            return false;
        }
    }
    else
    {
    return false;
    }
    return true;
  }
  //to check negative number...................
  function isNotNegative(text)
  {
    if(isDecimal(text))
    {
        if(text<0)
        {
            //entered value is negative 
            return false;
        }
    }
    else
    {
        return false;
    }
    return true;
  }
  //to check the positive number................
  function isNotPositive(text)
  {
    if(isDecimal(text))
    {
        if(text>=0)
        {
            //the number entered is Positive number
            return false;
        }
    }
    else
    {
        return false;
    }
    return true;
  }
  //to check same values of two controls................
  function isSame(text1,text2)
  {
    if(text1!=text2)
    {
       //the entered values are not same
        return false;
    }
    return true;
  }
  //to check valid email id.................
  function isEmail(text)
  {
    var exp;                                
    exp=/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
    if(exp.test(text)==false)
    {
       //the entered value is not correct email id
        return false;
    }
    return true;
  }
  //check for valid date.............
   function isValidDate(dd,mm,yy)
  {
   if (dd == 31 && (mm == 04 || mm == 06 || mm == 09 || mm == 11)) 
   {
        //the entered value is not a valid date
        return false; // 31st of a month with 30 days
    } 
   if (dd >= 30 && mm == 02) 
    {
        //the entered value is not a valid date
        return false; // February 30th or 31st
    } 
    if (mm == 02 && dd == 29 && !(yy % 4 == 0 && (yy % 100 != 0 || yy % 400 == 0))) 
    {
      //the entered value is not a valid date
      return false; // February 29th outside a leap year
    } 
      return true; // Valid date
  }
  //check for date format...........
   function isDate(text,format)
  {
    var exp;
    var mesg;                                
   if(format==1)
   {
        exp=/(0[1-9]|[12][0-9]|3[01])[.](0[1-9]|1[012])[.](1|2)\d\d\d/;
        mesg="Please Enter the Valid Date (dd.mm.yyyy Format)";
        
   }
   if(format==2)
   {
        exp=/(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](1|2)\d\d\d/;
        mesg="Please Enter the Valid Date (mm/dd/yyyy Format)";
   }
   if(format==3)
   {
        exp=/(1|2)\d\d\d[/](0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])/;
        mesg="Please Enter the valid Date (yyyy/mm/dd Format)";
   }
   if(exp.test(text)==false)
   {
        alert(mesg);
        return false;     
    }
   
    var general;
    general=text.split(".");
    if(format==1)
    {
        dd=general[0];
        mm=general[1];
        yy=general[2];
        if(isNumber(dd)==true && isNumber(mm)==true && isNumber(yy)==true)
        {
            if(isValidDate(dd,mm,yy)==false)
            {
                alert("Please Enter the Valid Date (dd.mm.yyyy Format)");
                return false;
            }
        }
        else
        {
            alert("Please Enter the Valid Date ((dd.mm.yyyy Format)");
            return false;
        }
     }
      if(format==2)
    {
        dd=general[1];
        mm=general[0];
        yy=general[2];
        if(isNumber(dd)==true && isNumber(mm)==true && isNumber(yy)==true)
        {
            if(isValidDate(dd,mm,yy)==false)
            {
                alert("Please Enter the Valid Date (mm/dd/yyyy Format)");
                return false;
            }
        }
        else
        {
            alert("Please Enter the Valid Date (mm/dd/yyyy Format)");
            return false;
        }
     }
      if(format==3)
    {
        dd=general[2];
        mm=general[1];
        yy=general[0];
        if(isNumber(dd)==true && isNumber(mm)==true && isNumber(yy)==true)
        {
            if(isValidDate(dd,mm,yy)==false)
            {
                alert("Please Enter the Valid Date (yyyy/mm/dd Format)");
                return false;
            }
        }
        else
        {
            alert("Please Enter the Valid Date (yyyy/mm/dd Format)");
            return false;
        }
     }
     return true;
  }
  //check valid datetime format..........
 function isValidTime(timeStr)
 {
    // Checks if time is in HH:MM:SS AM/PM format.
    // The seconds and AM/PM are optional.
    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
    var matchArray = timeStr.match(timePat);
    if (matchArray == null)
    {
        alert("Time is not in a valid format.");
        return false;
    }
    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];
    if (second=="")
    {
        second = null; 
    }
    if (ampm=="") 
    { 
        ampm = null 
    }
    if (hour < 0  || hour > 23)
    {
        alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
        return false;
    }
    if (hour <= 12 && ampm == null) 
    {
        if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) 
        {
            alert("You must specify AM or PM.");
            return false;
        }
    }
    if  (hour > 12 && ampm != null) 
    {
        alert("You can't specify AM or PM for military time.");
        return false;
    }
    if (minute<0 || minute > 59) 
    {
        alert ("Minute must be between 0 and 59.");
        return false;
    }
    if (second != null && (second < 0 || second > 59)) 
    {
        alert ("Second must be between 0 and 59.");
        return false;
    }
    return false;
 }
 //
 function ddlSelectedValue(intVal)
 {
    if (intVal<=0)
    {
        return false;
    }
    return true;
 }
 function LogoType(text)
 {
    text=text.split(".");
    value=text[(text.length-1)];
    if (!(value=="jpg" || value=="bmp" || value=="gif"))
    {
        return false;
    }    
    return true;
 }
 function ConfirmDelete()
        {
            if (confirm("Are you sure?"))
	        {
      	 	    return true;
	        }
	        else
	        {
  		        return false;
	        }
	        return true;
        }
  function ConfirmSelection()
        {
            if (confirm("Are you sure about your selection."))
	        {
      	 	    return true;
	        }
	        else
	        {
  		        return false;
	        }
	        return true;
        }
      
 function whichBrowser()
 {
    if (navigator.appVersion!=6.0)
    {
        alert("You need Microsoft Internet Explorer version 6.0 or greater")
        return false;
    }
    return true;
 }
 function sum(x,y)
 {
    return x + y;
 }
 function subtract(x,y)
 {
    return x - y;
 }
 function multiplay(x,y)
 {
    return x * y;
 }
 function divide(x,y)
 {
    return x / y;
 }
// function launch()
// {
//    if (!whichBrowser())
//    {
//        return;
//    }
//    if (navigator.appName=="Netscape")
//    {
//        positionStr= " ,screenX=0,screenY=0";
//    }
//    else
//    {
//        positionStr= " ,fullscreen=yes";
//    }
//    if (npa==null)
//    {
//        npa=open("../ClientNPA/City.aspx","","width=" + screen.width + ",height=" + screen.height + posotionStr);
//    }
//}

function fixLink(id, target){
    document.getElementById(id).href = window.location.protocol + "//" + window.location.host + "/" + target;
}
    

