/*-----------------------------------------------------------------*/
/* JavaScript Routines
/*-----------------------------------------------------------------*/
/* Winchester City Council
/* Governance Group
/* Information Management and Technology
/* Copyright (c) Winchester City Council 2008.  All rights reserved.
/* Unathorised distribution or reproduction of this program, 
/* or any portion of it, may result in severe civil and criminal penalties, 
/* and will be prosecuted to the maximum extent possible under the law
/*-----------------------------------------------------------------*/

/* --- START :: general --- */
function FocusNext(Cur, Next, Previous, evt , elem) {
    /* allows auto focus between controls */
    c=document.getElementById(Cur);
    n=document.getElementById(Next);  
    p=document.getElementById(Previous);   

    if (c.value.length==c.maxLength) n.focus();
    
    if (evt.which || evt.keyCode) {
        if ((evt.which != 9) || (evt.keyCode != 9)) {    
            if (c.value.length==0) p.focus();
        }
    }
}

/*-----------------------------------------------------------------*/
function SpreadPaste(vctrl1, vctrl2, vctrl3) {
    /* detects paste into control, then populates other controls with data */
    /* can only be used with the first control vctrl1 AND only by using */
    /* keyboard cut and paste (CTRL C & V) */
    ctl1 = document.getElementById(vctrl1);
    ctl2 = document.getElementById(vctrl2);
    ctl3 = document.getElementById(vctrl3);
    
    value = ctl1.value;
    valueLen = ctl1.value.length;
    
    if (ctl1.value.length>2) {
        val = value.substr(0,2);
        ctl1.value = val;
    }

    if ((valueLen-3)>0) {
        val = value.substr(3,5);
        ctl2.value = val;
    }
    
    if ((valueLen-9)>0) {
        val = value.substr(9 , 15);
        ctl3.value = val;
    }
        
    return false;
}

/*-----------------------------------------------------------------*/
function anyBlankCtrls( controls , errMsgCtrl , errMsgHTML ) {
    var myCtrls;
    var myCtrls_length;
    var flagError;
    var obj;
   
    myCtrls = controls.split(",");
    myCtrls_length = myCtrls.length; 
    flagError = true;
               
    /* --- START :: validate if any controls are blank --- */
    var i=0;
    for (i=0 ; i< myCtrls_length ; i++ ) {
    
        /*alert( document.getElementById(myCtrls[i]).value.length );*/
    
        if (document.getElementById) { // DOM3 = IE5, NS6
            if ( document.getElementById( myCtrls[i] ).value.length > 0  ) {
                flagError = false;
            } 
            
        } else {
			if (document.layers) { // Netscape 4
			    obj = myCtrls[i];
			    if ( document.obj.value.lentgh > 0 ) {
			        flagError = false;
			    }
			} else { // IE 4
                obj  = myCtrls[i];
                if (document.all.obj.value.length > 0 ) {
                    flagError = false;
                }			
			}
        }
    }
    /* --- END :: validate if any controls are blank --- */

    /* --- START :: change css of controls --- */
    if (flagError == true) {
        for (i=0 ; i< myCtrls_length ; i++ ) {
            if (document.getElementById) { // DOM3 = IE5, NS6
                document.getElementById(myCtrls[i]).style.borderStyle = "solid";
                document.getElementById(myCtrls[i]).style.borderColor = "#FF0000";
                document.getElementById(myCtrls[i]).style.borderWidth = "1px";                
                
            } else {
			    if (document.layers) { // Netscape 4
			        obj = myCtrls[i];
			        if ( document.obj.value = '' ) {
			            flagError = false;
			        }
			    } else { // IE 4
                    obj  = myCtrls[i];
                    if (document.all.obj.value = '' ) {
                        flagError = false;
                    }			
			    }
            }
        }
    }
    /* --- END :: change css of controls --- */

    /* --- START :: display error message --- */
    if (flagError == true) {
        if (document.getElementById) { // DOM3 = IE5, NS6
            document.getElementById( errMsgCtrl ).innerHTML = errMsgHTML;
        } else {
	        if (document.layers) { // Netscape 4
                document.errMsgCtrl.innerHTML = errMsgHTML;		
	        } else { // IE 4
                document.all.errMsgCtrl.innerHTML = errMsgHTML;		
	        }
        }
    }
    /* --- END :: display error message --- */
    
    return flagError;
    
}

/*-----------------------------------------------------------------*/
function activateMethod( flagError , ctlToActivate, ctlToActivateMethod ) {       
    var obj;
    
    /* --- START :: click search button if appropriate --- */
    if (flagError == false) {
        if (document.getElementById) { // DOM3 = IE5, NS6
            switch( ctlToActivateMethod ) {
                case "click":
                    document.getElementById(ctlToActivate).click();
                    break;    
                default:
                    /* nothing can be done */
                    break;
            }        
        } else {
			if (document.layers) { // Netscape 4
			    obj = ctlToActivate;
                switch( ctlToActivateMethod ) {
                    case "click":
                        document.obj.click()    
                        break;    
                    default:
                        /* nothing can be done */
                        break;
                }        
			} else { // IE 4
    		    obj = ctlToActivate;
                switch( ctlToActivateMethod ) {
                    case "click":
			            document.all.obj.click();
                        break;    
                    default:
                        /* nothing can be done */
                        break;
                }        
			}
        }
    }
    /* --- END :: click search button if appropriate --- */    
}

/*-----------------------------------------------------------------*/
function changeCSSClass( objID, cssClass ) {

    var currElem;

    if (document.getElementById) { // DOM3 = IE5, NS6
        currElem = document.getElementById(objID);
	} else {
	    if (document.layers) { // Netscape 4
            currElem = document.objID;	    
	    } else { // IE 4
	        currElem = document.all.objID;
	    }
	}

    //if (is_ie5up) {
        // JavaScript here for IE 4 and later
        currElem.setAttribute("classname", cssClass);        
    //} else if (is_nav3 || is_opera) {
        // JavaScript here for Nav3 and Opera 
    //    currElem.setAttribute("class", cssClass);
    //}
    
    currElem.className = cssClass;

    return;

}


/* --- END :: general --- */

/* --- START :: js to assist in tabindex --- */
function highlight(elem){
    //elem.className = 'focused';
    elem.className = 'focused';

}
function unhighlight(elem){
    elem.className = '';
}
/*
function highlight(elem){
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById( elem ).className = 'focused';
    } else {
		if (document.layers) { // Netscape 4
		    obj = elem;
		    document.obj.className = 'focused';
		} else { // IE 4
            obj  = elem;
            document.all.obj.className = 'focused';
		}
    }
}

function unhighlight(elem){
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById( elem ).className = '';
    } else {
		if (document.layers) { // Netscape 4
		    obj = elem;
		    document.obj.className = '';
		} else { // IE 4
            obj  = elem;
            document.all.obj.className = '';
		}
    }
}
*/

/* --- END :: js to assist in tabindex --- */

/* --- START :: search_CaseReferences.ascx --- */

/* --- END :: search_CaseReferences.ascx --- */

function genericLoop() {
        if (document.getElementById) { // DOM3 = IE5, NS6
            if ( document.getElementById( myCtrls[i] ).value = '' ) {

            } 
        } else {
			if (document.layers) { // Netscape 4
			    obj = myCtrls[i];
			    if ( document.obj.value = '' ) {

			    }
			} else { // IE 4
                obj  = myCtrls[i];
                if (document.all.obj.value = '' ) {

                }			
			}
        }
}
