// JavaScript Document

/* changement aleatoire image de fond */
function aleaImg(myId){
    var tabfonds = new Array;
    var nbimgs = 5;
    for(i=1;i<=nbimgs;i++){
        tabfonds[i] = "img/futurevintage/" + i + ".png";
    }
    var aleaNb = Math.round( Math.random() * nbimgs ) + 1;
    if(aleaNb > 5){ aleaNb = 5; }
    if(aleaNb < 1){ aleaNb = 1; }
    document.getElementById(myId).style.background = "url('" + tabfonds[aleaNb] + "') no-repeat";
    fadeIn(myId, 0);
    var launchImg = setTimeout("aleaImg('"+myId+"');", 10000);
}



/* changement image mises en valeur homepage */
var imageNumber = 0;
function changeImg(){
    // itération
    var tabMEV = new Array("1","3","5");
    imageNumber++;

    // affichage
    for(i=0;i<tabMEV.length - 1;i++){
        if(imageNumber == tabMEV.length){ imageNumber = 1; }
        else { imageNumber = imageNumber + 1; }
        
        var myTarget = "mev"+tabMEV[i];
        document.getElementById(myTarget).innerHTML = "<img src='img/home/claim-"+imageNumber+".png' onclick=\"changeImg('"+myTarget+"',"+imageNumber+");\" />";
        fadeIn(myTarget, 0);
    }
}


/* ouverture nouvelle fenetre */
function wo(theURL,winName,features) {
	features = features + "toolbar=no,status=no,resizable=yes,scrollbars=yes";
	window.open(theURL,winName,features);
}


/* montrer/cacher */
function showhide(myid){
	if ( document.getElementById(myid).style.display == "" || document.getElementById(myid).style.display == "none" ) {
		show(myid);
		fadeIn(myid,0);
	} else {
		fadeOut(myid,100);
		hide(myid);
	}
}

function show(myid){
	document.getElementById(myid).style.display="block";
}

function hide(myid){
	document.getElementById(myid).style.display="none";
}

function showmenu(mymenu, myrubrique){
	var adjustx = 0;
	var adjusty = 0;
	if(navigator.appVersion.indexOf("MSIE 7",0)>0){
		adjustx = document.body.offsetWidth/2 - 500;
		adjusty = 50;
	}
	document.getElementById(mymenu).style.left = document.getElementById(myrubrique).offsetLeft + adjustx + "px";
	document.getElementById(mymenu).style.top = document.getElementById(myrubrique).offsetTop + 25 + adjusty + "px";
	show(mymenu);
	fadeIn(mymenu,0);
}


/* verif questionnaires */
function verifQuest(){
	var continu = 1;
	
	alert(continu);
	
	// controle des champs
	if(document.pressRegistration.civility.value == "")				{ continu=0; }
	if(document.pressRegistration.firstname.value == "")			{ continu=0; }
	if(document.pressRegistration.lastname.value == "")				{ continu=0; }
	if(document.pressRegistration.jobtitle.value == "")				{ continu=0; }
	if(document.pressRegistration.email.value == "")				{ continu=0; }
	if(document.pressRegistration.email.value.indexOf("@",0) == -1)	{ continu=0; }
	if(document.pressRegistration.email.value.indexOf(".",0) == -1)	{ continu=0; }
	if(document.pressRegistration.email.value.indexOf(" ",0) == 1)	{ continu=0; }
	if(document.pressRegistration.medianame.value == "")			{ continu=0; }
	if(document.pressRegistration.address.value == "")				{ continu=0; }
	if(document.pressRegistration.zipcode.value == "")				{ continu=0; }
	if(document.pressRegistration.city.value == "")				{ continu=0; }
	if(document.pressRegistration.country.value == "")				{ continu=0; }
	if(document.pressRegistration.phone.value == "")				{ continu=0; }
	
	// controle global et message d'erreur
	if(continu==0){ 
		alert('Warning: please fill every mandatory field properly.'); 
	} else {
		document.pressRegistration.continu.value = 1;
		alert('Thank you for your interest in Denim by Premiere Vision. Your request has been emailed to our team, who will answer ASAP.');
		document.pressRegistration.submit();
	}
}

