/* Effacement automatique des champs de saisie */ 
function auto_fill(o, i){
 if(i){
  if(o.refv==null)
   o.refv = o.value;
  if(o.value==o.refv)
   o.value='';
   o.select();
 }
 else{
  if(o.value=='')
   o.value=o.refv;
 }
}

/* Comportement boutons */
function _submit(o){
 tmpo = o;
 while(tmpo=tmpo.parentNode){
  if(tmpo.tagName=="FORM")
   tmpo.submit();
 }
 return false;
}

function _reset(o){
 tmpo = o;
 while(tmpo=tmpo.parentNode){
  if(tmpo.tagName=="FORM")
   tmpo.reset();
 }
 return false;
}

/* SOND ouverture popup */
function popen(u, n, w, h, l, t, scroll){
	if(l == "centre") var l = (screen.width - w) / 2;
	if(t == "centre") var t = (screen.height - h) / 2;
 var _pop = window.open(u, n, 'width='+w+', height='+h+', top='+t+', left='+l+', location=no, menubar=no, resizable=0, scrollbars='+scroll+', status=no, toolbar=no, fullscreen=no');
 _pop.focus();
 return false;
}

function popen2(u, n, w, h, l, t, options){
	if(l == "centre") var l = (screen.width - w) / 2;
	if(t == "centre") var t = (screen.height - h) / 2;
 var _pop = window.open(u, n, 'width='+w+', height='+h+', top='+t+', left='+l+', location=no, menubar=no, resizable=0, scrollbars='+scroll+', '+  options + '');
 _pop.focus();
 return false;
}

function windowopen(u, n, w, h, l, t, scroll, resizable, statusbar){
 	if(w > 0 && h > 0)
	{
		if(l == "centre") var l = (screen.width - w) / 2;
		if(t == "centre") var t = (screen.height - h) / 2;
	}
 var _pop = window.open(u, n, 'width='+w+', height='+h+', top='+t+', left='+l+', location=no, menubar=no, resizable='+resizable+', scrollbars='+scroll+', status='+statusbar+', toolbar=no, fullscreen=no');
 _pop.focus();
}

/* Citroen dans le Monde */
function init_world()
{
	document.getElementById("hdnCurrentContinent").value = currentContinent;
	document.getElementById("hdnCurrentCountry").value = currentCountry;
	init_monde(currentContinent, currentCountry);	
}

function setCurrentContinent(i)
{			
	currentContinent = i;
	document.getElementById("hdnCurrentContinent").value = currentContinent;
	setCurrentCountry(-1);
}

function setCurrentCountry(y)
{
	currentCountry = y;
	document.getElementById("hdnCurrentCountry").value = currentCountry;
}

function init_monde(){
 conto = document.getElementById("cont");
 conto.cur = 0;
 acol = conto.getElementsByTagName("A");
 conto.cura = acol[0].parentNode;
 conto.cursa = null;
 for(i=0;i<acol.length;i++){
  acol[i].switch_count = switch_count;
  acol[i].prt = conto;
  acol[i].ind = i;
  acol[i].onclick = function(){  return this.switch_count();}
 }
 if(arguments[0]>=0){ // ouverture d'un continent par défaut
  conto.cur = arguments[0];
  document.getElementById("count"+conto.cur).style.display = "block";
  conto.cura = acol[conto.cur].parentNode;
  conto.cura.className = "on";
 }
 if(arguments[1]>=0){ // ouverture d'un pays par défaut
  conto.cursa = document.getElementById("count"+conto.cur).getElementsByTagName("A")[arguments[1]].parentNode;
  conto.cursa.className = "on";
 }
}

