var defaultEmptyOK = true
// decimal point character differs by language and culture
var decimalPointDelimiter = "."

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (sChar)
{   return ((sChar >= "0") && (sChar <= "9"))
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters are numbers; 
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true 
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function DayInMonth( iMonth , iYear ) {

if (iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12) {
	return 31;
}
else {
	if (iMonth == 2) {
		if (iYear%4 == 0) {
			return 29;
		}
		else {
			return 28;
		}
	}
	else {
		return 30;
	}
}
}

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}



// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = s.valueOf();
    return ((num >= a) && (num <= b));
}



// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg) && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

// isMonth (STRING s [, BOOLEAN emptyOK])
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}



// isDay (STRING s [, BOOLEAN emptyOK])
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s, iDayInMonth) { 
   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
	return isIntegerInRange (s, 1, iDayInMonth);
}



// isYear (STRING s [, BOOLEAN emptyOK])
// 
// isYear returns true if string s is a valid 
// Year number.  Must be 2 or 4 digits only.
// 
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// And yes, this function is not Year 10000 compliant, but 
// because I am giving you 8003 years of advance notice,
// I don't feel very guilty about this ...
//
// For B.C. compliance, write your own function. ;->
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return false;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    if (s < 1901 || s > 2078) return false;
    return (s.length == 4);
}

function isInteger(sInteger){
	var iForNext;
	
   // Search through string's characters one by one
   // until we find a non-numeric character.
   // When we do, return false; if we don't, return true.

   for (iForNext = 0; iForNext < sInteger.length; iForNext++) {   
      // Check that current character is number.
      var sCaracter = sInteger.charAt(iForNext);

      if (!isDigit(sCaracter)) {
			return false;
      }
   }

   if (sInteger < 0 || sInteger > 2147483647) {
		return false;
   }

   return true;
}

function isByte(sByte){
	var iForNext;
	
   // Search through string's characters one by one
   // until we find a non-numeric character.
   // When we do, return false; if we don't, return true.

   for (iForNext = 0; iForNext < sByte.length; iForNext++) {   
      // Check that current character is number.
      var sCaracter = sByte.charAt(iForNext);

      if (!isDigit(sCaracter)) {
			return false;
      }

   }
   
   if (sByte < 0 || sByte > 255) {
		return false;
   }
   return true;
}


// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0) || (trim(s) == ''))
}

//--------------------------------------------------------------------------------------
//
// Purpose   :  The same function as the trim function in VBScript
// Syntax    :  trim( sString )
// Parameter :  sString 
// Return    :  The value of sString without leading and trailing spaces
//
function trim( sString )
{
	var sResult 

	sResult = sString;
	
	iChar = 0;
	
	/* Drop leading spaces */
	while (sResult.charAt(0) == " ")
	{		
		sResult = sResult.substr(1)
	}
	
	/* Drop trailing spaces */
	while (sResult.charAt(sResult.length - 1) == " ")
	{
		sResult = sResult.substr(0,sResult.length - 1)
	}				

	/* if the sString contain only spaces, sResult return 0 */
	if ((sResult == 0) && (sString != "0"))
	{
		sResult = "";				
	}

	return sResult
}

