function getElementByIdEnd(tagName,idEnd) {
//ns
if (document.getElementsByTagName){                        
    var objlist = document.getElementsByTagName(tagName);
    //if (objlist.length == 0) {if (document.all) {objlist = document.all}}; //ie 5.5. and bellow
    for (var i=0;i<objlist.length;i++)   { 
    str = objlist[i].id;
        if (str.substr(str.length - idEnd.length).toLowerCase() == idEnd.toLowerCase()) {
            return objlist[i];
        }
    }
//ie4
} else if (document.all){
    for (i=0; i< document.all.length; i++){
        var str = document.all[i].id; 
        if (str.substr(str.length - objId.length).toLowerCase() == objId.toLowerCase()) {
            return document.all[i];
        } 
    }
//ns4
}  else {    
  return null;
 }
}
var indooCurrentFldId=''; 
var indooLastFldVal=''; 
function indooDPickBefore(id){
    indooCurrentFldId=id;
    indooLastFldVal=new String(__indooGetDat(id));
}
function indooDPickAfter(id,org){

}
function indoopopcalunload(){
}
function indooChkDatPick(fld){
    if (indooCurrentFldId!=''){
        checkSpan=false;
        if (typeof popCalWin.document!='object'){
            checkSpan=true;
        }else{
            if(popCalWin.closed==true){
                checkSpan=true;
            }
        }
        if (checkSpan==true){
            indooSetSpan()
        }
        indooCurrentFldId='';
        indooLastFldVal='';
    }
}
function indooAddfocus(){
	if (typeof window.addEventListener!='undefined'){
		window.addEventListener('focus', indooChkDatPick , false);
	} else {
		if (typeof window.attachEvent!='undefined'){
			window.attachEvent('onfocus', indooChkDatPick , false);
		}
	}
}
indooAddfocus();

function indooSetSpan(){
    dat1S=indooLastFldVal;
    dat2S=__indooGetDat(indooCurrentFldId);
    dat1=__indooDateNum(dat1S)
    dat2=__indooDateNum(dat2S);
    el=__indooGetElById(indooCurrentFldId);
    if (dat1>-1&&dat2>-1&&el!=null){
        if (dat1==dat2){
            el.value=dat2S
        }else{
            if (dat1>dat2){
                el.value=">="+dat2S+' <='+dat1S
            }else{
                el.value=">="+dat1S+' <='+dat2S
            }
        }
    }
}
function __indooGetDat(id){
	el=__indooGetElById(id)
	if (el!=null){
			if(el.value!=null && el.value!='' && el.value!='undefined'){
			    return el.value;
			}
	}
    return null
}
function __indooGetElById(id){
	if (document.getElementById){
		if (document.getElementById(id)){
			return document.getElementById(id);
		}
	}
    return null;
}
function __indooDateNum(str){
    if (str!=null){
        parts=str.split(__indooDatSep);
        if(parts.length==3){
            d=-1;m=-1;y=parts[2];
            if (__indooIsMonFirst==0){
                d=parts[0];
                m=parts[1];
            }else{
                d=parts[1];
                m=parts[0];
            }
            d=__indooFix2(d);
            m=__indooFix2(m)
            n=y+m+d
            if (isNaN(n)==false && d.length==2 && m.length==2){
                return parseInt(n)
            }
        }
    }
    return -1
}
function __indooFix2(str){
    if( str.length==1){
        return '0'+str;
    }else{
        return str;
    }
}

/// newValue is optional. When omitted then function returns paremeter value from url otherwise returns full url with parameter and new value
function indooUrlParameter(url,name,newValue){
    var regex = new RegExp("[\\?&]"+name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]")+"=([^&#]*)","i");  
    var results = regex.exec(url);  
    if (newValue == null){
        return results == null ? "" : results[1]
    }else{
        if (results == null){
            return url + (url.lastIndexOf('?') < 0 ? '?' : '&') + name + '=' + newValue;
        }else{
            return url.replace(results[0],results[0].substring(0,1) + name + '=' + newValue);
        }
    }
}
