/*For moving one row from one list box to another*/
function SelectMoveRows(SS1,SS2)
{
    var SelID='';
    var SelText='';
    // Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
        if (SS1.options[i].selected == true)
        {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            var newRow = new Option(SelText,SelID);
            SS2.options[SS2.length]=newRow;
			SS1.options[i]=null;
        }
    }
      SelectSort(SS2);
     
}

/*For moving all rows from one list box to another*/
function MoveAllRows(SS1,SS2)
{
    var SelID='';
    var SelText='';
    // Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            var newRow = new Option(SelText,SelID);
            SS2.options[SS2.length]=newRow;
			SS1.options[i]=null;
    }
	var testString = '';
	for(i=0;i<SS2.options.length;i++){
		testString = testString+SS2.options[i].text+",";
	}
	SelectSort(SS2);
 }

/*Sorting the items in the list box after moving from one list box to another*/
function SelectSort(SelList)
{
    var ID='';
    var Text='';
    for (x=0; x < SelList.length - 1; x++)
    {
        for (y=x + 1; y < SelList.length; y++)
        {
			if(SelList[x].text == SelList[y].text){
				SelList[x] = null;
			}
            if (SelList[x].text > SelList[y].text)
            {
                // Swap rows
                ID=SelList[x].value;
                Text=SelList[x].text;
                SelList[x].value=SelList[y].value;
                SelList[x].text=SelList[y].text;
                SelList[y].value=ID;
                SelList[y].text=Text;
            }
        }
    }
}

/*Selecting all the items of the listbox while submitting the form*/
function selectAll(cbList,bSelect) {
  for (var i=0; i<cbList.length; i++) 
    cbList[i].selected = cbList[i].checked = bSelect;
}

/*For generating a random password and disabling password and confirm password fields. Used by Create User and Change 
Password screens*/
function generatePassword(form){
	if(form.randomPassword.checked == true){
		//alert("Random Password selected");
		form.randomPassword.value="true";
		form.displayPassword.value = "";
		form.displayConfirmPassword.value ="";
		form.displayPassword.disabled = true;
		form.displayConfirmPassword.disabled = true;
		form.password.value = "xxxxxx";
		form.confirmPassword.value = "xxxxxx";
	}else{
		//alert("Random Password unselected");
		//alert("Pwd "+form.displayPassword.value+"\n Conf Pwd "+form.displayConfirmPassword.value);
		form.displayPassword.disabled = false;
		form.displayConfirmPassword.disabled = false;
		form.password.value = "";
		form.confirmPassword.value = "";
	}
}


/*

function disableIt(obj)
{
	obj.disabled = !(obj.disabled);
	var z = (obj.disabled) ? 'disabled' : 'enabled';
	alert(obj.type + ' now ' + z);
}

*/
/*For showing the group name and group description in a pop up window.*/
var newwindow;
function showGroupInfo(url)
{
	newwindow=window.open(url,'Groups','height=400,width=400,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function resetUserPassword(){
	
	//alert("Generated Password is :"+temp);
	document.ResetPasswordForm.action = "/go/resetPassword";
	document.ResetPasswordForm.submit();// Submit the page
	return true;
}

/*For resetting the password of the user for user maintenance role when Reset Password button is hit.*/
function resetPasswordForUserMaintenance(){
	//alert("Inside reset pwd for user maint");
	document.UpdateUserForm.randomPassword.value="true";
	document.UpdateUserForm.action = "/go/sso/resetUserMaintPassword";
	document.UpdateUserForm.submit();// Submit the page
	return true;
}

/*For the Change Password button to go to the viewChangePassword action.*/
function submitChangePassword()
{
	document.UpdateUserForm.action = "/go/sso/viewChangePassword";
	document.UpdateUserForm.submit();// Submit the page
	return true;
}


/*For updating the hidden variable corresponding to the check box on Search User Form*/
function setCheckBox(form){
	if((form.checkSearchOrgs.checked)){
		form.searchAllOrgs.value = "checked";
		form.userType.disabled = false;
	}
	else{
		form.searchAllOrgs.value = "unchecked";
		form.userType.disabled = true;
	}
}

/*For displaying the checkbox whether checked or unchecked based on the value of the hidden field corresponding to the check box.*/
function setCheckBox1(){
	if(document.SearchUserForm.searchAllOrgs.value == "checked"){
		document.SearchUserForm.checkSearchOrgs.checked = true;
	}
	else{
		document.SearchUserForm.checkSearchOrgs.checked = false;
	}
}

/*For Show All Users button.*/
function showAllUsers()
{
	document.GroupAssignmentStep2Form.lastName.value = "";
	document.GroupAssignmentStep2Form.userName.value = "";
	document.GroupAssignmentStep2Form.email.value = "";

	return true;
}
 
