﻿

/*******************************************
    Generic DHTML do everything script
By Mark 'Tarquin' Wilton-Jones 28-29/9/2002
Updated 19/10/2004 for event handler bug fix
********************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use

To use:

Insert this into the head of your page:
	<script src="PATH_TO_SCRIPT/dhtmlapi.js" type="text/javascript" language="javascript1.2"></script>

To reference any frame, iframe, form, input, image or anchor (but not link) by its name, or
positioned element by its id in the current document - it can optionally scan through any frameset
structure to find it (searching in frames that have not loaded will cause an error):
theObject = PS_findObj( nameOrIdOfObject[, optional referenceToFrameToStartSearchingIn] );

To change the visibility of a positioned element - true for visible, false for hidden:
PS_changeVisibility( idOfPositionedElement, true/false[, optional referenceToFrameToStartSearchingIn] );

To change the position of a positioned element - true for relative to the document, false for
relative to its current position:
PS_changePosition( idOfPositionedElement, leftOffset, topOffset, true/false[, optional referenceToFrameToStartSearchingIn] );

To change the z-index of a positioned element:
PS_changeZIndex( idOfPositionedElement, z-index[, optional referenceToFrameToStartSearchingIn] );

To change the background colour of a positioned element:
PS_changeBackground( idOfPositionedElement, colour[, optional referenceToFrameToStartSearchingIn] );
You MUST have the background colour set with the inline background-color style, to prevent Gecko
engine and Opera 5 bugs.

To change the display style of any element, if it is supported:
PS_changeDisplay( nameOrIdOfElement, '' or 'block' or 'inline' or 'none'[, optional referenceToFrameToStartSearchingIn] );
Note: IE 4 does not understand 'inline' , so '' should be used. iCab does not understand '', so 'block' should be used.

To change the size of a positioned element:
PS_changeSize( idOfPositionedElement, width, height[, optional referenceToFrameToStartSearchingIn] )

To change the clip of an absolutely positioned element:
PS_changeClip( idOfPositionedElement, leftClip, topClip, bottomClip, rightClip[, optional referenceToFrameToStartSearchingIn] );

To change the contents of a positioned element - also rewrites iframe content if that is
provided as an alternative:
PS_changeContents( idOfPositionedElement, newContents[, optional nameOfIframe[, optional referenceToFrame]] )

To create a new positioned element (after the document has loaded) as a child of the document:
PS_createNew( null, width, newID[, optional referenceToWindowOrFrame] )
Or as a child of an existing positioned element:
PS_createNew( idOfPositionedElement, width, newID[, optional referenceToFrameToStartSearchingIn] )
If the browser can create it, the element will be hidden, will have no contents and may be positioned anywhere.
Use the other functions provided to write the contents and style the element.

To get the value of a particular style for a positioned element ('visibility', 'left', 'top', 'zIndex',
'background', 'display', 'size' and 'clip' permitted):
PS_getStyle( idOfPositionedElement, style[, optional referenceToFrame] )
Or to get the background colour for the document:
PS_getStyle( 'document'[, optional null, referenceToFrame] )
In each case, the style must have been set using inline style syntax or with script. With Opera 6, to get the
background colour for the document before it is set with script, some arbitrary colour style must be set for
the HTML tag in a standard stylesheet, even if that colour is not used by the body. If not set in either
way, or if the browser does not support it, the function assumes defaults. If background colour is set using
the 'background' style, some browsers may return more information than just the colour. Some browsers may
return the hex colour code, not the colour name. Measurements return integers, and assume pixels, even if
other units were used. 'visibility' returns true/false for visible/hidden. 'clip' returns an object with top,
bottom, right, and left properties. 'size' returns an array [width,height].
This line toggles the display style between '' (default) and 'none':
PS_changeDisplay( 'mySpan', PS_getStyle( 'mySpan', 'display' ) ? '' : 'none' );
This line toggles the visbility style between 'visible' and 'hidden':
PS_changeDisplay( 'mySpan', PS_getStyle( 'mySpan', 'visibility' ) ? false : true );

To change the background colour of the document, if supported:
PS_changeBody( colour[, optional referenceToFrame] );

To get the position of a link (or anchor only if the name attribute is set):
arrayXY = PS_getPosition( referenceToTheLinkOrAnchor );

To get the width and height of any window or frame (defaults to the current window):
arrayWidthHeight = PS_getSize([optional referenceToWindowOrFrame]);

To get the scrolling offset of any window or frame (defaults to the current window):
arrayXscrollYscroll = PS_getSize([optional referenceToWindowOrFrame]);

To monitor the position of the mouse:
PS_monitorMouse([optional referenceToYourOwnHandlerFunction]);
From then on, the mouse position will be constantly stored as [xPosition,yPosition] in window.PS_getMouse
If you specify a handler function, that will also be executed when the mouse moves, but will not be
passed any arguments. To cancel this mousemove detection, use:
document.onmousemove = null; if( document.releaseEvents ) { document.releaseEvents( Event.MOUSEMOVE ); }

To find the position of the mouse after a mouse event (not click):
arrayXposYpos = PS_getMouseCoords(firstArgumentPassedToEventHandlerFunction);
For example onmouseover="mouseCoords = PS_getMouseCoords(arguments[0]);"

To get any element that can detect key events to monitor what key was used to
keypress/keydown/keyup/click it (nameOfEvent is in the format 'mousedown'):
PS_monitorKey( referenceToObject, nameOfEvent, referenceToYourOwnHandlerFunction );
Your handler function will be passed four arguments; the first will be the normal argument passed to
handler functions in Netscape browsers, the second will be the key code number, the third will be
the keycode->key mapping provided by String.fromCharCode(). The 'this' keyword will not be available
in your handler function so the forth argument will be the element that triggered the event.

To get any element that can detect mouse events to monitor what mouse button was used
to dblclick/mousedown/mouseup it (nameOfEvent is in the format 'mousedown'):
PS_monitorButton( referenceToObject, nameOfEvent, referenceToYourOwnHandlerFunction );
Your handler function will be passed four arguments; the first will be the normal argument passed to
handler functions in Netscape browsers, the second will be the button code number, the third will be
either 'left' or 'right' depending on which button was used. The 'this' keyword will not be available
in your handler function so the forth argument will be the element that triggered the event.
______________________________________________________________________________________________________*/