function switch_count(){
setCurrentContinent(this.ind);
 document.getElementById("fiche").className = 'bnone';
 //worldMapImg est definie cote serveur dans ucDetailCountry.ascx.cs
 document.getElementById("fiche").innerHTML = worldMapImg;
 this.prt.cura.className = "off";
 document.getElementById("count"+this.prt.cur).style.display = "none";
 document.getElementById("count"+(this.prt.cur = this.ind)).style.display = "block";
 if(this.prt.cursa!=null){
  this.prt.cursa.className = "off";
  this.prt.cursa = null;
 }
 this.prt.cura = this.parentNode;
 this.prt.cura.className = "on";
 return false;
}

/* Selection Panier */
function check_all(o, v){
 tmpo = o;
 while(tmpo=tmpo.parentNode){
  if(tmpo.tagName=="FORM")
   break;
 }
 tmpo = tmpo.getElementsByTagName("INPUT");  
 for(i=0;i<tmpo.length;i++)
  tmpo[i].checked = v;
 return false;
}

/* MP - Réglage hauteur colonnes */
function mp_adjust_height(){
 mxh = 0;
 for(i=0;i<arguments.length;i++)
  mxh = Math.max(mxh, parseInt(document.getElementById(arguments[i]).offsetHeight));
 alert(mxh);
 for(i=0;i<arguments.length;i++)
  document.getElementById(arguments[i]).style.height = mxh + 'px';
}

/* accueil */
var oldprod = null;
var pfirst = null, plast = null;

function init_gamm(){
 pfirst = document.getElementById('gi');
 col = document.getElementById('gamm').getElementsByTagName('A');
 for(i=0;i<col.length;i++)
 {
  if(col[i].className=='empty')
  {
	continue;
  }
  try
  {
	col[i].inf = document.getElementById('gi'+i);
	col[i].gfocus = gfocus;
	col[i].gblur = gblur;
	document.getElementById('gi'+i).onmouseover = function(){window.clearTimeout(plast);}
	document.getElementById('gi'+i).onmouseout = tm_gblur;
	if(col[i].childNodes[0].className!='noaction')
	{
	col[i].onmouseover = gfocus;
	col[i].onmouseout = tm_gblur;
	}
  }
  catch(e)
  {}
 }
}

function gfocus(){
 this.className = "actif";
 window.clearTimeout(plast);
 pfirst.style.visibility = 'hidden';
 if(oldprod!=null){
  if(this==oldprod)
   return;
  else
   oldprod.gblur(0);
 }
 this.inf.style.visibility = 'visible';
 oldprod = this;
}

function gblur(i){
 this.className = "none";
 this.inf.style.visibility = 'hidden';
 window.clearTimeout(plast);
 oldprod = null;
 if(i)
  pfirst.style.visibility = 'visible';
}

function tm_gblur(){
 plast = window.setTimeout("oldprod.gblur(1)", 300);
}

