

var iviDefaultHeight = 640 ;
var iviDefaultWidth = 760 ;
var iviDefaultFeatures = "toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no" ;

var NGchildrenWindow = new Array() ;



function openExtWindow( dest, h, w, n, f )
{
	var hauteur,largeur,nom,features ;
	if ( !h )
		hauteur = iviDefaultHeight ;
	else
		hauteur = h ;
	if ( !w )
		largeur = iviDefaultWidth ;
	else
		largeur = w ;
	if ( !n )
		nom = 'fenetre' ;
	else
		nom = n ;
	features = 'width='+largeur+',height='+hauteur+',';
	if ( !f )
		features += iviDefaultFeatures ;
	else
		features += f ;
	window.open( dest, nom, features ) ;
}

function closeOpener()
{
	if ( top.opener )
		top.opener.close() ;
}

function reloadOpener()
{
	if ( top.opener )
		top.opener.location.reload() ;
//		top.opener.location.href = top.opener.location.href ;
}





function test(content)
{
	alert(content);
	
	return false;
}

function popitup(url, destfield, scrollbars, h, w)
{
	param = "";
	
	if (scrollbars == null || scrollbars == true) param += "scrollbars,"
		
	if (h==null || h=="")
		param += "height=500,";
	else
		param += "height="+h+",";
		
	if (w==null || w=="")
		param += "width=400,";
	else
		param += "width="+w+",";

	newwindow=window.open(url,'name',param);
	
	if (window.focus) {newwindow.focus()}

	return false;
}

function refreshOpenerAndClosePopup()
{
	top.opener.location.href=top.opener.location.href;
	window.close();
}

function setWhatFields( param )
{
	whatfield = param;
}

function simplepopitup(url, scrollbars, h, w)
{
	param = "";
	
	if (scrollbars == null || scrollbars == true) param += "scrollbars,"
		
	if (h==null || h=="")
		param += "height=500,";
	else
		param += "height="+h+",";
		
	if (w==null || w=="")
		param += "width=400,";
	else
		param += "width="+w+",";

//	alert ("popitup(url)" + url);
	newwindow=window.open(url,'popup',param);
	
//	newwindow=window.open(url,'name','scrollbars,height=500,width=400');
	if (window.focus) {newwindow.focus()}
	return false;
}

function chooseFromPopup(param)
{
	var paramArray=param.split("/");
	if ( paramArray.length > 1 )
	{
		for ( i = 0 ; i < paramArray.length ; i++)
			top.opener.storeInField(paramArray[i],i);
	}
	else
		top.opener.storeInField(param);
	
	window.close();
	return false;
}

function chooseFromPopup2(fields, values)
{
	var fieldsArray=fields.split("/");
	var valuesArray=values.split("/");
	if ( valuesArray.length == fieldsArray.length )
	{
		if ( valuesArray.length > 1 )
		{
			for ( i = 0 ; i < valuesArray.length ; i++)
			{
				top.opener.storeValueInField(valuesArray[i],fieldsArray[i]);
			}
		}
	}
	else
		alert ("error : <> fields number");
	
	window.close();
	return false;
}

function chooseFromCal(param)
{
	doc = document.forms[0];
	txt = doc.elements[param].value;
	top.opener.storeInField(txt);
	window.close();
	return false;
}

function storeInField(param, index)
{
	doc = document.forms[0];
	var fieldArray=whatfield.split("/");
	
	if ( index != null )
	{
		if ( fieldArray.length > index )
			doc.elements[fieldArray[index]].value  = param;
	}
	else
		doc.elements[whatfield].value  = param;
//		alert ("sayhello " + param);
}

function storeValueInField( paramValue, paramField )
{
	doc = document.forms[0];
	doc.elements[paramField].value  = paramValue;
}

function confirmDeletionOld(id)
{  
	if (confirm("Are you sure?"))
	{
		if (confirm("Are you really sure?"))
		{
			document.forms[0].deletion.value=id;
			document.forms[0].submit();
		}
	}
   	return false;
}

function confirmDeletion(ids, fields)
{  
	ids = ""+ids;
	if (fields==null || fields=="") fields = "deletion";
	if (confirm("Are you sure?"))
	{
		if (confirm("Are you really sure?"))
		{
			var _ids= ids.split("/");
			var _fields= fields.split("/");
			for ( i = 0 ; i < _ids.length ; i++)
				document.forms[0].elements[_fields[i]].value=_ids[i];
			document.forms[0].submit();
		}
	}
   	return false;
}

function confirmItemDeletion(id, elem)
{  
	if (confirm("Are you sure?"))
	{
		if (confirm("Are you really sure?"))
		{
			elem.value = id;
			document.forms[0].submit();
		}
	}
   	return false;
}

function confirmFeeDeletion(id)
{  
   if (confirm("Are you sure?"))
   {
   if (confirm("Are you really sure?"))
   {
     document.forms[0].feedeletion.value=id;
	  document.forms[0].submit();
   }
   }
   return false;
}

function doReportAction(param)
{
   if (confirm("Are you sure?"))
   {
	document.forms[0].reportaction.value = param;
	document.forms[0].submit();
   }
	return false;
}