function PS_findObj( oName, oFrame, oDoc ) {
    
	if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
	for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
	for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = PS_findObj( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
	if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = PS_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	return null;
}
function PS_changeVisibility( oName, oVis, oFrame ) {
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	//if( theDiv.style ) { theDiv.style.visibility = oVis ? 'visible' : 'hidden'; } else { theDiv.visibility = oVis ? 'show' : 'hide'; }
	if( theDiv.style ) 
	{ 
	    if (oVis==true)
	    {
	        theDiv.style.display = '';
	    }
	    else
	    {
	        theDiv.style.display = 'none';
	    }
	 } 
	 else 
	 { 
	    theDiv.visibility = oVis ? 'show' : 'hide'; 
	 }
}
function PS_changePosition( oName, oXPos, oYPos, oRel, oStylePos, oFrame ) {
    
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	
	if( theDiv.style ) { theDiv = theDiv.style; } var oPix = document.childNodes ? 'px' : 0;
	if( typeof( oXPos ) == 'number' ) { theDiv.left = ( oXPos + ( oRel ? 0 : parseInt( theDiv.left ) ) ) + oPix; }
	if( typeof( oYPos ) == 'number' ) { theDiv.top = ( oYPos + ( oRel ? 0 : parseInt( theDiv.top ) ) ) + oPix; }
	if (oStylePos == false)
	{
    	theDiv.position = "absolute";
	}
	else
	{
	    theDiv.position = "relative";
	}
	
}
function PS_changeZIndex( oName, ozInd, oFrame ) {
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; } theDiv.zIndex = ozInd;
}
function PS_changeBackground( oName, oColour, oFrame ) {
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; } if( typeof( theDiv.bgColor ) != 'undefined' ) {
		theDiv.bgColor = oColour; } else if( theDiv.backgroundColor ) { theDiv.backgroundColor = oColour; }
	else { theDiv.background = oColour; }
}
function PS_changeDisplay( oName, oDisp, oFrame ) {
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; } if( typeof( oDisp ) == 'string' ) { oDisp = oDisp.toLowerCase(); }
	theDiv.display = ( oDisp == 'none' ) ? 'none' : ( oDisp == 'block' ) ? 'block' : ( oDisp == 'inline' ) ? 'inline' : '';
}
function PS_changeSize( oName, oWidth, oHeight, oFrame ) {
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; } var oPix = document.childNodes ? 'px' : 0;
	if( theDiv.resizeTo ) { theDiv.resizeTo( oWidth, oHeight ); }
	theDiv.width = oWidth + oPix; theDiv.pixelWidth = oWidth;
	theDiv.height = oHeight + oPix; theDiv.pixelHeight = oHeight;
}
function PS_changeClip( oName, oLeft, oTop, oBottom, oRight, oFrame ) {
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.clip ) { theDiv = theDiv.clip; theDiv.top = oTop; theDiv.right = oRight; theDiv.bottom = oBottom; theDiv.left = oLeft; }
	if( theDiv.style ) { theDiv.style.clip = 'rect('+oTop+'px '+oRight+'px '+oBottom+'px '+oLeft+'px)'; }
}
function PS_changeContents( oName, oContents, oIframe, oFrame ) {
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { theDiv = new Object(); } if( !oFrame ) { oFrame = window; }
	if( typeof( theDiv.innerHTML ) != 'undefined' ) { theDiv.innerHTML = oContents; }
	else if( theDiv.document && theDiv.document != oFrame.document ) {
		theDiv = theDiv.document; theDiv.open(); theDiv.write( oContents ); theDiv.close(); }
	else if( oIframe && oFrame.frames && oFrame.frames.length && oFrame.frames[oIframe] ) {
		theDiv = oFrame.frames[oIframe].window.document; theDiv.open(); theDiv.write( oContents ); theDiv.close(); }
}
function PS_createNew( oName, oWidth, oNewID, oFrame ) {
	if( document.layers && window.Layer ) {
		var theOldLayer = oName ? PS_findObj( oName, oFrame ) : oFrame ? oFrame : window; if( !theOldLayer ) { return; }
		theOldLayer.document.layers[oNewID] = new Layer( oWidth, theOldLayer );
	} else {
		var theOldLayer = oName ? PS_findObj( oName, oFrame ) : oFrame ? oFrame.document.body : document.body; if( !theOldLayer ) { return; }
		var theString = '<div id="'+oNewID+'" style="position:absolute;width:'+oWidth+'px;visibility:hidden;"></div>';
		if( theOldLayer.insertAdjacentHTML ) { theOldLayer.insertAdjacentHTML('beforeEnd',theString);
		} else if( typeof( theOldLayer.innerHTML ) != 'undefined' ) { theOldLayer.innerHTML += theString; }
	}
}
function PS_getStyle( oName, oStyle, oFrame ) {
	if( oName == 'document' ) {
		var theBody = oFrame ? oFrame.document : window.document;
		if( theBody.documentElement && theBody.documentElement.style && theBody.documentElement.style.backgroundColor ) { return theBody.documentElement.style.backgroundColor; }
		if( theBody.body && theBody.body.style && theBody.body.style.backgroundColor ) { return theBody.body.style.backgroundColor; }
		if( theBody.documentElement && theBody.documentElement.style && theBody.documentElement.style.background ) { return theBody.documentElement.style.background; }
		if( theBody.body && theBody.body.style && theBody.body.style.background ) { return theBody.body.style.background; }
		if( theBody.bgColor ) { return theBody.bgColor; }
		return '#ffffff';
	}
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return null; } if( theDiv.style && oStyle != 'clip' ) { theDiv = theDiv.style; }
	switch( oStyle ) {
		case 'visibility':
			return ( ( theDiv.visibility && !( theDiv.visibility.toLowerCase().indexOf( 'hid' ) + 1 ) ) ? true : false );
		case 'left':
			return ( parseInt( theDiv.left ) ? parseInt( theDiv.left ) : 0 );
		case 'top':
			return ( parseInt( theDiv.top ) ? parseInt( theDiv.top ) : 0 );
		case 'zIndex':
			return ( isNaN( theDiv.zIndex ) ? 0 : theDiv.zIndex );
		case 'background':
			return ( theDiv.bgColor ? theDiv.bgColor : theDiv.background-color ? theDiv.background-color : theDiv.background );
		case 'display':
			return ( theDiv.display ? theDiv.display : '' );
		case 'size':
			if( typeof( theDiv.pixelWidth ) != 'undefined' ) { return [theDiv.pixelWidth,theDiv.pixelHeight]; }
			if( typeof( theDiv.width ) != 'undefined' ) { return [parseInt(theDiv.width),theDiv.parseInt(height)]; }
			if( theDiv.clip && typeof( theDiv.clip.bottom ) == 'number' ) { return [theDiv.clip.right,theDiv.clip.bottom]; }
			return [0,0];
		case 'clip':
			if( theDiv.clip ) { return theDiv.clip; }
			theDiv = ( theDiv.style && theDiv.style.clip ) ? theDiv.style.clip : 'rect()';
			theDiv = theDiv.substr( theDiv.indexOf( '(' ) + 1 ); var theClip = new Object();
			for( var x = 0, y = ['top','right','bottom','left']; x < 4; x++ ) {
				theClip[y[x]] = parseInt( theDiv ); if( isNaN( theClip[y[x]] ) ) { theClip[y[x]] = 0; }
				theDiv = theDiv.substr( theDiv.indexOf( ( theDiv.indexOf( ' ' ) + 1 ) ? ' ' : ( theDiv.indexOf( '	' ) + 1 ) ? '	' : ',' ) + 1 );
			} return theClip;
		default:
			return null;
	}
}
function PS_changeBody( oColour, oFrame ) { if( !oFrame ) { oFrame = window; }
	if( document.documentElement && document.documentElement.style ) {
		oFrame.document.documentElement.style.backgroundColor = oColour; }
	if( document.body && document.body.style ) { oFrame.document.body.style.backgroundColor = oColour; }
	oFrame.document.bgColor = oColour;
}
function PS_getPosition( oLink ) {
	if( oLink.offsetParent ) { for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
		posX += oLink.offsetLeft; posY += oLink.offsetTop; } return [ posX, posY ];
	} else { if( !oLink.x && !oLink.y ) { return [0,0]; } else { return [ oLink.x, oLink.y ]; } }
}
function PS_getSize( oFrame ) {
	if( !oFrame ) { oFrame = window; } var myWidth = 0, myHeight = 0;
	if( typeof( oFrame.innerWidth ) == 'number' ) { myWidth = oFrame.innerWidth; myHeight = oFrame.innerHeight; }
	else if( oFrame.document.documentElement && ( oFrame.document.documentElement.clientWidth || oFrame.document.documentElement.clientHeight ) ) {
		myWidth = oFrame.document.documentElement.clientWidth; myHeight = oFrame.document.documentElement.clientHeight; }
	else if( oFrame.document.body && ( oFrame.document.body.clientWidth || oFrame.document.body.clientHeight ) ) {
		myWidth = oFrame.document.body.clientWidth; myHeight = oFrame.document.body.clientHeight; }
	return [myWidth,myHeight];
}
function PS_getScroll( oFrame ) {
	if( !oFrame ) { oFrame = window; } var scrOfX = 0, scrOfY = 0;
	if( typeof( oFrame.pageYOffset ) == 'number' ) { scrOfY = oFrame.pageYOffset; scrOfX = oFrame.pageXOffset; }
	else if( oFrame.document.documentElement && ( oFrame.document.documentElement.scrollLeft || oFrame.document.documentElement.scrollTop ) ) {
		scrOfY = oFrame.document.documentElement.scrollTop; scrOfX = oFrame.document.documentElement.scrollLeft; }
	else if( oFrame.document.body && ( oFrame.document.body.scrollLeft || oFrame.document.body.scrollTop ) ) {
		scrOfY = oFrame.document.body.scrollTop; scrOfX = oFrame.document.body.scrollLeft; }
	return [scrOfX,scrOfY];
}
function PS_monitorMouse(oFunc) {
	if( document.captureEvents && Event.MOUSEMOVE ) { document.captureEvents( Event.MOUSEMOVE ); }
	window.PS_getMouse = [0,0]; window.MWJstoreFunc = oFunc;
	document.onmousemove = function (e) { window.PS_getMouse = PS_getMouseCoords(e); if( window.MWJstoreFunc ) { window.MWJstoreFunc(); } };
}
function PS_getMouseCoords(e) {
	if( !e ) { e = window.event; } if( !e || ( typeof( e.pageX ) != 'number' && typeof( e.clientX ) != 'number' ) ) { return[0,0]; }
	if( typeof( e.pageX ) == 'number' ) { var xcoord = e.pageX; var ycoord = e.pageY; } else {
		var xcoord = e.clientX; var ycoord = e.clientY;
		if( !( ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || window.navigator.vendor == 'KDE' ) ) {
			if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) {
				xcoord += document.documentElement.scrollLeft; ycoord += document.documentElement.scrollTop;
			} else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
				xcoord += document.body.scrollLeft; ycoord += document.body.scrollTop;
			} } } return [xcoord,ycoord];
}
function PS_monitorKey( oOb, oEvent, oHandler ) {
	if( oOb.captureEvents && Event[oEvent.toUpperCase()] ) { oOb.captureEvents( Event[oEvent.toUpperCase()] ); }
	oOb['on'+oEvent.toLowerCase()] = function (e) { if( !e ) { e = window.event; }
		if( !e ) { return; } var oHandler = this['PS_'+e.type.toLowerCase()], b = e;
		e = ( typeof( e.which ) == 'number' ) ? e.which : ( ( typeof( e.keyCode ) == 'number' ) ? e.keyCode : ( ( typeof( e.charCode ) == 'number' ) ? e.charCode : 0 ) );
		if( oHandler ) { oHandler( b, e, String.fromCharCode( e ), this ); }
	}; oOb['PS_'+oEvent.toLowerCase()] = oHandler;
}
function PS_monitorButton( oOb, oEvent, oHandler ) {
	if( oOb.captureEvents && Event[oEvent.toUpperCase()] ) { oOb.captureEvents( Event[oEvent.toUpperCase()] ); }
	oOb['on'+oEvent.toLowerCase()] = function (e) { if( !e ) { e = window.event; }
		if( !e ) { return; } var oHandler = this['PS_'+e.type.toLowerCase()], b = e;
		if( typeof( e.which ) == 'number' ) { e = e.which; } else { e = e.button; }
		if( oHandler ) { oHandler( b, e, ( ( e < 2 ) ? 'left' : 'right' ), this ); }
	}; oOb['PS_'+oEvent.toLowerCase()] = oHandler;
}
//**********************************************************************************
function PS_changeEnable( oName, oEnbl, oFrame ) {
    
	var theDiv = PS_findObj( oName, oFrame ); if( !theDiv ) { return; }
	//if( theDiv.style ) { theDiv.style.visibility = oVis ? 'visible' : 'hidden'; } else { theDiv.visibility = oVis ? 'show' : 'hide'; }
	if (oEnbl==true)
	    {
	        theDiv.disabled = '';
	    }
	    else
	    {
	        theDiv.disabled = 'disabled';
	    }
	
}