/* fondus */
function fadeIn(myDiv,myOpacite) {
	var opacitefinal = 100;
	var vitesse = 1;
	var step = 5;
	var oldOpacite = parseInt(myOpacite);
	var newOpacite = oldOpacite + step;
	
	if (newOpacite < opacitefinal) { 
		var startFade = setTimeout("fadeIn('"+myDiv+"',"+newOpacite+")", vitesse);
		if(navigator.appName != "Microsoft Internet Explorer"){
			document.getElementById(myDiv).style.opacity = newOpacite/100;
		} else {
			document.getElementById(myDiv).style.filter = "alpha(opacity:"+newOpacite+")";
		}
	} else {
		clearTimeout(startFade); 
		if(navigator.appName != "Microsoft Internet Explorer"){
			document.getElementById(myDiv).style.opacity = opacitefinal/100;
		} else {
			document.getElementById(myDiv).style.filter = "alpha(opacity:"+opacitefinal+")";
		}
	}
}

function fadeOut(myDiv,myOpacite) {
	var opacitefinal = 0;
	var vitesse = 5;
	var step = 1;
	var oldOpacite = parseInt(myOpacite);
	var newOpacite = oldOpacite - step;
	
	if (newOpacite > opacitefinal) { 
		var endFade = setTimeout("fadeOut('"+myDiv+"',"+newOpacite+")", vitesse);
		if(navigator.appName != "Microsoft Internet Explorer"){
			document.getElementById(myDiv).style.opacity = newOpacite/100;
		} else {
			document.getElementById(myDiv).style.filter = "alpha(opacity:"+newOpacite+")";
		}
	} else {
		clearTimeout(endFade); 
		if(navigator.appName != "Microsoft Internet Explorer"){
			document.getElementById(myDiv).style.opacity = opacitefinal/100;
		} else {
			document.getElementById(myDiv).style.filter = "alpha(opacity:"+opacitefinal+")";
		}
		hide(myDiv);
	}
}


/* creation liste exposants */
var tabExpo = new Array;

function  createlist(myorder){
	myTable 	= tabExpo; 
	myTarget 	= "dynamiclist"; 
	more 		= "more"; 
	
	if(myorder=="company"){
		myTable.sort(sortByCompany);
	} else if (myorder=="sector"){
		myTable.sort(sortBySector);
	} else if(myorder=="country"){
		myTable.sort(sortByCountry);
	} else {
		myTable.sort(sortByCompany);
	}
	
	myList = "\n<table width='100%' cellpadding='20' cellspacing='0' border='0' id='exhibitorslist'><tr>\n";
	myList += "<th><a href=\"javascript:;\" onClick=\"createlist('company');\">v | COMPANY</a></th>\n";
	myList += "<th><a href=\"javascript:;\" onClick=\"createlist('sector');\">v | SECTOR</a></th>\n";
	myList += "<th><a href=\"javascript:;\" onClick=\"createlist('country');\">v | COUNTRY</a></th>\n";
	myList += "</tr>\n";
	for(i=0;i<myTable.length;i++){
		var altern = "";
		if(i%2==0){ altern=" class='multiple'" }
		myMore = "<div id='"+more+i+"' class='more'>";
		myMore += "<a href='javascript:;' onclick=\"fadeOut('"+more+i+"',100);\" class='close'>close | x</a>";
		myMore += "<h3>"+myTable[i]['company']+"</h3>";
		myMore += myTable[i]['address']+"<br />";
		myMore += myTable[i]['country'];
		myMore += "<h4>contact: "+myTable[i]['contact']+"</h4>";
		if(myTable[i]['email']!=""){
			myMore += "email: <a href='mailto:"+myTable[i]['email']+"'>"+myTable[i]['email']+"</a><br />";
		}
		if(myTable[i]['tel']!=""){
			myMore += "tel: "+myTable[i]['tel']+" / ";
		}
		if(myTable[i]['fax']!=""){
			myMore += "fax: "+myTable[i]['fax']+"<br />";
		}
		if(myTable[i]['web']!=""){
			myMore += "web: <a href='http://"+myTable[i]['web']+"' target='_blank'>"+myTable[i]['web']+"</a>";
		}
		myMore += "</div>\n";
		
		var isnew = "";
		if(myTable[i]['isnew']=="1"){
			isnew = "<span class='isnew'>*</span>";
		}
		myList += "<tr><td "+altern+"><a href='javascript:;' onClick=\"showhide('"+more+i+"');\">"+myTable[i]['company'].toUpperCase()+"</a> "+isnew+"<br />"+myMore+"</td><td "+altern+">"+myTable[i]['sector']+"</td><td "+altern+">"+myTable[i]['country']+"</td></tr>\n\n";
	}
	myList += "</table>";
	document.getElementById(myTarget).innerHTML = myList;
}



