// ---------------------------------------------------------------------
// pass selected date to shopping basket page

function datePicked(year,month,day) {
	var fld;
	fld = document.getElementById('AD');
	if (fld == null)
		fld = document.getElementById('TD');
	if (fld == null) {
		alert("datePicked: fld is null");
	}
	else {
		fld.value = year + '-' + month + '-' + day;
		window.document.AskDate.submit();
	}
}

// ---------------------------------------------------------------------
// change product quantity

function incr(ProductCode) {
	fld = document.getElementById(ProductCode);
	if (isNaN(parseInt(fld.value)))
		fld.value = 0;
	fld.value = parseInt(fld.value) + 1;
}

function decr(ProductCode) {
	fld = document.getElementById(ProductCode);
	if (isNaN(parseInt(fld.value)))
		fld.value = 1;
	fld.value = parseInt(fld.value) - 1;
	if (parseInt(fld.value) < 0)
		fld.value = 0;
}

// ---------------------------------------------------------------------
// set text for a form prompt

function set_prompt(field,text) {
	var labels = document.getElementsByTagName('label');
	var fld = null;
	for (i = 0; i < labels.length; i++) {
		if (labels[i].htmlFor == field && labels[i].className == "prompt") {
			labels[i].innerHTML = text;
			break;
		}
	}
	return;
}

// ---------------------------------------------------------------------
// clear search box onfocus

function doClear(theText) {
     if (theText.value == theText.defaultValue)
         theText.value = "";
}

// ---------------------------------------------------------------------
// attach/remove event handlers

function CCaddEvent(newEvent,newFunction,elementName) {
	if (typeof elementName == 'undefined' )
		newElement = window;
	else
		newElement = document.getElementById(elementName);
	if (newElement.addEventListener) { // Firefox method
		newElement.addEventListener(newEvent,newFunction,false);
	} else if (newElement.attachEvent) { // IE method
		newEvent = 'on' + newEvent;
		newElement.attachEvent(newEvent,newFunction);
	} else {
		// no add/attachevent support
	}
}

function CCremoveEvent(obj,event_name,func_name) {
	if (obj.detachEvent) {
		obj.detachEvent("on"+event_name,func_name);
	}
	else if(obj.removeEventListener) {
		obj.removeEventListener(event_name,func_name,true);
	}
	else {
		obj["on"+event_name] = null;
	}
}

// ---------------------------------------------------------------------
// if we have a form and a field, set focus

function SetFocus() {
	var frm = null;
	var i;
	for (i = 0; i < document.forms.length; i++) {
		if (document.forms[i].name == 'SearchForm')
			continue;
		else {
			frm = document.forms[i];
			break;
		}
	}
	if (frm != null) {
		var fld = null;
		for (i = 0; i < frm.elements.length; i++) {
			if (frm.elements[i].readOnly == true)
				continue;
			else {
				fld = frm.elements[i];
				break;
			}
		}
		if (fld != null) {
			if (navigator.userAgent.indexOf("Firefox/1") > -1 ||
				navigator.userAgent.indexOf("Firefox/2") > -1) {
				var bgDiv = document.getElementById('background');
				if (bgDiv != null) {
					bgDiv.style.display = 'none';
					bgDiv.style.width = (document.body.clientWidth - 963) + 'px';
					bgDiv.style.display = 'block';
				}
			}
			fld.focus();
		}
	}
}

// ---------------------------------------------------------------------
// add a bookmark

function AddBookmark(url) {
	title = "Conciergerie.com"; 
	if (window.sidebar) { // Firefox
		alert("To add a bookmark, click OK, then type control-D");
	}
	else if (window.external) { // IE
		window.external.AddFavorite( url, title);
	}
}

// ---------------------------------------------------------------------
// swap visibility of MagicZoom divs

function AltView(idBase) {
	var Photo1DivName = idBase + '1';
	var Photo2DivName = idBase + '2';
	var Div1 = document.getElementById(Photo1DivName);
	var Div2 = document.getElementById(Photo2DivName);
	if (Div1 != null && Div2 != null) {
		if (Div1.style.display == 'block') {
			Div1.style.display = 'none';
			Div2.style.display = 'block';
		}
		else {
			Div2.style.display = 'none';
			Div1.style.display = 'block';
		}
	}
}

// ---------------------------------------------------------------------
// functions to display news line at bottom of homepage

function initNews(numNews) {
	document.getElementById("newsContent0").style.color="rgb(0,0,0)";
	printContent(0, numNews);
}

function fade(eID, colorNum) {
	if (colorNum < 255) { // if color is not white yet
		colorNum += 11; // increase color darkness
		document.getElementById(eID).style.color = "rgb(" + colorNum + "," + colorNum + "," + colorNum + ")";
		setTimeout("fade('" + eID + "', " + colorNum + ")", 10);
	}
	else
		colorNum = 0; //reset couleurTitre value
}