//--------------------------------------------------------------------------------------
//
// Purpose   :  The same function as the trim function in VBScript
// Syntax    :  trim( sString )
// Parameter :  sString 
// Return    :  The value of sString without leading and trailing spaces
//
function isDate( sDate ) {

var iStart = 0;
var sDay = "";
var sMonth = "";
var sYear = "";
var sSeparator = "-./";
var iNext;
var iFor;
var iVar;

for (iNext=0 ; iNext < (sDate.length) ; iNext++) {
	for (iFor=0 ; iFor < (sSeparator.length) ; iFor++) {
		if (sDate.charAt(iNext) == sSeparator.charAt(iFor)) {
			iStart = iNext + 1;
			iNext = sDate.length;
			break;
		}
	}
	iVar = sDate.charAt(iNext);
	sDay += iVar.toString();
}

for (iNext=iStart ; iNext < (sDate.length) ; iNext++) {
	for (iFor=0 ; iFor < (sSeparator.length) ; iFor++) {
		if (sDate.charAt(iNext) == sSeparator.charAt(iFor)) {
			iStart = iNext + 1;
			iNext = sDate.length;
			break;
		}
	}
	iVar = sDate.charAt(iNext);
	sMonth += iVar.toString();
}

for (iNext=iStart ; iNext < (sDate.length) ; iNext++) {
	for (iFor=0 ; iFor < (sSeparator.length) ; iFor++) {
		if (sDate.charAt(iNext) == sSeparator.charAt(iFor)) {
			iNext = sDate.length;
			break;
		}
	}
	iVar = sDate.charAt(iNext);
	sYear += iVar.toString();
}

if (isMonth(sMonth) & isYear(sYear)) {
	if (isDay(sDay,DayInMonth(sMonth.valueOf(), sYear.valueOf()))) {
		return true;
	}
	else return false;
return true;
}
else {
return false;
}
}

function popBox(sTitle, iWidth, iHeight, sFilename)
{
		
	var oBox;
	var sExt;
	var iTop;
	var iLeft;
		
	iWidth = Math.round(iWidth + 25);
	iHeight = Math.round(iHeight + 50);				
		
	iLeft = Math.round((window.screen.width - iWidth) / 2);
	iTop = Math.round((window.screen.height - iHeight) / 2);

	sExt = "toolbar=no,scrollbars=yes,directories=no,menubar=no,width=" + iWidth + ",height=" + iHeight + ",top=" + iTop + ",left=" + iLeft

	oBox = parent.open(sFilename, sTitle, sExt);

	if(oBox != null){

		if (oBox.opener == null){
			oBox.opener = self;
		}

		oBox.focus();
		oBox = null;
	}
}
	
function remoteBox(iWidth, iHeight, sFilename)
{
		
	var oBox;
	var sExt;
	var iTop;
	var iLeft;
	
		
	iWidth = Math.round(iWidth +25);
	iHeight = Math.round(iHeight + 50);				
		
	iLeft = Math.round((window.screen.width - (iWidth +20)));
	iTop = Math.round((window.screen.height - iHeight) / 2);

	sExt = "toolbar=no,scrollbars=no,directories=no,menubar=no,width=" + iWidth + ",height=" + iHeight + ",top=" + iTop + ",left=" + iLeft

	oBox = parent.open(sFilename, "RC", sExt);

	if(oBox !=null){

		if (oBox.opener==null){
			oBox.opener=self;
		}

		oBox.focus();
		oBox = null;

	}
}
	
	

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

var iCurrentTab = 1;

function ChangeTab(iTab)
{
		
	// Changes on the current tab
	document.all.item("TabLink" + iCurrentTab).className = "clsTab";
	document.all.item("DivTabContent" + iCurrentTab).style.visibility = "hidden";
	document.all.item("DivTabContent" + iCurrentTab).style.display = "none";

	document.images.item("OngletCornerLeft" + iCurrentTab).src = "../Images/Tab/BorderTop.gif";
	document.images.item("OngletCornerLeft" + iCurrentTab).width = 4;
	document.images.item("OngletCornerLeft" + iCurrentTab).height = 2;
	document.all.item("OngletDown" + iCurrentTab).style.backgroundImage = "url(../Images/Tab/BorderTop.gif)";
	document.images.item("OngletCornerRight" + iCurrentTab).src = "../Images/Tab/BorderTop.gif";
	document.images.item("OngletCornerRight" + iCurrentTab).width = 4;
	document.images.item("OngletCornerRight" + iCurrentTab).height = 2;


	// Changes on the new current
	document.all.item("TabLink" + iTab).className = "clsTabSelected";
	document.all.item("DivTabContent" + iTab).style.visibility = "visible";
	document.all.item("DivTabContent" + iTab).style.display = "inline";

	document.images.item("OngletCornerLeft" + iTab).src = "../Images/Tab/OngletCornerLeftDownSelect.gif";
	document.all.item("OngletDown" + iTab).style.backgroundImage = "url(../Images/Tab/BackGround.gif)";
	document.images.item("OngletCornerRight" + iTab).src = "../Images/Tab/OngletCornerRightDownSelect.gif";

	// set the current tab
	iCurrentTab = iTab;
}

