//
// Copyright (c) 2005-2006 BroadVision, Inc. All rights reserved.
//
// This software is copyrighted.  Under the copyright laws, this software
// may not be copied, in whole or in part, without prior written consent
// of BroadVision, Inc. or its assignees. This software is provided under
// the terms of a license between BroadVision and the recipient, and its
// use is subject to the terms of that license.
//
// This software may be protected by one or more U.S. and International
// patents. Certain applications of BroadVision One-To-One software are
// covered by U.S. patent 5,710,887.
//
// TRADEMARKS: BroadVision and BroadVision One-To-One are registered
// trademarks of BroadVision, Inc., in the United States and the European
// Community, and are trademarks of BroadVision, Inc., in other
// countries.  The BroadVision logo, is a trademark of BroadVision, Inc.,
// in the United States and other countries. Additionally, IONA and Orbix
// are trademarks of IONA Technologies, Ltd.  RSA, MD5, and RC2 are
// trademarks of RSA Data Security, Inc.
//

//
//
//
function toggleSelectAll(field, button, selectAllLabel, unselectAllLabel) {
  var checked = false;
  var buttonLabel = selectAllLabel;

  if (button.value == selectAllLabel) {
    checked = true;
    buttonLabel = unselectAllLabel;
  }

  if(field==null)
	return false;
  var max = field.length;
  if (max > 1) {
    for (var index = 0; index < max; index++) {
       field[index].checked = checked;
    }
    button.value = buttonLabel;
  }
  else {
    field.checked = checked;
    button.value = buttonLabel;
  }
}

//
//
//
function atLeastOneChecked(field) {
  if (field == null) {
    return false;
  }

  if (field.length == null) {
    if (field.checked == false) {
      return false;
    }
    return true;
  }

  for (var index = 0; index < field.length; index++) {
    if (field[index].checked) {
      return true;
    }
  }
  return false;
}

function onlyOneChecked(field) {
  var loopCount=0;
  if (field == null) {
    return false;
  }

  if (field.length == null) {
    if (field.checked == false) {
      return false;
    }
    return true;
  }
  
  for (var index = 0; index < field.length; index++) {
    if (field[index].checked) {
      loopCount++
    }
  }
  if(loopCount==1){
	  return true;
  }
  else{
	  return false;
  }
}

//
//
//
function showAlert(alertMsg) {
  if (alertMsg != null && alertMsg.length > 0) {
    alert(alertMsg);
  }
}

function headcountlov(selectedElement,str,params0,params1,params2,params3,params4,params5,params6,params7,params8,params9,params10,params11,params12,params13,params14,params15,params16,params17,params18){
	 var headcount = new Object;
	 headcount.allyear          = params0;
	 headcount.firsthalf        = params1;
	 headcount.secondhalf       = params2;
	 headcount.firstseason      = params3;
	 headcount.secondseason     = params4;
	 headcount.thirdseason      = params5;
	 headcount.forthseason      = params6;
	 headcount.jan               = params7;
	 headcount.feb               = params8;
	 headcount.mar               = params9;
	 headcount.apr               = params10;
	 headcount.may               = params11;
	 headcount.jun               = params12;
	 headcount.jul               = params13;
	 headcount.aug               = params14;
	 headcount.sep               = params15;
	 headcount.oct               = params16;
	 headcount.nov               = params17;
	 headcount.dec               = params18; 
	 operatorList = { 'YEAR': [headcount.allyear] ,
		           'HALF': [headcount.firsthalf,headcount.secondhalf] , 
                    	   'SEASON':[headcount.firstseason,headcount.secondseason,headcount.thirdseason,headcount.forthseason] ,
			   'MONTH': [headcount.jan,headcount.feb,headcount.mar,headcount.apr, headcount.may,headcount.jun, headcount.jul,headcount.aug,headcount.sep,headcount.oct,headcount.nov,headcount.dec] 
                 };
	operatorList2 = { 'YEAR': ["Y"] ,
		           'HALF': ['H1','H2'] , 
                    	   'SEASON':['Q1','Q2','Q3','Q4'] ,
			   'MONTH': ['M01','M02','M03','M04','M05','M06','M07','M08','M09','M10','M11','M12'] 
                 };
        var elem = document.getElementById( str ) ;
        var opertype = selectedElement.options[selectedElement.selectedIndex].getAttribute ('dtype'); 	 
  	var operstr = "<SELECT name = " + str + " id='" + str + ".select'>" ;
  		
 	for(i=0; i<operatorList[opertype].length; i++){  	
          operstr += "<Option value ='" + operatorList2[opertype][i] + "' >";
          operstr +=  operatorList[opertype][i] + "</Option>" ;          
        }
  	operstr += "</SELECT>" ;
	elem.innerHTML = operstr ;
  			 
	
}


function pchange(selectedElement,params0,params1,params2,params3,params4,params5,params6,params7,params8,params9,params10,params11,params12,params13,params14,params15,params16,params17,params18){
	 var headcount = new Object;
	 headcount.allyear          = params0;
	 headcount.firsthalf        = params1;
	 headcount.secondhalf       = params2;
	 headcount.firstseason      = params3;
	 headcount.secondseason     = params4;
	 headcount.thirdseason      = params5;
	 headcount.forthseason      = params6;
	 headcount.jan               = params7;
	 headcount.feb               = params8;
	 headcount.mar               = params9;
	 headcount.apr               = params10;
	 headcount.may               = params11;
	 headcount.jun               = params12;
	 headcount.jul               = params13;
	 headcount.aug               = params14;
	 headcount.sep               = params15;
	 headcount.oct               = params16;
	 headcount.nov               = params17;
	 headcount.dec               = params18; 
	 operatorList = {  '':[""],
			   'YEAR': [headcount.allyear] ,
		           'HALF': [headcount.firsthalf,headcount.secondhalf] , 
                    	   'SEASON':[headcount.firstseason,headcount.secondseason,headcount.thirdseason,headcount.forthseason] ,
			   'MONTH': [headcount.jan,headcount.feb,headcount.mar,headcount.apr, headcount.may,headcount.jun, headcount.jul,headcount.aug,headcount.sep,headcount.oct,headcount.nov,headcount.dec] 
                 };
	operatorList2 = {  '':[""],
			   'YEAR': ["Y"] ,
		           'HALF': ['H1','H2'] , 
                    	   'SEASON':['Q1','Q2','Q3','Q4'] ,
			   'MONTH': ['M01','M02','M03','M04','M05','M06','M07','M08','M09','M10','M11','M12'] 
                 };
        //var elem = document.getElementById( "content/TIME_UNIT" ) ;
        var opertype = selectedElement.options[selectedElement.selectedIndex].getAttribute ('value'); 
	alert(opertype);  
	alert(operatorList[opertype]);
  	var operstr = "<SELECT name = 'content/TIME_UNIT' >" ;
 	for(i=0; i<operatorList[opertype].length; i++){  	
          operstr += "<option value ='" + operatorList2[opertype][i] + "' >";
          operstr +=  operatorList[opertype][i] + "</option>" ;          
        }
  	operstr += "</SELECT>" ;
	//alert(elem.tagName);
	var elem = $("select[@name='content/TIME_UNIT']").get(0);
	elem = elem.parentNode;
	elem.innerHTML = operstr ;		 
  			 
	
}