function printContent(i, numNews) {
	document.getElementById("sampleTheme").innerHTML = category[i];
	document.getElementById("sample").innerHTML = content[i];
	fade("newsContent"+i, 0);
	if (i < numNews - 1)
		i++;
	else
		i = 0;
	setTimeout("printContent(" + i + "," + numNews + ")", 5000);
}

// ---------------------------------------------------------------------
// wish list functions

function ShowWishListXsec() {
	ShowWishList("block");
	setTimeout('ShowWishList("none")' ,3000);
}

function ShowWishList(state) {
	var thewishlistspan = document.getElementById("thewishlist");
	if (thewishlistspan != null) {
		var thestyle = thewishlistspan.style;
		if (ltIE7 == false) {
			if (thestyle == null) {
				if (state == "block")
					thewishlistspan.setAttribute("style", "display:block;");
			}
			else {
				if (state == "block")
					thewishlistspan.style.display = "block";
				else
					thewishlistspan.removeAttribute("style");
			}
		}
		else {
			thestyle.display = state;
		}
	}
}

function IE6ShowWishList() {
	var thewishlistspan = document.getElementById("thewishlist");
	if (thewishlistspan != null) {
		var thestyle = thewishlistspan.style;
		if (thestyle == null || thewishlistspan.style.display == "none")
			ShowWishList("block");
		else
			ShowWishList("none");
	}
}

// ---------------------------------------------------------------------
// image rollover functions

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ---------------------------------------------------------------------
// open a new window

function MM_openBrWindow(theURL,winName,features) { //v2.0
  newWindow = Window.open(theURL,winName,features);
  if (window.focus)
   newWindow.focus();
  return false;
}

// ---------------------------------------------------------------------
// accordion/toggler functions

var togglerOpened = '';
var togglersArray = new Array();
togglersArray[1]  = 'overview';
togglersArray[2]  = 'detailed_desc';
togglersArray[3]  = 'faq';
togglersArray[4]  = 'suggestions';
togglersArray[5]  = 'customer_testimonials';
togglersArray[6]  = 'order_options';
togglersArray[7]  = 'cancellation_policy';
togglersArray[8]  = 'menu';
togglersArray[9]  = 'additional_info';
togglersArray[10] = 'more_photos';

function togglerStyle(el_id, arrow_id, action) {
	if (action == "onmouseover" && togglerOpened != el_id) {
		MM_swapImage('arrow'+arrow_id,'',site_root + '/arrow_open_on.gif',el_id,'',site_root + '/bt_'+el_id+'_on_e.gif',1)
	}
	if (action == "onmouseout" && togglerOpened != el_id) {
		for(i=1;i<=togglersArray.length;i++) {
			if(togglersArray[i] == el_id) {
				MM_swapImage('arrow'+i,'',site_root + '/arrow_close.gif',el_id,'',site_root + '/bt_'+el_id+'_off_e.gif',1)
			}
		}
	}
	if (action == "onclick") {
		if (el_id == togglerOpened) { // Already opened ... proceed to close
			MM_swapImage('arrow'+arrow_id,'',site_root + '/arrow_close.gif',el_id,'',site_root + '/bt_'+el_id+'_off_e.gif',1)
			togglerOpened = '';
		} else { // Closed .. proceed to open and close previous one
			for(i=1;i<=togglersArray.length;i++) {
				if(togglersArray[i] == togglerOpened) {
					MM_swapImage('arrow'+i,'',site_root + '/arrow_close.gif',togglerOpened,'',site_root + '/bt_'+togglerOpened+'_off_e.gif',1)
				}
			}
			togglerOpened = el_id;
			MM_swapImage('arrow'+arrow_id,'',site_root + '/arrow_open.gif',el_id,'',site_root + '/bt_'+el_id+'_on_e.gif',1)
		}
	}
}

if (window.addEvent) { // if not, we don't need an accordion anyway
	var accordion = null;
	window.addEvent('load', function() {
		accordion = new Accordion('h3.atStart', 'div.atStart', {
			opacity: true,
			show: 0,
			// show: 'none',
			alwaysHide: true,
			// start: 'all-closed',
			onActive: function(toggler, element) {
				toggler.setStyle('color', '#ff3300');
			},

			onBackground: function(toggler, element) {
				toggler.setStyle('color', '#222');
			}
		}, $('accordion'));
	});
}

// ---------------------------------------------------------------------
// http://www.hunlock.com/blogs/Digg_Style_Videos_For_Your_Blog
// video window functions