/* Videos */
function fill_vid(u, type, thumb, altimg, w, h, alertMessageR, alertMessageQ, imagePath, qtImage){
 var HTMLvid = '';
 switch(type){
  case "w":
  HTMLvid += '<object id="videowindow" width="'+w+'" height="'+(h+45)+'" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject">'
  + '<param name="autostart" value="true">'
  + '<param name="filename" value="'+u+'">'
  + '<param name="showcontrols" value="true">'
  + '<param name="showstatusbar" value="false">'
  + '<param name="sendplaystatechangeevents" value="true">'
  + '<embed id="videowindow" type="application/x-mplayer2" src="'+u+'" name="videowindow" width="'+w+'" height="'+(h+45)+'" showcontrols=1></embed>'
  + '</object> ';
  break;
  case "r":
  if(detectReal()==false){
   HTMLvid += '<p class="center">'+ alertMessageR + '</p><img width="320" height="240" src="'+ imagePath+ 'video_pict.gif" alt="Video"/>';
   break;
  }
  HTMLvid += '<object id="videowindow" width="'+w+'" height="'+h+'" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">'
  + '<param name="src" value="'+u+'">'
  + '<param name="controls" value="ImageWindow">'
  + '<param name="console" value="one">'
  + '<param name="autostart" value="true">'
  + '<embed src="'+u+'" width="'+w+'" height="'+h+'" nojava=true controls=ImageWindow console=one autostart=false>'
  + '<noembed><p class="center">'+ alertMessageR + '</p><img width="320" height="240" src="'+ imagePath+ 'video_pict.gif" alt="Video"/></noembed>'
  + '</object>';
  HTMLvid += '<br/><object id="videowindow" width="'+w+'" height="45" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">'
  + '<param name="controls" value="ControlPanel">'
  + '<param name="console" value="one">'
  + '<param name="autostart" value="true">'
  + '<embed src="'+u+'" width="'+w+'" height=45 nojava=true controls=ControlPanel console=one>'
  + '<noembed><p class="center">'+ alertMessageR + '</p><img width="320" height="240" src="'+ imagePath+ 'video_pict.gif" alt="Video"/></noembed>'
  + '</object>';
  break;
  
  case "q":
  if(canDetectPlugins()){
   if(detectQuickTime()==false){
    HTMLvid += '<p class="center">'+ alertMessageQ + '</p><img width="320" height="240" src="'+ imagePath+ 'video_pict.gif" alt="Video"/>';
    break;
   }
  }
  if(u.indexOf("rtsp://")>=0){
  HTMLvid += '<object id="videowindow" width="'+w+'" height="'+(h+16)+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0">'
  + '<param name="src" value="' + qtImage + '">'
  + '<param name="href" value="'+u+'">'
  + '<param name="autoplay" value="true">'
  + '<param name="controller" value="false">'
  + '<param name="type" value="image/x-quicktime">'
  + '<embed id="videowindow" src="' + qtImage + '" href="'+u+'" width="'+w+'" height="'+(h+16)+'" autoplay="true" controller="false" target="myself" type="image/x-quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed>';
	} else{
  HTMLvid += '<object id="videowindow" width="'+w+'" height="'+(h+16)+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0">'
  + '<param name="src" value="'+u+'">'
  + '<param name="autoplay" value="true">'
  + '<param name="controller" value="true">'
  + '<param name="type" value="video/quicktime">'
  + '<embed id="videowindow" src="'+u+'" width="'+w+'" height="'+(h+16)+'" autoplay="true" controller="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed>';
	}
  HTMLvid += '<noembed><p>'+ alertMessageQ + '</p><img width="320" height="240" src="'+ imagePath+ 'video_pict.gif" alt="Video"/></noembed>'
  + '</object>';
  break;
 }
 
 document.getElementById("vbox").innerHTML = HTMLvid;
 if(thumb!='' && altimg!='')
  document.getElementById(thumb).innerHTML = '<img src="'+altimg+'" alt="" width=133 />';
 return false;
}

// MPR evol v3.2 -- Ajout IFrame dans template TplVideosGallery
function fill_iframe(HTMLIframe, id, altimg){	
	
	document.getElementById("vbox").innerHTML = HTMLIframe;
	// Ajout M. Pressouyre pour image static quand clic flash
	if(id!='' && altimg!='')
	 document.getElementById(id).innerHTML = '<img src="'+altimg+'" alt="" width=133 />'; 
}

function detectReal(){
 var pluginFound = false;
 var activeXFound = false;

 // If this Microsoft Internet Explorer 4.5 for Macintosh, plugins detection is impossible
 if (navigator.appVersion.indexOf("PPC")!=-1 && navigator.userAgent.indexOf("MSIE 4")!=-1)
  return false;

 // Check for Plug-in presence
 plugInFound = getPlugIn("RealPlayer","G2","Plug-In");

 // Check for RealPlayer ActiveX
 try {
  testObject = new ActiveXObject("rmocx.RealPlayer G2 Control.1");

  // Since G2 (Real 6), all Real player version numbers begin by 6
  embedVersion = testObject.GetVersionInfo();
		
  // First version supported : 6.0.6.131 = G2 Gold
  versionArray = embedVersion.split(".");
  conditionA = versionArray[0]>=6;
  conditionB = versionArray[1]>=0;
  conditionC = versionArray[2]>=6;
  conditionD = versionArray[3]>=131;
		
  if (conditionA && conditionB && conditionC && conditionD)
   activeXFound = true;
  else 
   activeXFound = false;
 } catch(e){
  activeXFound = false;
 }
 
 if (plugInFound || activeXFound)
  return true;
 else
  return false;
}

