myUtils = {
	makeFrame:function( json ){
		myElmnt = new Element( json.htmlelmt );
		if( json.attributes != null )
			myElmnt.writeAttribute( json.attributes );
		if( json.txtContent != null )
			myElmnt.update( json.txtContent );
		
		return myElmnt; 
	},
	createFrame:function( element , json, where ){
		myElmnt = myUtils.makeFrame( json );
		if( isNull( where ) )
			element.insert( myElmnt );
		else if( where == 'top' )
			element.insert( { top : myElmnt } );
		else if( where == 'bottom' )
			element.insert( { bottom : myElmnt } );
		else if( where == 'before' )
			element.insert( { before : myElmnt } );
		else if( where == 'after' )
			element.insert( { after : myElmnt } );
		
		return myElmnt; 
	},
	updateFrame:function( element , json ){
		myElmnt = myUtils.makeFrame( json );
		element.update( myElmnt );
		return myElmnt; 
	}
};

Element.addMethods( myUtils );

function isSet( mixed ){ return ( typeof( mixed ) != 'undefined' && !isNull( mixed ) ); }
function isNull( mixed ){ return ( mixed == null ); }

Array.prototype.in_array = function(valeur) {
	for (var i in this) { if (this[i] == valeur) return true;}
	return false;
}

function is_array(input){ return typeof( input ) == 'object' && ( input instanceof Array ); }

String.prototype.verifemail = function(){
	var rv = true;
	var emailFormat = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/i;
	if( this.search( emailFormat ) == -1 ){
		rv = false;
	}
	return rv;
}

String.prototype.trim = function( val ) {
	if( isNull( val ) )
		return this.replace( /^\s+/, '' ).replace( /\s+$/, '' );
	else{
		var expDeb = '/^\\'+val+'/';
		var expEnd = '/\\'+val+'$/';
		return this.replace( eval( expDeb ) , '' ).replace( eval(expEnd) , '' );
	}
}

function firstVP( url ){
	var popVP = new popupVF( url );
	popVP.firstVP();
}

function firstVP_V4( url ){
	var popVP = new popupVF_V4( url );
	popVP.firstVP();
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
					((expires) ? "; expires=" + d.toGMTString() : "") +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");

	document.cookie = curCookie;
}

function getCookie(name){
    if(document.cookie.length == 0)
      return null;

    var regSepCookie = new RegExp('(; )', 'g');
    var cookies = document.cookie.split(regSepCookie);

    for(var i = 0; i < cookies.length; i++){
      var regInfo = new RegExp('=', 'g');
      var infos = cookies[i].split(regInfo);
      if(infos[0] == name){
        return unescape(infos[1]);
      }
    }
    return null;
  }


function setCookieLong(name, value, path, domain, secure, duration) {
	var d = new Date();
	d.setTime(d.getTime() + duration*1000);
	var curCookie = name + "=" + escape(value) +
					((d) ? "; expires=" + d.toGMTString() : "") +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function switch_visibility(valeur,div_a_masquer) {
	div = $(div_a_masquer);
	div.style.display = valeur;
}

function cutAndPaste( content ){
	if( isSet( $('pasteItFromDestroyed' ) ) ){
		$('pasteItFromDestroyed').update( content.innerHTML );
	}
}

function switch_input_value_vip(inputamodif,valeur) {
	if( $(inputamodif).value == valeur )
		$(inputamodif).value = '';
}

function switch_input_value( inputamodif ){
	$( inputamodif ).value = '';
}


function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    } else {
    	if (document.documentElement && document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    } else {
     if (document.body && document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;

}

function centrerthepopup(popup){
	var cumulativeoffset = $('page_container').cumulativeScrollOffset();
	var heightPopup = $(popup).getStyle('minHeight');
	var widthPopup = $(popup).getWidth();
	
	var heightScreen = getWindowHeight();
	
	$(popup).setStyle({left: '50%',marginLeft: '-'+widthPopup/2+'px', top: (heightScreen/2)+cumulativeoffset[1]+'px', marginTop: '-'+parseInt(heightPopup)/2+'px'});
	
	
}

