function changePage(page, param) {
  document.frm.page.value = page;
  document.frm.param.value = param;
  document.frm.submit();
}

function lockButtons(whichform) 
{
    ua = new String(navigator.userAgent);
    if (ua.match(/IE/g)) {
        for (i=1; i<whichform.elements.length; i++) {
            if ((whichform.elements[i].type == 'submit') || (whichform.elements[i].type == 'button'))
                whichform.elements[i].disabled = true;
        }
    }
    whichform.submit();
}

/*
function openWindow()
{
    var newWin = null;
    var url = openWindow.arguments[0];
    nArgs = openWindow.arguments.length;
    var width = openWindow.arguments[1];
    var height = openWindow.arguments[2];

    //  if dynamic window size args are passed
    if (nArgs > 1)
        newWin =  window.open ("","newWindow","toolbar=no,width=" + width + ",height=" + height + ",directories=no,status=no,scrollbars=yes,resizable=no,menubar=no");
    else 
        newWin =  window.open ("","newWindow","toolbar=no,width=" + SGL_JS_WINWIDTH + ",height=" + SGL_JS_WINHEIGHT + ",directories=no,status=no,scrollbars=yes,resizable=no,menubar=no");
    newWin.location.href = url;
}
*/

/*
* @modif Cyril AGRA 8/08/2005
*/
function openWindow()
{
    var newWin = null;
    var url = openWindow.arguments[0];
    nArgs = openWindow.arguments.length;
    var width = openWindow.arguments[1];
    var height = openWindow.arguments[2];
    var winName = "newWindow";
    if(openWindow.arguments[3]) {
        winName = openWindow.arguments[3];
    }

    //  if dynamic window size args are passed
    if (nArgs > 1)
        newWin =  window.open ("",winName,"toolbar=no,width=" + width + ",height=" + height + ",directories=no,status=no,scrollbars=yes,resizable=no,menubar=no");
    else 
        newWin =  window.open ("",winName,"toolbar=no,width=" + SGL_JS_WINWIDTH + ",height=" + SGL_JS_WINHEIGHT + ",directories=no,status=no,scrollbars=yes,resizable=no,menubar=no");
    newWin.location.href = url;
}

function confirmSubmit(item, formName)
{
    var evalFormName = eval('document.' + formName)
    var flag = false
    for (var count = 0; count < evalFormName.elements.length; count++) {
        var tipo = evalFormName.elements[count].type
        if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '')
            flag = true 
    }
    if (flag == false) {
        alert('You must select an element to delete')
        return false
    }
    var agree = confirm("Are you sure you want to delete this " + item + "?");
    if (agree)
        return true;
    else
        return false;
}

function confirmDelete(item, formName, inputName, mesNoSelected, mesConfirm)
{
    var evalFormName = eval('document.' + formName)
    var flag = false
    for (var count = 0; count < evalFormName.elements.length; count++) {
        var tipo = evalFormName.elements[count].type
        var name = evalFormName.elements[count].name
        if (tipo == 'checkbox' && name == inputName && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '')
            flag = true 
    }
    if (flag == false) {
        alert(mesNoSelected)
        return false
    }
    var agree = confirm(mesConfirm + item + "?");
    if (agree)
        return true;
    else
        return false;
}

function confirmSave(formName)
{
    var evalFormName = eval('document.' + formName)
    var flag = false
    for (var count = 0; count < evalFormName.elements.length; count++) {
        var tipo = evalFormName.elements[count].type
        if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '')
            flag = true 
    }
    if (flag == false) {
        alert('You must select an element to save')
        return false
    }
}

function confirmSend(formName)
{
    var evalFormName = eval('document.' + formName)
    var flag = false
    for (var count = 0; count < evalFormName.elements.length; count++) {
        var tipo = evalFormName.elements[count].type
        if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '')
            flag = true 
    }
    if (flag == false) {
        alert('You must select at least one recipient')
        return false
    }
}

function confirmCategoryDelete(item) 
{
    var agree = confirm("Are you sure you want to delete this " + item + "?");
    if (agree)
        return true;
    else
        return false;
}

function verifySelectionMade() 
{
    var moveForm = document.moveCategory.frmNewCatParentID
    var selectedCat = moveForm.value
    if (selectedCat == '') {
        alert('Please select a new parent category')
        return false;
    } else
        return true;
}

function checkInput(formName, fieldName)
{
    var f = eval('document.' + formName + '.' + fieldName)
    if (f.value == '') {
        alert('Please enter a value in the field before submitting');
        return false;
    } else
        return true;
}