// Parse plugins collection with strings to find
// User has to pass strings to be found in plugin name and description
// Ex. "Shockwave","Flash","5"
function getPlugIn() {
 var allFound = false;
 var plugInsCollection = navigator.plugins;
 for (i=0;i<plugInsCollection.length;i++) {
  // Get plugin description
  plugInDescription = " " + plugInsCollection[i].description;
  plugInName = " " + plugInsCollection[i].name;
  for (j=0;j<arguments.length;j++) {
   if (plugInDescription.indexOf(" " + arguments[j])!=-1 || plugInName.indexOf(" " + arguments[j])!=-1)
    allFound = true;
   else{
    allFound = false;
    break;
   }
  }

  // Send back the search result
  if (allFound){
   return true;
  }
 }
 return false;
}

function init_rolls(){
 theacol = document.getElementById("colD").getElementsByTagName("A");
	for(i=0;i<theacol.length;i++){
   theacol[i].im = theacol[i].getElementsByTagName("IMG")[0];
   theacol[i].roff = theacol[i].im.src;
   theacol[i].ron = theacol[i].roff.substring(0, theacol[i].roff.length-7) + 'on.gif';
   theacol[i].onmouseover = function(){ this.im.src = this.ron;}
   theacol[i].onmouseout = function(){ this.im.src = this.roff;}
  }
}

/* Gestion du Zoom */
//MAJ zopen, match_size, tm_resize, tm_resize_inv en fonction de la maquette 1.1
var _popzoom = null;
var IW = 0, IH = 0, HD = 0;

/* Zoom ouverture popup */
function zopen(u, l, t){
 _popzoom = window.open(u, 'popzoom', 'width=1, height=1, top='+t+', left='+l+', location=no, menubar=no, resizable=1, scrollbars=auto, status=no, toolbar=no, fullscreen=no');
 window.focus();
 _popzoom.blur();
if(navigator.userAgent.indexOf("Firefox") != -1)
{
 var monDiv = _popzoom.document.createElement("div");
 monDiv.innerHTML = "<img src='"+u+"' onclick='window.close()'>"
 _popzoom.document.body.appendChild(monDiv);
}
else 
{
 _popzoom.document.write("<img src='"+u+"' onclick='window.close()'>");
 }
 window.setTimeout("match_size()", 10);
 return false;
}

/* Zoom resize popup */
function match_size(){
 if(!_popzoom){
  window.setTimeout("match_size()", 10);
  return false;
 }
 if(_popzoom.document.images==null){
  window.setTimeout("match_size()", 10);
  return false;
 }
 if(_popzoom.document.images.length==0){
  window.setTimeout("match_size()", 10);
  return false;
 }
 if(_popzoom.document.images[0].complete!=1)
  window.setTimeout("match_size()", 10);
 else{
  _popzoom.document.body.style.margin = 0;
  IW = _popzoom.document.getElementsByTagName('IMG').item(0).offsetWidth;
  IH = _popzoom.document.getElementsByTagName('IMG').item(0).offsetHeight;    
  if((IW<_popzoom.document.body.clientWidth)||(IH<_popzoom.document.body.clientHeight)){
   _popzoom.resizeTo(2000, 2000);
   IW = _popzoom.document.getElementsByTagName('IMG').item(0).offsetWidth;
   IH = _popzoom.document.getElementsByTagName('IMG').item(0).offsetHeight;
   tm_resize_inv();
  }
  else
   tm_resize();
 }
 _popzoom.document.title = "CITROËN";
  return false;
}