//**********************************************************************************
function PS_completeString(strToComplete,charToUse,direction,maxLength)
    {
        
        if(strToComplete.length >= maxLength){return strToComplete;}
        var complementString = "";
        // building string to use to complete the intitial value
        
        for(var i =0; i < maxLength - strToComplete.length; i++)
        {
        
            complementString += charToUse;
        }
        
        if (direction == 'rigth')
        {
            strToComplete = strToComplete + complementString;
        }
        else
        {
            strToComplete = complementString + strToComplete;
        }
        
        return strToComplete;
        
    }

function ShowColorPicker(butID, textBoxFieldID)
	{
		document.all[textBoxFieldID].value = window.showModalDialog('/ColorPicker/ColorPicker.htm',document.all[textBoxFieldID].value,'dialogHeight:455px;dialogWidth:370px;center:Yes;help:No;scroll:No;resizable:No;status:No;');
		
	}

function DropDownListOnChange(ddlElemID, txtElemID, OthersText, ActionType) 
{
    var ddlElem = PS_findObj(ddlElemID);
    var txtElem = PS_findObj(txtElemID)
	
	if (OthersText == "")
	{
	    PS_changeVisibility(txtElemID,false);
	    return;
	}
	
	if (ActionType == "DisableEnable")
	{
	        
	    if (ddlElem.options(ddlElem.selectedIndex).text == OthersText)
	    {
	        txtElem.disabled = false;
	    }
	    else
	    {
	        txtElem.value = "";
	        txtElem.disabled = true;
	    }
    }
	else
	{
        if (ddlElem.options(ddlElem.selectedIndex).text == OthersText)
	    {
	        PS_changeVisibility(txtElemID,true);
	    }
	    else
	    {
	        txtElem.value = "";
	        PS_changeVisibility(txtElemID,false);
	    }
    }
}