function getSelectedValue(selectObj)
{
    return (selectObj.options[selectObj.selectedIndex].value);
}


function toggleDisplay(myElement)
{	
	boxElement = document.getElementById(myElement);

	if (boxElement.style.display == 'none') {
		boxElement.style.display = 'block';
	} else {
    	// ... otherwise collapse box
		boxElement.style.display = 'none';
	}
}

function confirmCustom(alertText, confirmText, formName)
{
    var evalFormName = eval('document.' + formName)
    var flag = false
    for (var count = 0; count < evalFormName.elements.length; count++) {
        var tipo = evalFormName.elements[count].type
        if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '')
            flag = true 
    }
    if (flag == false) {
        alert(alertText)
        return false
    }
    var agree = confirm(confirmText);
    if (agree)
        return true;
    else
        return false;
}

/*
* add form 
*
* @param string  element name
* @param         element value
* @param string  form name
* @param string  type 
*
*/
function addFormValue(myElement, value, form, type)
{
    var myForm = document.getElementById(form);
    
    newInput = document.createElement("input");
    newInput.setAttribute('name', myElement);
    newInput.setAttribute('value', value);
    newInput.setAttribute('type', type);
    myForm.appendChild(newInput);
}

/*** CALENDAR ***/
// fill liste of days by month selected
function ShowNbDays(idListDays, idListMonths, firstOption)
{
    var m = document.getElementById(idListMonths).options[document.getElementById(idListMonths).selectedIndex].value;
    var d = new Date(m.substr(2,4),m.substr(0,2),0);

    if (m != 0) {
        var nbj = d.getDate();
        var i,j,o,sel;
    
        if (firstOption === undefined) firstOption = false;
        
        // Elément sélectionné
        sel = document.getElementById(idListDays).options.selectedIndex;
        
        // Vidage de la liste
        if (firstOption)
            document.getElementById(idListDays).length = 1;
        else
            document.getElementById(idListDays).length = 0;
        
        for (i=1;i<=nbj;i++)
        {
           j=i.toString();
           if (j.length<2) { j="0"+j; }
    
           // Création des options
           o = new Option(j,j);
           document.getElementById(idListDays).options[document.getElementById(idListDays).options.length] = o;
        }
    
        // Sélection du jour en cours
        if ( (sel>0) && (document.getElementById(idListDays).options[sel]) )
            document.getElementById(idListDays).options[sel].selected = 1;
    }
    else
        document.getElementById(idListDays).options[0].selected = 1;
}

function ChangeMonth(idListDays, idListMonths)
{
    if (document.getElementById(idListDays).options[document.getElementById(idListDays).selectedIndex].value == 0)
        document.getElementById(idListMonths).options[0].selected = 1;
}

// search and select the current Date
function CurDate(idListDays, idListMonth, firstOption)
{
    d = new Date();
    Mois = 1+d.getMonth();
    chM = Mois.toString();
    if (chM.length<2) { chM="0"+chM; }
    An = d.getFullYear();
    ch = chM+An.toString();
    i = 0;
    while(ch!=document.getElementById(idListMonth).options[i].value) { i++; }
    j = d.getDate();
    if (document.getElementById(idListMonth).options[i]) document.getElementById(idListMonth).options[i].selected = 1;
    if (document.getElementById(idListDays).options[j-1]) document.getElementById(idListDays).options[j-1].selected = 1;
    ShowNbDays(idListDays, idListMonth, firstOption);
}

// open popup
function Calendar(idListDays, idListMonth, baseUrl, length, month, year, firstOption)
{
    j = document.getElementById(idListDays).selectedIndex+1;
    j = j.toString();
    if (j.length<2) { j="0"+j; }
    m = document.getElementById(idListMonth).value.toString();
    d = m.substr(2,4)+m.substr(0,2)+j;
    if (firstOption === undefined) firstOption = false;
    //on passe en paramètre la date en cours
    var h = 133; var w = 130;
    var chParam = "resizable=no, location=no, menubar=no, directories=no, scrollbars=no, status=no, ";
    chParam+='width='+w+', height='+h+', left=200, top=270';
    FenCalend = window.open(baseUrl+ '?d='+d+'&length='+length+'&month='+month+'&year='+year+'&idListDays='+idListDays+'&idListMonth='+idListMonth+'&firstOption='+firstOption, 'FenCalend', chParam);
}
/*** FIN CALENDAR ***/
