function compareDates(fdt,tdt) {

	var chk = "Y";
	if(tdt.length > 0)    {
	var len1 = fdt.length;
	
	var ind = fdt.indexOf("-");
	var d1 = eval(fdt.substring(0,ind));
		
	fdt = fdt.substring(ind+1,len1);
	
	
	ind = fdt.indexOf("-");
	var m1 = eval(fdt.substring(0,ind));
	
	fdt = fdt.substring(ind,len1);	
	var y1 = eval(fdt.substring(1,len1));
	
	
	
	len1 = tdt.length;	
	ind = tdt.indexOf("-");
	var d2 =  (tdt.substring(0,ind));
		
	tdt = tdt.substring(ind+1,len1);

	ind = tdt.indexOf("-");
	var m2 = eval(tdt.substring(0,ind));
	
	tdt = tdt.substring(ind,len1);	
	var y2 = eval(tdt.substring(1,len1));
	
	chk = "N";
	//alert(d1+"-"+d2);
	//alert(m1+"-"+m2);
	//alert(y1+"-"+y2);
	
	if(y2 > y1) {
		//alert("1");
		chk="Y";
	}
	if(y2 == y1) {
		if(m2 > m1) {
			//alert("2");
			chk="Y";
		}	
	}
	if(y2 == y1) {
		if(m2 == m1) {
			if(d2 >= d1) {
				//alert("3");
				chk="Y";
			}	
		}	
	}
	} 
	if(chk == "N") {
		alert("check dates");
		return false;
	} else {
		return true;
	}
	
}

function isBlank(str)
    {
         var len = str.length;
         var i;
         for (i=0;i<len;++i)
         {
           if (str.charAt(i) != " ")
           return false;
         }
         return true;
    }
// function to trim the gievn input string                                                                                                                                                                                                                                                            
function trim(inputString) {
        if (typeof inputString != "string") { 
                return inputString;
        }
        var retValue = inputString;
        var ch = retValue.substring(0, 1);
        while (ch == " ") {
                retValue = retValue.substring(1, retValue.length);
                ch = retValue.substring(0, 1);
        }
        ch = retValue.substring(retValue.length-1, retValue.length);
        while (ch == " ") {
                retValue = retValue.substring(0, retValue.length-1);
                ch = retValue.substring(retValue.length-1, retValue.length);
        }
        return retValue;
  }



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 emailChkFR(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&&!emailCheckFR(tmp1)) return false;
                        }
                
                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 emailCheckFR (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+"-Le email address semble incorrect (contr\u00f4le @ et.'s)")
        return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null)
{
    alert(emailStr+"-Le username dans l'email ne semble pas \u00eatre valide")
    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+"-Le IP address de destination est inadmissible")
                return false
            }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
        alert(emailStr+"-Le Domain Name ne semble pas \u00eatre valide")
    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+"-L'adresse doit finir dans un domaine de trois-lettre, ou pays de deux lettres")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="\u00a1Esta direcci\u00f3n omite un hostname!"
   alert(emailStr+"-"+errStr)
   return false
}
return true;
}




function closeWin(){
    window.close();
    window.opener.parent.location.reload(true);

}

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; 
} 
function closeThisWin(formName){
    eval("document."+formName).action="/icsf2006/ControllerServlet?handler=MASTER&code=redirect";
    eval("document."+formName).submit();

}
function chkImageFile(filename){
    if(filename.lastIndexOf(".") > 0 ){
    var extn = (filename.substring(filename.lastIndexOf(".")+1,filename.length)).toLowerCase();
    if((extn == "jpg") || (extn == "jpeg") || (extn == "png") || (extn == "bmp") || (extn == "gif")){
    return true;
    }
    else{
    return false;
    }
    }
    else{
    return false;
    }
    }

function chkImageOrSwfFile(filename){
    if(filename.lastIndexOf(".") > 0 ){
    var extn = (filename.substring(filename.lastIndexOf(".")+1,filename.length)).toLowerCase();
    if((extn == "jpg") || (extn == "jpeg") || (extn == "png") || (extn == "bmp") || (extn == "gif") || (extn == "swf")){
    return true;
    }
    else{
    return false;
    }
    }
    else{
    return false;
    }
    }


function checkPassword(password ,minLength ,maxLength){

if(searchForNumbersAndAlpha(password)){
    if(checkLength(password,minLength,maxLength)){
    return true
    }else{
alert("Your password must be beween six to ten characters");
    return false;
    }
}else{
 alert("Please enter numbers and alphabets !");
return false ;
}
}

function checkPasswordFR(password ,minLength ,maxLength){

if(searchForNumbersAndAlpha(password)){
    if(checkLength(password,minLength,maxLength)){
    return true
    }else{
alert("Votre mot de passe doit \u00eatre beween six \u00e0 dix caract\u00e8res");
    return false;
    }
}else{
 alert("Entrez s'il vous pla\u00eet dans les nombres et les alphabets !");
return false ;
}
}


function checkLength(str,minLength ,maxLength){
    if(str.length<minLength || str.length >maxLength){
    return false ;
    }else{
    return true ;
    }
}

 function searchForNumbersAndAlpha(string)
{  var index = string.search(/1|2|3|4|5|6|7|8|9|0/);   
  if(index<0){
  return false;
  }
  else if(index>=0 && isNaN(string)){  
  return true;
  }else{
  return false ;
  }
}

function changeDisplayState(textId,linkId,showLinkName,hideLinkName) {
        d=document.getElementById(linkId);
        e=document.getElementById(textId);
        if (e.style.display == 'none' || e.style.display == "") {
          e.style.display = 'block';
          d.innerHTML = hideLinkName;
        } else {
          e.style.display = 'none';
          d.innerHTML = showLinkName;
        }
}     
