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);
        }
    }
}
function Get_Cookie( check_name ) {

	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

function Set_Cookie( name, value, expiresDays, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expiresDays )
	{
		expires = expiresDays * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	val = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	document.cookie = val;
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var __resultIndexes = new Array();
function getFormElementByNameEnd(elementName, storeAll){
    var result = checkResultStore(elementName,null,true)
    
    if (null!=result){
        return result;
    }
    var resultArr = new Array();
    isResultArrSet=false
    if(__resultIndexes[elementName.length]=='undefined'||__resultIndexes[elementName.length]==null){
        isResultArrSet=true;
    }else{
        result = __resultIndexes[elementName.length][elementName];
        if(result=='undefined'){
            return null;
        }else{
            return result;
        }
    }
    result = null;
    
	var frm = document.forms[0];
	for(var j = 0; j < frm.length; j++){
		nm = frm[j].name;
		if (nm == elementName){
		   result = frm[j];
		   if(storeAll==true){
		       resultArr[elementName]=result;
		   }else{
		        return result;
		   }
		   //return addToResultStore(frm[j],elementName,null,true)
		}
		if (nm.length > elementName.length) {
			nmEnd = nm.substr(nm.length - elementName.length,nm.length)
		    resultArr[nmEnd]=frm[j];
			if (nmEnd == elementName){
                result = frm[j];
 		           if(storeAll!=true){
		                return result;
		           }
               //return addToResultStore(frm[j],elementName,null,true)
			}
		}
	}
	if(isResultArrSet==true){
	    __resultIndexes[elementName.length]=resultArr
	}
   return addToResultStore(result,elementName,null,true)
}


var __resultStore=null;
function addToResultStore(result, param1,param2,param3){
    if (__resultStore==null){
        __resultStore=[];
    }    
 	isSet=false;
 	for(var i = 0; i < __resultStore.length; i++) {
 	    if (__resultStore[i][1]==param1 && __resultStore[i][2]==param2 && __resultStore[i][3]==param3){
 	        isSet=true;
 	        __resultStore[i]=[result,param1,param2,param3]
 	        break;
 	    } 
 	}
    if (isSet==false){
        __resultStore[__resultStore.length]=[result,param1,param2,param3]
    }
    return result;
}
function checkResultStore(param1,param2,param3){
    if (__resultStore==null){
        return null;
    }else{
 	    for(var i = 0; i < __resultStore.length; i++) {
 	        if (__resultStore[i][1]==param1 && __resultStore[i][2]==param2 && __resultStore[i][3]==param3){
 	            return __resultStore[i][0]
 	        } 
 	    }
    }
    return null
}
function getFormElementsByNameEnd(elementName, substring, returnFirstResultOnly){// return array
	var result = checkResultStore(elementName, substring, returnFirstResultOnly)
	if (null!=result){
	    return result;
	}
	var frm = document.forms[0];
	if (elementName.length>1){
		elName = elementName.substr(1)
	}else{
		elName = elementName
	}
    var els = new Array();
    for(var j = 0; j < frm.length; j++){
        nm = frm[j].name
		if (nm == elementName){
		   els[els.length] = frm[j];
		} else {
			if (nm.length > elName.length) {
				nmEnd = nm.substr(nm.length - elName.length,nm.length)
				if (substring != null){
					 if (nm.indexOf(substring)>-1){
						if (nmEnd == elName){
							els[els.length] = frm[j];
							if (returnFirstResultOnly==true){
							    return addToResultStore(els,elementName, substring, returnFirstResultOnly);
							} 
						}
					}
				}else{
					if (nmEnd == elName){
						els[els.length] = frm[j];
						if (returnFirstResultOnly==true){
						    return addToResultStore(els,elementName, substring, returnFirstResultOnly);
						} 
					}
				}
			}
		}
    }
    return addToResultStore(els,elementName, substring, returnFirstResultOnly);
}
__indooIsReload=false;
function indooReload(url,isScript){
    if(__indooIsReload==false){
        __indooIsReload=true;
        if(isScript){
            eval(url);
        }else{
            document.location.href=url;
        }
    }
}