var DGCurrentSelectedRow;
function setDGRowSelected(Row, RowKeyValue)
{
    
    var hdElem = PS_findObj("hdSelectedCampaignID");
    
    if (!DGCurrentSelectedRow)
    {
        DGCurrentSelectedRow = PS_findObj("trSelectedRow");
    }
    
    if (DGCurrentSelectedRow)
    {
        DGCurrentSelectedRow.cells[0].style.backgroundColor="#f8f8f8";
    }
    
    DGCurrentSelectedRow = Row;
    
    Row.cells[0].style.backgroundColor="#ff6666";
    
    hdElem.value = RowKeyValue;
    
}

function periodeSelectChange(Elem, MainID)
{
    
    var lblFrstElem = PS_findObj(MainID+"_lblFirstDate");
    var lblScndElem = PS_findObj(MainID+"_lblSecondDate");
    
    PS_changeVisibility(MainID + "_trFirstDate",false);
    PS_changeVisibility(MainID + "_trSecondDate",false);
    if (Elem.value == "8")
    {
        PS_changeVisibility(MainID + "_trFirstDate", true);
        lblFrstElem.innerHTML = "Le :";
       
    }
    else if (Elem.value == "9")
    {
        PS_changeVisibility(MainID + "_trFirstDate", true);
        PS_changeVisibility(MainID + "_trSecondDate", true);
        lblFrstElem.innerHTML = "Du :";
        lblScndElem.innerHTML = "Au :";
    }
    else
    {
    }
        
}
//**********************************************************************************
function HighlightRow(chkB)    {
 
    xState=chkB.checked;  
             
    if(xState)
        {
          
            chkB.parentElement.parentElement.style.backgroundColor='#ffffcc';
            chkB.parentElement.parentElement.style.color='#cc0033'; 
        }
        else 
        {
            chkB.parentElement.parentElement.style.backgroundColor='#ffffff'; 
            chkB.parentElement.parentElement.style.color='black'; 
        }
}