function doReappointingAction(param)
{
   if (confirm("Are you sure?"))
   {
	document.forms[0].reappointingaction.value = param;
	document.forms[0].submit();
   }
	return false;
}

function doFeeAction(param)
{
   if (confirm("Are you sure?"))
   {
	document.forms[0].feeaction.value = param;
	document.forms[0].submit();
   }
	return false;
}

function publish(idminute, publishstate)
{  
	if (confirm("Are you sure?"))
	{
		document.forms[0].pubminute.value=idminute;
		document.forms[0].published.value=publishstate;
		document.forms[0].submit();
	}
   	return false;
}

function openDrawer(idminute)
{  
	var _drawers = document.forms[0].pubminute.value;
	var _ids=_drawers.split(",");
	_ids.concat(idminute);
	document.forms[0].pubminute.value = _ids.join();
   	return false;
}

function closeDrawer(idminute)
{  
	var _drawers = document.forms[0].pubminute.value;
	var _ids=_drawers.split(",");
	for ( i = 0 ; i < _ids.length ; i++)
	{
		if ( _ids[i] == idminute )
		{
			_ids.splice(i, 1);
			break;
		}
	}
	document.forms[0].pubminute.value = _ids.join();
   	return false;
}


// Cookies

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

//	document.cookie = name + "=" +escape( value ) +
	document.cookie = name + "=" + value +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
	
// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
		return null;
		
	if ( start == -1 ) return null;
	
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



// Drawer functions

	function checkDrawer( _name, _checked, _id )
	{
		var _drawers = document.forms[0].drawers.value;
		var _arr = _drawers.split(",");
		if ( _checked )
			document.forms[0].drawers.value = addDrawer( _arr, _id );
		else
			document.forms[0].drawers.value = removeDrawer( _arr, _id );
			
		Set_Cookie( _name, document.forms[0].drawers.value) 
		document.forms[0].action += "#m" + _id;
		document.forms[0].submit();
		
		return false;
	}
	
    function addDrawer( _arr, _id )
    {
		if ( findDrawer( _arr, _id ) < 0 )
			_arr.unshift( _id );
		return _arr.join(",");
    }
	
    function removeDrawer( _arr, _id )
    {
		var _pos = findDrawer( _arr, _id )
		if ( _pos >= 0 )
			_arr.splice( _pos, 1 );
		return _arr.join(",");
    }
	
    function findDrawer( _arr, _id )
    {
		for ( var _i = 0 ; _i < _arr.length ; _i ++ )
			if ( _arr[_i] == _id )
				return _i;
		return -1;
    }
    
    
    
    // Struts tools
    
    function doRecDelete(aBase,aItem) {
 		if (confirm("Are you sure?"))
			if (confirm("Are you really sure?"))
  				location.href = aBase + '&id=' + aItem; 
    } 
    
    function doItem(aBase,aItem) {
 		if (confirm("Are you sure?"))
			if (confirm("Are you really sure?"))
  				location.href = aBase + '&id=' + aItem; 
  //   HC_doOpenRemote(aBase + '?id=' + aItem,'preview','*','600','scrollbars','form'); 
    } 
    
function submitSave( theform, doaction)
{
	if (doaction == null) doaction = 'save';
	theform.elements["do"].value = doaction;
}

function submitContactSave( theform, doaction)
{
	if( theform.elements["password"].value == theform.elements["confpassword"].value )
		submitSave( theform, doaction);
	else
	{
		alert( "Password and Confirmation should be the same!" );
		return false;
	}
}

function submitDelete( theform, doaction)
{
	if (doaction == null) doaction = 'delete';
	if (confirm("Are you sure?"))
	{
		if (confirm("Are you really sure?"))
			theform.elements["do"].value = doaction;
		else
			return false;
	}
	else
		return false;
}


function selectMeFromOther ( theOther, theSelect )
{
	for ( var i = 0 ; i < theSelect.length ; i++ )
		theSelect[i].selected = false ;
	var _listOfVals = theOther.options[theOther.options.selectedIndex].value.split("/");
	for ( var j = 1 ; j < _listOfVals.length ; j++ )
	{
		var val = _listOfVals[j];
		for ( var i = 0 ; i < theSelect.length ; i++ )
			if ( theSelect[i].value == val ) 
				theSelect[i].selected = true ;
	}
}

function changeOtherFromMe ( theOther, theSelect )
{
	var _listOfVals = theOther.options[theOther.options.selectedIndex].value.split("/");
	var _idOther = _listOfVals[0];
	
	for ( var i = 0 ; i < theSelect.length ; i++ )
	{
		if(theSelect[i].selected)
			_idOther += "/" + theSelect[i].value;
	}
	theOther.options[theOther.options.selectedIndex].value = _idOther;
}

function getValuesAndStoreInHidden ( theSelect, theHidden, theForm )
{
	var theReturn = "";
	for ( var i = 0 ; i < theSelect.length ; i++ )
	{
		if(theReturn == "")
			theReturn = theSelect[i].value;
		else
			theReturn += "*" + theSelect[i].value;
	}
	theHidden.value = theReturn;
	if (doaction == null) doaction = 'save';
	theForm.elements["do"].value = doaction;
}


function setTo ( theForm, theid, thename )
{
	theForm.mediaid.value = theid;
	theForm.filename.value = thename;
	window.close();
}