function showPopUp(sURL, bIsMenuBar, bIsScrollbars, bIsToolbar, bIsResizable, bIsCentered, iWindowLeft, iWindowTop, iWindowHeight, iWindowWidth)
{
	var oBox;
	var sExt;
	var iTop;
	var iLeft;
	
	if (bIsCentered)
	{
		iWidth = Math.round(iWindowWidth + 25);
		iHeight = Math.round(iWindowHeight + 50);				
			
		iLeft = Math.round((window.screen.width - iWindowWidth) / 2);
		iTop = Math.round((window.screen.height - iWindowHeight) / 2);
	}
	else
	{
		iWidth = iWindowWidth;
		iHeight = iWindowHeight;				
			
		iLeft = iWindowLeft;
		iTop = iWindowTop;
	}

	if (bIsToolbar) {sExt = "toolbar=yes,"}
	else {sExt = "toolbar=no,"}

	if (bIsScrollbars) {sExt = sExt + "scrollbars=yes,"}
	else {sExt = sExt + "scrollbars=no,"}

	if (bIsMenuBar) {sExt = sExt + "directories=yes,"}
	else {sExt = sExt + "directories=no,"}

	if (bIsMenuBar) {sExt = sExt + "menubar=yes,"}
	else {sExt = sExt + "menubar=no,"}
	
	if (bIsResizable) {sExt = sExt + "resizable=yes,"}
	else {sExt = sExt + "resizable=no,"}
	

	sExt = sExt + "width=" + iWidth + ",height=" + iHeight + ",top=" + iTop + ",left=" + iLeft

	oBox = parent.open(sURL, null, sExt);

	if(oBox !=null){
/*
		if (oBox.opener==null){
			oBox.opener=self;
		}
*/
		oBox.focus();
		oBox = null;

	}
}

function showFreePopUp(sURL, bIsMenuBar, bIsScrollbars, bIsToolbar, bIsResizable, bIsCentered, iWindowLeft, iWindowTop, iWindowHeight, iWindowWidth)
{
	var oBox;
	var sExt;
	var iTop;
	var iLeft;
	
	if (bIsCentered)
	{
		iWidth = Math.round(iWindowWidth + 25);
		iHeight = Math.round(iWindowHeight + 50);				
			
		iLeft = Math.round((window.screen.width - iWindowWidth) / 2);
		iTop = Math.round((window.screen.height - iWindowHeight) / 2);
	}
	else
	{
		iWidth = iWindowWidth;
		iHeight = iWindowHeight;				
			
		iLeft = iWindowLeft;
		iTop = iWindowTop;
	}

	if (bIsToolbar) {sExt = "toolbar=yes,"}
	else {sExt = "toolbar=no,"}

	if (bIsScrollbars) {sExt = sExt + "scrollbars=yes,"}
	else {sExt = sExt + "scrollbars=no,"}

	if (bIsMenuBar) {sExt = sExt + "directories=yes,"}
	else {sExt = sExt + "directories=no,"}

	if (bIsMenuBar) {sExt = sExt + "menubar=yes,"}
	else {sExt = sExt + "menubar=no,"}
	
	if (bIsResizable) {sExt = sExt + "resizable=yes,"}
	else {sExt = sExt + "resizable=no,"}
	

	sExt = sExt + "width=" + iWidth + ",height=" + iHeight + ",top=" + iTop + ",left=" + iLeft
	var datname = new Date();
	//alert(datname.getTime())
	window.open(sURL, datname.getTime(), sExt);
}