function playVid(vidId, noBlackout) {
	if (_vidPane == null) { // find CSS divs
		_vidPane = document.getElementById('vidPane');
		_blackout = document.getElementById('blackout'); // look for div
	}
	_vidPane.style.left = '0px';
	_topMargin = document.body.clientHeight - 430 - 78;
	_vidPane.style.top = _topMargin + 'px';
	if (vidId == null) { // hide the div
		_vidPane.style.display = 'none';
		_vidPane.innerHTML = ''; // purge html to kill video
		_blackout.style.display = 'none'; // hide blackout layer
	}
	else {
		vidId = vidId.href; // get url
		if (!noBlackout)
			_blackout.style.display = 'block'; // make visible
		else
			_blackout.style.display = 'none'; // or hide
		var vidInfo = vidId.split('/'); // split URL: vidInfo[0]=http, [1]=domain, etc
		var vidstring; // build HTML vidstring
		vidstring  = '';
vidstring += "<table class='vidArea' width='541' cellspacing='0' cellpadding='0' align='center'>";
vidstring += "  <tr>";
vidstring += "    <td class='vidHead' colspan='3'></td>";
vidstring += "  </tr>";
vidstring += "  <tr>";
vidstring += "    <td width='17' class='vidLeft'></td>";
vidstring += "    <td class='vidArea' width='507' bgcolor='#f7f5f3' valign='top'>";
vidstring += "      <table class='vidArea' width='468' cellspacing='0' cellpadding='0'>";
vidstring += "        <tr>";
vidstring += "          <td class='vidArea' align='center'>";
vidstring += "            <img class='vidArea' src='" + site_root + "/title_video_e.gif' alt='' ";
vidstring += "            width='507' height='50' border='0' usemap='#close' />";
vidstring += "          </td>";
vidstring += "        </tr>";
vidstring += "        <tr>";
vidstring += "          <td class='vidArea' style='text-align:center;padding:20px 0px 10px 0px;'>";
		vidstring += '<embed ';  
		vidstring += ' enableJavascript="false" allowScriptAccess="never"';
		vidstring += ' allownetworking="internal" type="application/x-shockwave-flash"';
		vidstring += ' wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
		// customze for each service
		if (vidInfo[2].indexOf('youtube.com') >= 0) { // YouTube (use browser URL, autoplays)
			vidInfo = vidId.match(/v=.+$/);
			vidInfo = String(vidInfo).replace(/v=/g,'');
			vidstring += ' src="http://www.youtube.com/v/'+vidInfo+'&autoplay=1" ';
			vidstring += ' height="350" width="425"></embed>';
		}
		else if (vidInfo[2].indexOf('video.google.com') >= 0) { // Google (use browser URL, autoplays)
			vidInfo = vidId.match(/docid=.+$/);
			vidInfo = String(vidInfo).replace(/docid=/g,'');
			vidstring += '  src="http://video.google.com/googleplayer.swf?docId='+vidInfo+'&autoplay=1" ';
			vidstring += ' height="350" width=425">';
		}
		else if (vidInfo[2].indexOf('metacafe.com') > 0) { // MetaCafe (use browser URL, autoplays)
			vidInfo = vidId.match(/watch.+$/);
			vidInfo = String(vidInfo).replace(/watch./,'');
			vidInfo = String(vidInfo).replace(/.$/,'');
			vidstring += ' flashVars="playerVars=autoPlay=yes" ';
			vidstring += ' src="http://www.metacafe.com/fplayer/'+vidInfo+'.swf" ';
			vidstring += ' width="400" height="345">';  
		}
		else if (vidInfo[2].indexOf('ifilm.com') >= 0) { // iFilm (use browser URL, autoplays)
			vidInfo = vidId.match(/video.+$/);
			vidInfo = String(vidInfo).replace(/video./,'');
			vidstring += ' flashVars="flvbaseclip='+vidInfo+'&ip=true" ';
			vidstring += ' src="http://ifilm.com/efp" quality="high" name="efp" align="middle" ';
			vidstring += ' width="425" height="350">';  
		}
		else if (vidInfo[2].indexOf('dailymotion.com') >= 0) { // Daily Motion (use EMBED URL, autoplays)
			vidstring += ' src="' + vidId + _cc_daily_vars + '" flashVars="autoStart=1" ';
			vidstring += ' width="425" height="334">';
		}
		else if (vidInfo[2].indexOf('break.com') >= 0) { // Break (use EMBED URL, autoplays)
			vidstring += ' src="'+vidId+'&autoplay=1" ';
			vidstring += ' width="425" height="350">';
		}
		else if (vidInfo[2].indexOf('shoutfile.com') >= 0) { // Shoutfile (use EMBED URL, no autoplay)
			vidstring += ' src="'+vidId+'"';
			vidstring += ' width="400" height="300">';
		}
		else if (vidInfo[2].indexOf('soapbox.msn.com') >= 0) { // MSN Soapbox (use LINK, autoplays)
			vidInfo = vidId.match(/vid=.+$/);
			vidInfo = String(vidInfo).replace(/vid=/g,'');
			vidstring += ' src="http://images.soapbox.msn.com/flash/soapbox1_1.swf" ';
			vidstring += ' flashvars="c=v&ap=true&v='+vidInfo+'" ';
			vidstring += ' height="360" width="412">';
		}
		else if (vidInfo[2].indexOf('atomfilms.com') >= 0) { // AtomFilms (use URL, no autoplay)
			vidInfo = vidId.match(/film\/.+(\.jsp)/);
			vidInfo = String(vidInfo[0]).replace(/film\//g,'');
			vidInfo = String(vidInfo).replace(/\.jsp/g,'');
			vidstring += ' src="http://www.atomfilms.com:80/a/autoplayer/shareEmbed.swf?keyword='+vidInfo+'" ';
			vidstring += ' height="350" width="425" autostart="true">';
		}
		else { // Failed
			vidstring += '></embed><br /><br /><br />Unknown video service</center>';
		} 
		// add common tail
vidstring += "          </embed>";
vidstring += "          </td>";
vidstring += "        </tr>";
vidstring += "";
vidstring += "      </table>";
vidstring += "    </td>";
vidstring += "    <td width='17' class='vidRight'>";
vidstring += "    </td>";
vidstring += "  </tr>";
vidstring += "  <tr>";
vidstring += "    <td class='vidFoot' colspan='3'></td>";
vidstring += "  </tr>";
vidstring += "</table>";
vidstring += "</span>";
vidstring += "<map name='close' id='close' title='Click to close video'>";
vidstring += "<area shape='rect' coords='465,10,495,40' href='#' onclick='return(playVid());' alt='Click to close video' />";
vidstring += "</map>";
		// insert HTML, display video
		_vidPane.innerHTML = vidstring;

		var scrollTop = 0;
		if (ltIE7 == true) { // set Y-position of window in visible clip
			if (document.documentElement && document.documentElement.scrollTop)
				scrollTop = document.documentElement.scrollTop;
			else if (document.body)
				scrollTop = document.body.scrollTop
		}
		_vidPane.style.top = (scrollTop + _topMargin) + 'px';
		_vidPane.style.display = 'block'; // video was hidden, make visible
	}
	return(false); // so browser doesn't do A HREF clicks
}

//........................................................................
// Drag and Grab handlers
// Called automatically when mouse moved after drag event starts

function moveHandler(e) {
	if (e == null) { // get event data if not passed, IE style
		e = window.event
	}
	if ( _dragOK ) { // ok to move object?
	   _savedTarget.style.left = e.clientX-_dragXoffset+'px';	// calculate offset and move it
	   _savedTarget.style.top = e.clientY-_dragYoffset+'px';	// calculate y offset and move it
	   return false;											// so browser doesn't do anything
	}
}

//........................................................................
// called when user releases mouse button after a drag event starts

function cleanup(e) {
	document.onmousemove = null;			// turn off mousemove event
	document.onmouseup = null;				// turn off mouseup event
	_savedTarget.style.cursor = _orgCursor;	// restore cursor
	_dragOK = false;						// turn off global constant
}

//........................................................................
// called when user holds mouse button

function dragHandler(e) {
	var cursorType = '-moz-grabbing';								// set mouse cursor to grabbing hand
	if (e == null) { // get event info if none
		e = window.event;
		cursorType = 'move';
	}
	var target = e.target != null ? e.target : e.srcElement;		// save event object
	if (target.className == "vidFrame") {
		_orgCursor = target.style.cursor;							// save current mouse cursor
		_savedTarget = target;										// remember object we're working with
		target.style.cursor = cursorType;							// change mouse cursor
		_dragOK = true;												// when true, movehandler will move window
		_dragXoffset = e.clientX-parseInt(_savedTarget.style.left);	// remember X offset
		_dragYoffset = e.clientY-parseInt(_savedTarget.style.top);	// remember Y offset
		document.onmousemove = moveHandler;							// call moveHandler() when mouse moves
		document.onmouseup = cleanup;								// call cleanup() when user releases mouse
		return false;												// so browser doesn't do anything
	}
}

//........................................................................
// start event handler
// when mouse is clicked, call dragHandler()	 

document.onmousedown = dragHandler;

// initialize global variables
var _savedTarget = null;	// target layer (effectively vidPane)
var _orgCursor = null;		// original mouse cursor
var _dragOK = false;		// true when we can move the window
var _topMargin = 0;			// distance from top of viewport to top of vidFrame

var _dragXoffset = 0;		// how much we've moved the element
var _dragYoffset = 0;

var _vidPane  = null;		// video layer, defined when video called
var _blackout = null;		// blackout layer, defined when video called

// cc special vars for daily motion
var _cc_daily_vars = "&autoPlay=1&related=0";

// ---------------------------------------------------------------------