//**********************************************************************************
function SelectAllCheckboxes(spanChk,strcmp){

    var theBox=spanChk
    xState=theBox.checked;    

     var elm=theBox.form.elements;

      elm=theBox.form.elements;
        for(i=0;i<elm.length;i++)
        
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id && elm[i].id.indexOf(strcmp) != -1  )
            {
                if(elm[i].checked!=xState)
                elm[i].click();
            }
}

//**********************************************************************************
function display(image,name){
	var theImage = new Image();
		theImage.src = image+'?'+new Date().getUTCSeconds();
		theImage.onerror = function(){
			alert("Probleme: Pas d'Image !");
		}

		theImage.onload  = function(){
		var width  = theImage.width;  if(width <100) { width  = 100 };if(width >640) { width  = 640 }
		var height = theImage.height; if(height<100) { height = 100 };if(height>640) { height = 640 }
		theImage.width = width
		var left = Math.round((screen.width - width) / 2);
		var top  = Math.round((screen.height - height) / 2);
		var features = 'top='+top+',left='+left+',width='+width+',height='+height;
		var openWindow = window.open('','display',features);
			with(openWindow.document){
			writeln('<html><head><title>'+name+'</title></head>');
			writeln('<body onload="self.focus()" onblur="self.close()"');
			writeln('style="background-image:url('+image+');');
			writeln('background-repeat:no-repeat;width:'+width+';height:'+height+'">');
		
			writeln('</body></html>');
			close();
			}
		}
			return false;
	}