/* LISTE HOTELS */
var tabHotels = new Array;

function  createlisthotels(myorder){
	myTable 	= tabHotels; 
	myTarget 	= "dynamichotelslist"; 
	
	if(myorder=="rate"){
		myTable.sort(sortByRate);
	} else if (myorder=="time"){
		myTable.sort(sortByTime);
	} else if (myorder=="standard"){
		myTable.sort(sortByStandard);
	} else if (myorder=="area"){
		myTable.sort(sortByArea);
	} else {
		myTable.sort(sortByHotel);
	}
	
	myList = "\n<table width='100%' cellpadding='20' cellspacing='0' border='0' id='exhibitorslist'><tr>\n";
	myList += "<th width='30%'><a href=\"javascript:;\" onClick=\"createlisthotels('area');\">AREA<img src='img/orderlist.gif' alt='order list' border='0' /></a></th>\n";
	myList += "<th width='40%'><a href=\"javascript:;\" onClick=\"createlisthotels('hotel');\">HOTEL<img src='img/orderlist.gif' alt='order list' border='0' /></a></th>\n";
	myList += "<th width='10%'><a href=\"javascript:;\" onClick=\"createlisthotels('rate');\">RATE (&euro;)<img src='img/orderlist.gif' alt='order list' border='0' /></a></th>\n";
	myList += "<th width='10%'><a href=\"javascript:;\" onClick=\"createlisthotels('time');\">TIME <img src='img/orderlist.gif' alt='order list' border='0' /></a></th>\n";
	myList += "<th width='10%'><a href=\"javascript:;\" onClick=\"createlisthotels('standard');\">STANDARD <img src='img/orderlist.gif' alt='order list' border='0' /></a></th>\n";
	myList += "</tr>\n";
	
	for(i=0;i<myTable.length;i++){
		var altern = "";
		var nbstars = parseInt(myTable[i]['standard']);
		var z=0;
		var mystars = "";
		for(z=0;z<nbstars;z++){
			mystars += "<img src='img/star.png' alt='star' />";
		}
		
		if(i%2==0){ altern=" style='background:#222;'" }
		myMore = "<div id='hotelmore"+i+"' class='more'>\n";
		myMore += "<a href='javascript:;' onclick=\"fadeOut('hotelmore"+i+"',100);\" class='close'>close | x</a>\n";
		myMore += "<h3>"+myTable[i]['hotel']+" "+mystars+"</h3>\n";
		myMore += "<p>rate: "+myTable[i]['rate']+" (&euro;)</p>\n";
		myMore += "<p>area: "+myTable[i]['area']+"<br />";
		myMore += "station: "+myTable[i]['station']+"<br />\n";
		myMore += "time: "+myTable[i]['time']+"</p>\n";
		myMore += "<p><a href='http://maps.google.com/?q="+myTable[i]['hotel']+" hotel paris france' target='_blank'>locate this hotel with GoogleMap</a></p>";
		myMore += "</div>\n";
		
		myList += "<tr><td "+altern+" class='expListArea'>"+myTable[i]['area']+"</td>\n";
		myList += "<td "+altern+"><a href='javascript:;' onClick=\"showhide('hotelmore"+i+"');\">"+myTable[i]['hotel']+"</a><br />"+myMore+"</td>\n";
		myList += "<td "+altern+">"+myTable[i]['rate']+"</td>\n";
		myList += "<td "+altern+">"+myTable[i]['time']+"</td>\n";
		myList += "<td "+altern+">"+mystars+"</td></tr>\n";
	}
	myList += "</table>";
	document.getElementById(myTarget).innerHTML = myList;
	document.getElementById("compteur").innerHTML = i+" hotels";
}