function tm_resize(){
 if(document.all){
  _popzoom.resizeBy(IW-_popzoom.document.body.clientWidth, IH-_popzoom.document.body.clientHeight);
  if((IH>_popzoom.document.body.clientHeight)||(IW>_popzoom.document.body.clientWidth))
   window.setTimeout("tm_resize()", 1000);
  else
  _popzoom.focus();
 }
 else{
  _popzoom.resizeBy(IW-_popzoom.innerWidth, IH-_popzoom.innerHeight);
  if((IH>_popzoom.innerHeight)||(IW>_popzoom.innerWidth))
   window.setTimeout("tm_resize()", 1000);
  else
   _popzoom.focus();
 }
}

function tm_resize_inv(){
 _popzoom.resizeTo(IW, IH);
 _popzoom.document.getElementsByTagName('IMG').item(0).style.width = "100%";
 _popzoom.document.getElementsByTagName('IMG').item(0).style.height = "100%";
 _popzoom.focus();
}

function load_img(){
 var l = location.href;
 if((ind = l.indexOf("?i="))>=0)
  imgsrc = l.substring(ind+3, l.length);
 document.body.innerHTML = '<img src="'+imgsrc+'" alt="" title="">'; 
}

function _print(){
 if(window.print)
  window.print();
 return false;
}

function _false(){
 return false;
}

/* SOND fermeture popup */
function pclose(){
 self.close();
 return false;
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// May 17, 2003: Fixed bug in parseDate() for dates <1970
// March 11, 2003: Added parseDate() function
// March 11, 2003: Added "NNN" formatting option. Doesn't match up
//                 perfectly with SimpleDateFormat formats, but 
//                 backwards-compatability was required.

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format,FromPh) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	if(FromPh == 1)
	{
		return newdate;
	}
	else
	{
		return newdate.getTime();
	}
	
	}

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
	}

// initialize global variables
var pluginFound = false;

function canDetectPlugins() {
    if((navigator.plugins && navigator.plugins.length > 0)) {
	return true;
    } else {
	return false;
    }
}
function detectQuickTime() {
    pluginFound = detectPlugin('QuickTime');
    return pluginFound;
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


function PasteAsText( htmlphId )
{
	document.all[htmlphId].insertHtml(window.clipboardData.getData("Text"));
}


function CleanWord( htmlphId )
{
	html = document.all[htmlphId].html;
	
	html = html.replace(/<o:p>\s*<\/o:p>/g, "") ;
	html = html.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
	
	// Remove mso-xxx styles.
	html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;

	// Remove margin styles.
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
	html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
	html = html.replace( /\s*tab-stops:[^"]*/gi, "" ) ;

	// Remove FONT face attributes.
	html = html.replace( /\s*face="[^"]*"/gi, "" ) ;
	html = html.replace( /\s*face=[^ >]*/gi, "" ) ;
	html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
	
	// Remove Class attributes
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	// Remove styles.
	html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;

	// Remove empty styles.
	html =  html.replace( /\s*style="\s*"/gi, '' ) ;
	
	html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
	
	html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
	
	// Remove Lang attributes
	html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	
	html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;
	
	html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;

	// Remove XML elements and declarations
	html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
	
	// Remove Tags with XML namespace declarations: <o:p><\/o:p>
	html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
	
	// Remove comments [SF BUG-1481861].
	html = html.replace(/<\!--.*-->/g, "") ;
	
	html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

	html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
	html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
	html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
	html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
	html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
	html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;

	html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;
	
	html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

	// Remove empty tags (three times, just to be sure).
	html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;

	// Transform <P> to <DIV>
	var re = new RegExp( "(<P)([^>]*>.*?)(<\/P>)", "gi" ) ;	// Different because of a IE 5.0 error
	html = html.replace( re, "<div$2<\/div>" ) ;
	
	// Fix relative anchor URLs (IE automatically adds the current page URL).
	re = new RegExp( window.location + "#", "g" ) ;
	html = html.replace( re, '#') ;

	document.all[htmlphId].html = html;
	
	return html ;
}