//**********************************************************************************
function RateMe(ddlobj,imgRating)
{
    var rtImg=PS_findObj(imgRating);
    var objddl=PS_findObj(ddlobj);
    switch (objddl[objddl.selectedIndex].value)
        {
        case "5": { rtImg.src = "/Images/rating/50stars.gif" ;break }
        case "4": { rtImg.src = "/Images/rating/40stars.gif" ;break }
        case "3": { rtImg.src = "/Images/rating/30stars.gif" ;break }
        case "2": { rtImg.src = "/Images/rating/20stars.gif" ;break }
        case "1": { rtImg.src = "/Images/rating/10stars.gif" ;break }
        case "0": { rtImg.src = "/Images/rating/00stars.gif" ;break }
        }
}
//**********************************************************************************
function OpenClose1(Icon,DivID,hdClose)	
{
	var retval='';
	var _hdClose=PS_findObj(hdClose);
	
	if (Icon.src.split('plus').length > 1)//plus//closed
	{
		retval='/Images/Icons/minus.gif';//minus//navopened
		Icon.alt='Cacher..';
		PS_changeVisibility(DivID, true);
		_hdClose.value='0'
	}
	else
	{
		retval='/Images/Icons/plus.gif';//plus//navclosed
		Icon.alt='Montrer..';
		PS_changeVisibility(DivID, false);
		_hdClose.value='1';
	}
    return retval;	
}
    
//**********************************************************************************
function OpenClose(Icon,DivID)	
{
	var retval='';
	
	if (Icon.src.split('plus').length > 1)//plus//closed
	{
		retval='/Images/Icons/minus.gif';//minus//navopened
		Icon.alt='Cacher..';
		PS_changeVisibility(DivID, true);
	}
	else
	{
		retval='/Images/Icons/plus.gif';//plus//navclosed
		Icon.alt='Montrer..';
		PS_changeVisibility(DivID, false);
	}
    return retval;	
}
//**********************************************************************************

function ClearOption(optionNumber,txtOptionName,txtOptionDescription,ddlOptionSort)
{
    var OptName=PS_findObj(txtOptionName+optionNumber);
    var OptDescription=PS_findObj(txtOptionDescription+optionNumber);
    var OptPosition=PS_findObj(ddlOptionSort+optionNumber);
    if (OptName.value!='')
    {
        if(confirm('Etes-vous sûr de vouloir supprimer cette option\n toutes les jointures de cette option avec les formules associées vont être supprimées!'))
        {
    OptName.value='';
    OptDescription.value='';
    OptPosition.value='1';        
        }
    }
}
//**********************************************************************************

function MovetoNext(From,To)
{
    TestKey();
	_From = PS_findObj(From);
	_To=PS_findObj(To);
	
	if(_From.value.length==3)
	{
	    _To.focus;
	    _To.select();
	}
}	
//**********************************************************************************

 function TestKey()
{
    if ((event.keyCode < 48) || (event.keyCode > 57))
    event.keyCode = 0;
}
//**********************************************************************************