/* FONCTIONS DE TRI */
function sortByCompany(a, b) {
	var x = a.order.toLowerCase();
	var y = b.order.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}	
function sortBySector(a, b) {
	var x = a.sector.toLowerCase();
	var y = b.sector.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}	
function sortByCountry(a, b) {
	var x = a.country.toLowerCase();
	var y = b.country.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function sortByHotel(a, b) {
	var x = a.hotel.toLowerCase();
	var y = b.hotel.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function sortByTime(a, b) {
	var x = a.time.toLowerCase();
	var y = b.time.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function sortByStandard(a, b) {
	var x = a.standard.toLowerCase();
	var y = b.standard.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function sortByRate(a, b) {
	var x = a.rate.toLowerCase();
	var y = b.rate.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function sortByArea(a, b) {
	var x = a.area.toLowerCase();
	var y = b.area.toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}


/* ALTERNER LES COULEURS DANS UN TEXTE */
function alternateColors(myid){
	var color1 = "";
	var color2 = "#888";
	var mycontenttable = new Array();
	mycontenttable = document.getElementById(myid).innerHTML.split(", ");
	document.getElementById(myid).innerHTML = "";
	var newcontent = "";
	for(i=0; i<(mycontenttable.length); i++){
		if(i%2==0){
			mycolor = color1;
		} else {
			mycolor = color2;
		}
		newcontent += "<span style='color:"+mycolor+";' class='visitor'>"+mycontenttable[i]+"</span> ";
	}
	document.getElementById(myid).innerHTML = newcontent;
}


/* HOTELS */
var tabHotels = new Array;

tabHotels[0]={num:'0',nom:'Villa Lutèce Port Royal****',adresse:'52-52 bis rue Jenner - 75013 Paris - tel :  01 53 61 90 90',web:'www.villa-lutece-port-royal.com',distance:'1km '};
tabHotels[1]={num:'1',nom:'Hotel La Demeure***',adresse:'51 boulevard Saint Marcel - 75013 Paris - tel : 01 43 37 81 25‎',web:'www.hotel-paris-lademeure.com',distance:'1,3km '};
tabHotels[2]={num:'2',nom:'Hotel La Manufacture***',adresse:'8 rue Philippe de Champaigne - 75013 Paris - tel : 01 70 61 46 86',web:'www.hotel-la-manufacture.com',distance:'1,4km '};
tabHotels[3]={num:'3',nom:'Hotel Résidence Richemont***',adresse:'17  rue Jean Colly - 75013 Paris  - tel : 01 45 82 84 84',web:'www.hotel-richemont.com',distance:'1,5km '};
tabHotels[4]={num:'4',nom:'Hotel le Vert Galant***',adresse:'43 rue Croulebarbe - 75013 PARIS - tel : 01 44 08 83 50',web:'www.vertgalant.com',distance:'1,8km'};
tabHotels[5]={num:'5',nom:'Hotel Saint Charles***',adresse:'6  rue de l’Espérance - 75013 Paris - tel : 01 45 88 56 17',web:'www.hotel-saint-charles.com',distance:'1,9km'};
tabHotels[6]={num:'6',nom:'Best Western Amiral Hotel****',adresse:'98 Avenue d&acute;Italie - 75013 Paris - tel : 01 45 65 13 51',web:'www.amiralhotel.com',distance:'2km '};
tabHotels[7]={num:'7',nom:'Best Western Bercy Rive gauche***',adresse:'82-84 rue Regnault - 75013 Paris - tel : 01 45 85 70 70',web:'www.parishotelbercy.com',distance:'2km '};
tabHotels[8]={num:'8',nom:'The Five Hotel***',adresse:'3 rue Flatters - 75005 Paris - tel : 01 43 31 74 21',web:'www.thefivehotel.com',distance:'2,3km '};
tabHotels[9]={num:'9',nom:'Relais Saint Jacques****',adresse:'3 Rue de l&acute;Abbé de l&acute;Epée - 75005 Paris - tel : 01 70 61 46 86',web:'www.relais-saint-jacques.com',distance:'2,9km '};
tabHotels[10]={num:'10',nom:'Hotel Novanox***',adresse:'155 Boulevard de Montparnasse  - 75006 Paris - tel : 01 43 26 61 72',web:'www.hotel-novanox.com',distance:'3km'};
tabHotels[11]={num:'11',nom:'Le petit paris****',adresse:'214 rue Saint Jacques - 75005 Paris - tel : 01 53 10 29 29',web:'www.hotelpetitparis.com',distance:'3km '};
tabHotels[12]={num:'12',nom:'Le Marceau Bastille-Hotel Gallery***',adresse:'13 rue Jules César - 75012 Paris - tel : 01 70 61 46 86',web:'www.hotelmarceaubastille.com',distance:'3km '};
tabHotels[13]={num:'13',nom:'Le Chaplain Rive Gauche*** ',adresse:'11 bis  rue Jules Chaplain - 75006 Paris - tel : 01 70 61 46 86',web:'www.hotelchaplain.com',distance:'3,7 km'};
tabHotels[14]={num:'14',nom:'Hotel Des Académies et Des Arts***',adresse:'15 rue de la Grande Chaumière - 75006 Paris - tel : 01 70 61 46 86',web:'www.hotel-des-academies.com',distance:'3,7km '};
tabHotels[15]={num:'15',nom:'Hotel color design*** ',adresse:'35 rue Citeaux - 75012 Paris - tel : 01 43 07 77 28',web:'www.colordesign-hotel-paris.com',distance:'4km '};
tabHotels[16]={num:'16',nom:'L&acute;hotel du petit moulin****',adresse:'29-31  rue de poitou - 75003 Paris - tel : 01 42 74 10 10',web:'www.paris-hotel-petitmoulin.com',distance:'4,2km '};
tabHotels[17]={num:'17',nom:'Hotel Aviatic***',adresse:'105 rue de Vaugirard - 75006 Paris - tel : 01 53 63 25 50',web:'www.aviatichotel.com',distance:'4,8km '};
tabHotels[18]={num:'18',nom:'Hotel Gabriel Paris Marais****',adresse:'25 Rue du Grand-Prieuré - 75011 Paris - tel : 01 47 00 13 38 ',web:'www.gabrielparismarais.com',distance:'5,4km '};

function createHotelsList(){
	var hotelsList="";
	for (i=0;i<tabHotels.length;i++){
		hotelsList += "<p>"                                             
		hotelsList += "<strong><a href='http://"+tabHotels[i]['web']+"' target='_blank'>" + tabHotels[i]['nom'] + "</a></strong><br />";
		hotelsList += tabHotels[i]['adresse'] + "<br />";
		hotelsList += "distance: " + tabHotels[i]['distance'];                              
		hotelsList += "</p>";
	}
	document.getElementById("hotelsList").innerHTML = hotelsList;
}


/* liste exposants */
function searchExhibitors(){
    document.exhibitorSearch.isnew.value = 0;
    document.exhibitorSearch.submit();
}

function searchNewExhibitors(){
    document.exhibitorSearch.isnew.value = 1;
    document.exhibitorSearch.submit();
}