function ShowPage(iPageID)
{
	if (iPageID != 0)
	{
		var sURL = "AdminDefault.asp?PageID=" + iPageID;
		parent.location.replace(sURL);
	}

	return false;
}


function ShowURL(sURL, bIsNewWindow)
{
	if (sURL != "")
	{
		if (bIsNewWindow)
		{	
			window.open(sURL, "_new");
		}
		else
		{
			parent.location.replace(sURL);
		}			
	}

	return false;
}

function PortalSubmitForm(sFormAction)
{
	if (CheckFields())
	{
		document.forms["PortalForm"].FormAction.value = sFormAction;
		document.forms["PortalForm"].submit();
	}
	return false;
}

function PortalRefreshPage(iPageID, sTarget)
{
	document.forms["PortalForm"].PageID.value = iPageID;
	document.forms["PortalForm"].LayoutID.value = 0;
	document.forms["PortalForm"].FormAction.value = "";
	document.forms["PortalForm"].IsChildPage.value = "False";
	document.forms["PortalForm"].ParentLayoutID.value = 0;

	document.forms["PortalForm"].target = sTarget;
	document.forms["PortalForm"].submit();

	return false;
}

function SwapImgRestore()
{ 
  var i,x,a=document.sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
	x.src=x.oSrc;
}

function PreloadImages()
{ 
  var d=document;
  if(d.images)
  { 
	if(!d.p) 
		d.p=new Array();
		
   var i,j=d.p.length,a=PreloadImages.arguments;
   
   for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0)
		{ 
			d.p[j]=new Image; 
			d.p[j++].src=a[i];
		}
	}
}

function FindObj(n, d)
{
	var p,i,x;
  
	if(!d)
	 d=document; 
	
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
   }
   
	if(!(x=d[n])&&d.all)
	 x=d.all[n]; 
	 
	for (i=0;!x&&i<d.forms.length;i++)
	 x=d.forms[i][n];
	 
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
	 x=FindObj(n,d.layers[i].document);
	 
	if(!x && document.getElementById) 
	 x=document.getElementById(n); 
	 
	return x;
}

function SwapImage()
{ 
  var i,j=0,x,a=SwapImage.arguments;
  
  document.sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
   if ((x=FindObj(a[i]))!=null)
   {
	 document.sr[j++]=x; 
	 if(!x.oSrc) 
	  x.oSrc=x.src; 
	 x.src=a[i+2];
	}
}

//--------------------------------------------------------------------------------------
//
// Purpose   :  Select / Unselect all Checkboxes in the custom access control  
// Syntax    :  
// Parameter :  
// Return    :  
var IsAllSelected = false;
function SelectAllCustomAccessControl()
{
	IsAllSelected = !(IsAllSelected);

	for(iTag=0; iTag < document.all.length; iTag++) 
	{    
		if (document.all(iTag).type == 'checkbox')
		{
			sName = document.all(iTag).name;
			sTemp = sName.substr(0,2);
			if (sTemp =='G_') 
			{
				document.all(iTag).checked =IsAllSelected;
			}
		}
	}
	SaveValue();			
}

//--------------------------------------------------------------------------------------
//
// Purpose   :  Select / Unselect all Checkboxes in the channel 
// Syntax    :  
// Parameter :  
// Return    :  
var IsAllChannelSelected = false;
function SelectAllChannels()
{
	IsAllChannelSelected = !(IsAllChannelSelected);

	for(iTag=0; iTag < document.all.length; iTag++) 
	{    
		if (document.all(iTag).type == 'checkbox')
		{
			sName = document.all(iTag).name;
			sTemp = sName.substr(0,2);
			if (sTemp =='C_') 
			{
				document.all(iTag).checked =IsAllChannelSelected;
			}
		}
	}
	SaveChannel();			
}
