//<script> /* For enabling the sytax highlighting while editing in interdev  */
///////////////////////////////////////////////////////////////////////////////

/*
 * File Name: UtiltiyFunctions.js
 *      Utiltiy functions.
 * ----------------------------------------------------------------------------     
 * Revision History
 * 
 * On 19/12/2002 by Jagadish Chandra R
 *      Created
 * ----------------------------------------------------------------------------     
 * Copyright(c) 2002 MindTree Consulting(Pvt) Ltd.
 */

/*
 * Function that checks and unchecks the checkbox based on the parameter passed.
 * Checks if the parameter is true or 1, and unchecks if false or 0.
 */
function setChecked(form, name, val) {
    var elmts = form.elements;   // Get the elements
    var len = elmts.length;
    for(var i=0 ; i<len ; i++) {   
        if (elmts[i].name == name) {// If the element is checkbox with particular name
            elmts[i].checked = val;
        }
    }
}

/* 
 * Function that checks or unchecks all the checkboxes, based on the user checks or
 * unchecks the checkbox on the top title row
 */
function checkAndUnCheckAll(form, name, elmt){
    
    if (elmt.checked){
        setChecked(form, name, true);   // If checked, check all the checkboxes
    } else {
        setChecked(form, name, false);
        
    }
}


/* 
 * Function to check whether any check box is checked.
 */

function isChecked(form, name) {
    var elmts = form.elements;   // Get all the elements
    var len = elmts.length;
    for(var i=0 ; i<len; i++) {   
        if (elmts[i].name == name && elmts[i].checked) {
            // If the element is checkbox with particular name and if checked
            return true;
        }
    }
    // No items checked
    return false;

}

/* 
 * Function to check whether any check box is present or not
 */

function isCheckPresent(form, name) {
    var elmts = form.elements;   // Get all the elements
    var len = elmts.length;
    for(var i=0 ; i<len; i++) {   
        if (elmts[i].name == name) {
            // If the element is checkbox with particular name 
            return true;
        }
    }
    // No items checked
    return false;

}


/*
 * Function for invoking the pagination
 */
function paginate(frm, operation, startIndex,length){

   frm.reset();

   if(operation == 'prev'){
    frm.start.value= (startIndex - length);
   }
   if(operation == 'next'){
    frm.start.value= (startIndex + length);
   }
   if(operation == 'page'){
    frm.start.value= startIndex;
   }

   frm.submit();
}

/*
* returns true if any radio button is selected in the group 
* or false if no button is selected
*/
function getSelectedCheck(buttonGroup) {
	   
	   if (buttonGroup[0]) {    // if the button group is an array (one button is not an array)
		  for (var i=0; i<buttonGroup.length; i++) {
			 if (buttonGroup[i].checked) {
				return true
			 }
		  }
	   } else {
		  if (buttonGroup.checked) { return true; }  // if the one button is checked, return true
	   }
	   // if we get to this point, no checkbox is selected
	   return false;
	}

/*
*called by popMultichild
*
*/
	function popChild(childControl,		/*the area/state list box*/
						selParentId,	/*the country/industry ID*/
						bSelChild,		/*whether to pre-select the child*/
						selParentName,	/*the country/industry Name*/
						arrChild,		/*the child array*/
						arrSelChildId	/*array of child ids to be selected*/){
		var currlength = childControl.options.length;
		var j=currlength;
		selParentName = '-- ' + selParentName + ' --';
		childControl.options[j] = new Option(selParentName,"");
		j++;
		if(arrChild != null){
			for(var i=0;i<arrChild.length;i++){
				if(arrChild[i][0] == selParentId){
					childControl.options[j] = new Option(arrChild[i][2],arrChild[i][1]);
					if(arrSelChildId != null && bSelChild){
						for(var p=0;p<arrSelChildId.length;p++){
							if(arrChild[i][1] == arrSelChildId[p]){
								childControl.options[j].selected = true;
								break;
							}
						}
					}
					j++;
				}
			}
		}
	}

/*
*
*populate the states/Areas for the country/industry selected
*
*/
	function popMultiChild(parentControl,	/*the country/Industry list box*/
							childControl,	/*the area/state list box*/
							bSelChild,		/*whether to pre-select the child values*/
							arrChild,		/*the child array */
							arrSelChildId	/*array of child ids to be selected*/){
		childControl.options.length = 1;
		var i = parentControl.options.length;
		for (var j=1;j<i;j++){
			var selParentId = parentControl.options[j].value;
			if(parentControl.options[j].selected == true){
				var selParentName = parentControl.options[j].text;				
				popChild(childControl,selParentId,bSelChild,selParentName,arrChild,arrSelChildId);	
			}
		}
	}
/*
*
*save the area / state selection in an array every time it changes
*
*/
	function saveChildSel(control,arrSelChildId){
		
		var childLength = control.options.length;

		for(var k=0;k<arrSelChildId.length;k++){
			arrSelChildId[k] ='';
		}

		
	
		for(var i=1;i<childLength;i++){
			if(control.options[i].selected==true){
				arrSelChildId[i-1] = control.options[i].value;
			}
		}
	}


///////////////////////////////////////////////////////////////////////////////
//</script> /* For enabling the sytax highlighting while editing in interdev */