function ClasseIPChange(ddlClassType,txtClass)
{
    Classddl = PS_findObj(ddlClassType);
    Classtxt1 = PS_findObj(txtClass+'1');
    Classtxt2 = PS_findObj(txtClass+'2');
    Classtxt3 = PS_findObj(txtClass+'3');
    Classtxt4 = PS_findObj(txtClass+'4');

    switch (Classddl.value)
        {
        case "A": { 
                    Classtxt2.value='*';PS_changeEnable(txtClass+'2',false);
                    Classtxt3.value='*';PS_changeEnable(txtClass+'3',false);
                    Classtxt4.value='*';PS_changeEnable(txtClass+'4',false);
                    break; 
                  }
        case "B": { 
                    PS_changeEnable('txtClass2',true);
                    if(Classtxt2.value=='*') Classtxt2.value='';
                    Classtxt3.value='*';PS_changeEnable(txtClass+'3',false);
                    Classtxt4.value='*';PS_changeEnable(txtClass+'4',false);
                    break; 
                  }
        case "C": { 
                    PS_changeEnable(txtClass+'2',true);
                    if(Classtxt2.value=='*') Classtxt2.value='';
                    PS_changeEnable(txtClass+'3',true);
                    if(Classtxt3.value=='*') Classtxt3.value='';
                    Classtxt4.value='*';PS_changeEnable(txtClass+'4',false);
                    break; 
                  }
        case "S": { 
                    PS_changeEnable(txtClass+'1',true);
                    PS_changeEnable(txtClass+'2',true);
                    if(Classtxt2.value=='*') Classtxt2.value='';
                    PS_changeEnable(txtClass+'3',true);
                    if(Classtxt3.value=='*') Classtxt3.value='';
                    PS_changeEnable(txtClass+'4',true);
                    if(Classtxt4.value=='*') Classtxt4.value='';
                    break; 
                  }
        }

}

//**********************************************************************************

function verifyIP (checkEmpty,txtClass) 
{
    Classtxt1 = PS_findObj(txtClass+'1');
    Classtxt2 = PS_findObj(txtClass+'2');
    Classtxt3 = PS_findObj(txtClass+'3');
    Classtxt4 = PS_findObj(txtClass+'4');
    
    if ((checkEmpty==true) && (Classtxt1.value == '' && Classtxt2.value == '' && Classtxt3.value == '' && Classtxt4.value == '')) return true;
    
    IPvalue= Classtxt1.value + '.' + Classtxt2.value + '.' + Classtxt3.value + '.' + Classtxt4.value;
 
    var ipPattern = /^(\d{1,3})\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/;
    var ipArray = IPvalue.match(ipPattern);

    if(Classtxt1.value == '' || Classtxt2.value == '' || Classtxt3.value == '' || Classtxt4.value == '') return false;
    if(IPvalue == '255.255.255.255' || Classtxt1.value == '0') return false;
    
    for (i = 0; i < 4; i++) {
        thisSegment = ipArray[i];
        if (thisSegment != '*' && thisSegment > 255) return false;
    }

    return true;
}
//**********************************************************************************

 function IconsLookup(){
            var sFeatures, h, w, IconLookup, i
	        h = window.screen.availHeight 
	        w = window.screen.availWidth 
	        sFeatures = "height=" + 600 + ",width=" + h*.80 + ",screenY=" + (h*.30) + ",screenX=" + (w*.33) + ",top=" + (h*.10) + ",left=" + (w*.25) + ",resizable,scrollbars=yes,location=no"
	        IconLookup = window.open("/Chat/IconsLookup.aspx","IconLookup",sFeatures)
            return false;
        }

//**********************************************************************************

function ClearRenfort(RenfortNumber,stxtRenfort,stxtDescription,sddlType)
{

    var RenfortName=PS_findObj(stxtRenfort+RenfortNumber);
    var RenfortDescription=PS_findObj(stxtDescription+RenfortNumber);
    var RenfortType=PS_findObj(sddlType+RenfortNumber);
    if (RenfortName.value!='')
    {
        if(confirm('Etes-vous sûr de vouloir supprimer ce Renfort / Confort\n '))
        {
            RenfortName.value='';
            RenfortDescription.value='';
            RenfortType.value='Renfort';        
        }
    }
    
}
//**********************************************************************************

function ShowHideRenforts(tblRenfort,checked,hdObjectID)
{
    if(PS_findObj(hdObjectID).value!='0')
    {
        if (checked)
            PS_changeVisibility(tblRenfort, true);
        else
            PS_changeVisibility(tblRenfort, false);
    }
}
//**********************************************************************************

function ShowHideSearchArea1(show,hdClosed,tblAdvancedSearch)
{
    if (show==1)
    {
        PS_findObj(hdClosed).value ='0';
        PS_changeVisibility(tblAdvancedSearch, true);
    }
    else
    {
        PS_findObj(hdClosed).value ='1';
        PS_changeVisibility(tblAdvancedSearch, false);
    }    
}
 
 function DropDownCustomValidation(source, args)
 {
    var ddl = PS_findObj(source.controltovalidate);
    var txt = PS_findObj(ddl.dataFld);
        
    if (ddl.value == "")
    {
        args.IsValid = false; 
        return;
    }
    else
    {
        if (txt)
        {
            if (ddl.value == ";###;" && txt.value == "")
            {
                args.IsValid = false;
                return;
            }
        }
    }
    args.IsValid = true;
    
}

