
function PdfExtensionsOkay() {
var extension = new Array();
var fieldvalue = document.uploadForm.filenamecur.value;
if(isBlank(fieldvalue)){
    alert("Please select a file");
    return false;
}
extension[0] = ".pdf";
extension[1] = ".PDF";

var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
for(var i = 0; i < extension.length; i++) {
	if(thisext == extension[i]) { return true; }
	}
alert("Your upload form contains an unapproved file name.");
return false;
}

function ExtensionsOkay() {
var extension = new Array();

var fieldvalue = document.uploadForm.filenamecur.value;
if(isBlank(fieldvalue)){
    alert("Please select a file");
    return false;
}
extension[0] = ".zip";
extension[1] = ".ZIP";

var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
for(var i = 0; i < extension.length; i++) {
	if(thisext == extension[i]) { return true; }
	}
alert("Your upload form contains an unapproved file name.");
return false;
}

function isBlank(str)
    {
         var len = str.length;
         var i;
         for (i=0;i<len;++i)
         {
           if (str.charAt(i) != " ")
           return false;
         }
         return true;
    }

function emailChk(em){
                em=em+",";
                while(em.indexOf(',')!=-1){
                        var tmp=em.substring(0, em.indexOf(','));
                        em=em.substring(em.indexOf(',')+1);
                        var tmp1=trimAll(tmp);
                        if(tmp1.length>0&&!emailCheck(tmp1)) return false;
                        }
                
                return true;
                }


function chkFldSizeExceeds(fldValue,permittedLength)
{
        if (fldValue.length < permittedLength)
                return false;
        else
                return true;
}



function trimAll( strValue ) {

        var objRegExp = /^(\s*)$/;

        //check for all spaces
        if(objRegExp.test(strValue)) {
           strValue = strValue.replace(objRegExp, '');
           if( strValue.length == 0)
              return strValue;
        }

        //check for leading & trailing spaces
        objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
        if(objRegExp.test(strValue)) {
           //remove leading and trailing whitespace characters
           strValue = strValue.replace(objRegExp, '$2');
        }
        return strValue;
}

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
        alert(emailStr+"-Email address seems incorrect (check @ and .'s)")
        return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null)
{
    alert(emailStr+"-The username in the email doesn't seem to be valid.")
    return false
}
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
          for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                alert(emailStr+"-Destination IP address is invalid!")
                return false
            }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
        alert(emailStr+"-The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert(emailStr+"-The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(emailStr+"-"+errStr)
   return false
}
return true;
}

function closeWin(){
    window.close();
    window.opener.parent.location.reload(true);

}

//function checking validity of a url



function checkUrl(urlStr){
    var RegExpDict = new Object();
    RegExpDict.url=/^([(http|ftp):\/\/(www\.)]|[a-zA-Z])?.+\.|\/([a-zA-Z]{2,10}|[0-9]{0,3}|[\.])((\]|\/)?)$/;    
    if(RegExpDict.url.test(urlStr)){
    	return true;
    }
    else{
    	return false;
    }
        
}

function count(str,srchChar) {
var ct = 0;
    for(var i =0; i<str.length; i++) {    
        if(str.charAt(i)==srchChar)
            ct++;
    }
return ct;
}

var dtCh= "-";
var minYear=1900;
var maxYear=2200;



function daysInFebruary (year){
        // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
        for (var i = 1; i <= n; i++) {
                this[i] = 31
                if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
                if (i==2) {this[i] = 29}
   }
   return this
}



function isDate(dtStr){
dtStr = trimAll(dtStr)
    var daysInMonth = DaysArray(12);
    var pos1=dtStr.indexOf(dtCh);
    var pos2=dtStr.indexOf(dtCh,pos1+1);
    var strDay=dtStr.substring(0,pos1);
    var strMonth = dtStr.substring(pos1+1,pos2);
    var strYear=dtStr.substring(pos2+1);
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
        for (var i = 1; i <= 3; i++) {
                if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }
        month=parseInt(strMonth)
        day=parseInt(strDay)
        year=parseInt(strYr)


    if (pos1==-1 || pos2==-1){
        alert("The date format should be : dd-mm-yyyy");
        return false;
    }

    if(isNaN(strDay)) {
        alert("The date should be an integer");
        return false;
    }

    if(isNaN(strMonth)) {
        alert("The month should be an integer");
        return false;
    }

    if(isNaN(strYear)) {
        alert("The year should be an integer");
        return false;
    }

    if (strMonth.length<1 || month<1 || strMonth>12){
		alert("Please enter a valid month")
		return false
    }
    
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
    }

    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
            return false
    }


    return true
}

function newXMLHttpRequest() {
  var xmlreq = false;

  if (window.XMLHttpRequest) {

    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    // Create XMLHttpRequest via MS ActiveX
    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1) {
        alert(e1);
      // Failed to create required ActiveXObject

      try {
        // Try version supported by older versions
        // of Internet Explorer

        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {
         alert(e2 + " Your Browser Version doesn't support AJAX. Please try installing newer versions of the browser");
        // Unable to create an XMLHttpRequest with ActiveX
      }
    }
  }

  return xmlreq; 
} 