
var win=null;

function NewWindow(mypage,myname,w,h,scroll,pos){

	if(pos=="random"){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}else if((pos!="center" && pos!="random") || pos==null){
		LeftPosition=0;
		TopPosition=20;
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=0,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}

function deleteField( field, value ) {
	if( document.getElementById( field ).value == value ){
		document.getElementById( field ).value = '';
	}
}

/*****************************************************************/
/***************************************************************** MODIFS SEB*****************************************************************/
/* Fonction pour affichage sur fiche produit des infos detaillees*/

function productDetail( productId, infos, link, pageUrl, node )
{
	$links = document.getElementsByClassName( 'product-menu' );
	for ( i = 0; i < $links.length; i++ ){
		$links[ i ].className = 'product-menu';
	}
	link.className = 'product-menu active';

	// Création de l'objet
	var XHR = new XHRConnection();
	// Préparation des variables à envoyer
	XHR.appendData('id','test');

	/*var script = '/bainetspa_fr/product/view/';*/
	var script = pageUrl
	if( infos == null ){
		document.getElementById( 'tabContent' ).innerHTML = '';
	}else{
		document.getElementById( 'product-wait-text' ).style.display = 'block';
		script += '/productid/' + productId + '/infos/' + infos + '/node/' + node;
		XHR.sendAndLoad( script, "POST", productResult );
	}

	return false;
}

// Declaration des fonctions de callback permettant le remplissage des listes
var productResult = function (obj)
{
	document.getElementById( 'product-wait-text' ).style.display = 'none';
	document.getElementById( 'tabContent' ).innerHTML = obj.responseText;

	//Pour que la fenetre redescende sur le contenu
	document.getElementById( 'content' ).focus();
}

/***************************************************************** FIN MODIFS SEB*************************************************************/

/*****************************************************************/
/* Fonction pour affichage des infos clients pro */
function showDiv( type ){
	if ( type == 'particulier' ) {
		document.getElementById('proFieldsHidden').style.display = 'none';
	}else if ( type == 'professionnel' ) {
		var inputProFields = document.getElementsByClassName('proField');
		for ( i=0; i<inputProFields.length; i++ ){
			if ( inputProFields[i].value == "null" ) {
				inputProFields[i].value = "";
			}
		}
		document.getElementById('proFieldsHidden').style.display = 'block';
	}
}

function showSecondDiv( divName, fromUserRegister ){
	if ( document.getElementById( divName ).style.display == 'none' || document.getElementById( divName ).style.display == '' ){
		document.getElementById( divName ).style.display = 'block';

		if ( document.getElementById( 'plus-'+divName ) != null ) {
			document.getElementById( 'plus-'+divName ).innerHTML == '+' ? document.getElementById( 'plus-'+divName ).innerHTML = '-' : document.getElementById( 'plus-'+divName ).className = 'on';
		}
	}else{
		document.getElementById( divName ).style.display = 'none';
		if ( document.getElementById( 'plus-'+divName ) != null ) {
			document.getElementById( 'plus-'+divName ).innerHTML == '-' ? document.getElementById( 'plus-'+divName ).innerHTML = '+' : document.getElementById( 'plus-'+divName ).className = '';
		}
	}

	if( fromUserRegister != null ){
		var Facturation = document.getElementById('infos-facturation');
		var Livraison = document.getElementById('infos-livraison');

		if( Facturation.style.display == 'block' || Facturation.style.display == '' ){
			Facturation.style.display = 'none';
			Livraison.style.display = 'block';
		}else{
			Facturation.style.display = 'block';
			Livraison.style.display = 'none';
		}
	}

}

function userRegister(){

	var arrayOfRequiredProFields = requiredProFields.split( ";" );

	var arrayOfRequiredAddFields = requiredAddFields.split( ";" );

	var typeOfPartnerArray = document.getElementsByName('type');
	var typeOfPartner = '';
	for (var i=0; i<typeOfPartnerArray.length;i++) {
		if (typeOfPartnerArray[i].checked) {
			typeOfPartner = typeOfPartnerArray[i].value;
		}
	}


	if ( typeOfPartner == 'professionnel' ) {
		for ( i=0; i<arrayOfRequiredProFields.length; i++ ){
			var tmp = document.getElementsByName( arrayOfRequiredProFields[i] );
			for ( var j=0; j<tmp.length; j++ ){
				if( tmp[j].value == '' ){
					document.getElementById('pro-error').style.display = 'block';
					return false;
				}
			}
		}
	}

	/*if ( document.getElementById('delivery').checked ) {
		for ( i=0; i<arrayOfRequiredAddFields.length; i++ ){
			var tmp = document.getElementsByName( arrayOfRequiredAddFields[i] );
			for ( var j=0; j<tmp.length; j++ ){
				if( tmp[j].value == '' ){
					document.getElementById('add-error').style.display = 'block';
					return false;
				}
			}
		}
	}*/

	var email = document.getElementById('input-email').value;

	var objLogin = document.getElementById('input-login');
	if( objLogin != null ){
		document.getElementById('input-login').value = email;
		return true;
	}

	return false;
}

/*****************************************************************/
/* Fonction pour deplacer un user vers un nouveau contact*/

function moveUser( userId, userErpId, parentNodeId )
{
	// Création de l'objet
	var XHR = new XHRConnection();
	// Préparation des variables à  envoyer
	XHR.appendData('id','test');
	var script = '/partner/move/';

	script += 'user_id/' + userId + '/user_erp_id/' + userErpId + '/parent_node_id/' + parentNodeId;
	XHR.sendAndLoad( script, "POST", moveUserResult );

	return false;
}

// Declaration des fonctions de callback permettant le remplissage des listes
var moveUserResult = function (obj)
{
	//alert( obj.responseText );
}

/*****************************************************************/
/* Fonction pour accepter ou refuser un user */

function actionToUser( userId, action, message )
{
	if ( confirm( message ) ) {
		if ( typeof( document.getElementById( 'admin-link-user-' + userId ) ) != 'null' ) {
			document.getElementById( 'admin-link-user-' + userId ).style.display = 'none';
			document.getElementById( 'admin-link-user-loading-' + userId ).style.display = 'block';
		}
		// Création de l'objet
		var XHR = new XHRConnection();
		// PrÃ©paration des variables Ã  envoyer
		XHR.appendData('id','test');
		var script = '/partner/admin/';

		script += 'user_id/' + userId + '/action/' + action;
		XHR.sendAndLoad( script, "POST", actionToUserResult );
	}
	return false;
}

// Declaration des fonctions de callback permettant le remplissage des listes
var actionToUserResult = function (obj)
{
	location.reload();
}

/**
 *
 * @access public
 * @return void
 **/
function submitForm( nameOfTheForm, idOfTheInput, nameOfTheButton ){
	document.getElementById( idOfTheInput ).name = nameOfTheButton;
	document.forms[nameOfTheForm].submit();
}