function ShowAnnuaireInverse(txtPhoneID)
{
    var Elem = PS_findObj(txtPhoneID)
    
    if (Elem)
    {
        window.open("http://www.infobel.com/fr/france/inverse.aspx?qPhone="+Elem.value+"&amp;SubmitREV=Rechercher&amp;inphCoordType=EPSG")
    }
    else
    {
        Alert("Erreur le système n'a pas pu lire le numèro de téléphone");
    }
}


function IsValidDateEffet(source,args){

    if (isDateLaterThanNow(args.Value)){
        args.IsValid = true;
    }
    else{
        args.IsValid = false;
    }    
}   
function isDateLaterThanNow(dtStr){
    
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
	
	var DateNow = new Date();
	DateNow.setDate(DateNow.getDate()-1);
	var DateEffet = new Date(strYear,strMonth-1,strDay);
    
	if (DateEffet <= DateNow)
	    return false;
		
return true
}
// --------------------------------------------------------------------------------------------------
// function isRibValid()
// calcul/vérification de la validité d'un RIB/RIP (Relevé d'Identité Bancaire/Postale)
// accepte 3 ou 4 arguments
// - 3 arguments :    code banque (numérique)
//                    code guichet (numérique)
//                    numéro de compte (alpha)
//                La fonction retourne alors la clé RIB Calculée
// - 4 arguments :    Clé RIB en plus (numérique)
//                La fonction retourne alors un booleen indiquant si le RIB est valide
//
// Attention : la validité des arguments (code bqe numérique, numéro de compte à 11 caractères, etc ...) n'est pas contrôlée par la fonction.
// --------------------------------------------------------------------------------------------------
function isRIBvalid()
    {
    if (isRIBvalid.arguments.length>=3)
        {
        var bqe=isRIBvalid.arguments[0];
        var gui=isRIBvalid.arguments[1];
        var cpt=isRIBvalid.arguments[2].toUpperCase();
        var tab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        var tab1="123456789123456789234567890123456789".split("");
        while (cpt.match(/\D/) != null)
            cpt=cpt.replace(/\D/, tab1[tab.indexOf(cpt.match(/\D/))]);
        var cp=parseInt    (cpt, 10);
        
        a=bqe%97;
        a=a*100000+parseInt(gui, 10);
        a=a%97;
        a=a*Math.pow(10, 11) + cp;
        a=a%97
        a=a*100;
        a=a%97
        a=97-a;
        if (isRIBvalid.arguments[3] != "")
            {
                if (isRIBvalid.arguments[3] == a)
                {
                    alert("RIB Valide");
                }
                else
                {
                    alert("RIB invalide, la clè calculée est : " + a);
                }
            }
        else
            {
                alert("La clè RIB calculée est :" + a);
            }   
        }
    else
        {
            alert("Imposible de vérifier le RIB, pramètres incorrects!");
        
        }
    }
    
function ValidateRIB()
{
    if (PS_findObj("_txtCodeBanque").value == "")
    {
        alert("Le code banque est obligatoire!");
        PS_findObj("_txtCodeBanque").focus();
        return;
    }
    if (PS_findObj("_txtCodeGuichet").value == "")
    {
        alert("Le code guichet est obligatoire!");
        PS_findObj("_txtCodeGuichet").focus();
        return;
    }
    if (PS_findObj("_txtNumCompte").value == "")
    {
        alert("Le numèro de compte est obligatoire!");
        PS_findObj("_txtNumCompte").focus();
        return;
    }
    
   isRIBvalid(PS_findObj("_txtCodeBanque").value, PS_findObj("_txtCodeGuichet").value, PS_findObj("_txtNumCompte").value,PS_findObj("_txtCle").value);
}

//Begin date validation
////////////////////////////////////////////////////////////////////////
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

function IsValidDate(source,args){

    if (isDate(args.Value)){
        args.IsValid = true;
    }
    else{
        args.IsValid = false;
    }    
}   
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function isEmail(string) {
    if (string.search(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/) != -1)
        return true;
    else
        return false;
}
function isPhone(string) {
    if (string.search(/^(06)((\-\d\d){4}|(\.\d\d){4}|( \d\d){4}|(\d\d){4})/) != -1)
        return true;
    else
        return false;
}
function isPostalCode(string){
    if (string.search(/^\d{5}/) != -1)
        return true;
    else
        return false;
}
function getAge(dtStr){
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
	    if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    
    var bday=parseInt(strDay);
    var bmo=parseInt(strMonth);
    var byr=parseInt(strYr);
    var age;
    var now = new Date();
    tday=now.getDate();
    tmo=(now.getMonth()+1);
    tyr=(now.getFullYear());
    /*if(tmo > bmo){
        age=byr;
        }
    else if (tmo==bmo & tday>=bday){
        age=byr;    
        }
    else{
        age=byr+1;
        }
    age=tyr-age;    */
    age = tyr - byr;  
    return (age);
}


/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
