//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2008 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function ControlVersion()
{
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}
	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}
function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }
  document.write(str);
}
function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    
    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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];}
}

var countryurl = Array();

countryurl["all"] = "ourlocations_international.html";
countryurl["Australia"] = "http://www.cpm-aus.com.au/";
countryurl["Austria"] = "http://www.cpmaustria.at/";
countryurl["Belgium"] = "http://www.be.cpm-int.com/";
countryurl["Canada"] = "http://www.cybastevens.com/";
countryurl["France"] = "http://www.fr.cpm-int.com/";
countryurl["Germany"] = "http://www.de.cpm-int.com/";
countryurl["India"] = "http://www.in.cpm-int.com/";
countryurl["Ireland"] = "http://www.ie.cpm-int.com/";
countryurl["Italy"] = "http://www.inventacpm.it/";
countryurl["Netherlands"] = "http://www.nl.cpm-int.com/";
countryurl["Spain"] = "http://www.es.cpm-int.com/";
countryurl["Switzerland"] = "http://www.ch.cpm-int.com/";
countryurl["United Kingdom"] = "http://www.uk.cpm-int.com/";
countryurl["United States"] = "http://www.us.cpm-int.com/";
countryurl["Vietnam"] = "http://www.viravietnam.com/";

var newsdata_a = Array();
var newsdata_b = Array();

newsdata_a[1] = "CPM Celebrates 'Grow Our Own' Success <a href='news_cpm_celebrates_grow_our_own_success.html' class='redlink'>more</a>";
newsdata_a[2] = "CPM Technology Group Goes from Strength to Strength <a href='news_cpm_technology_group_doubles_turnover.html' class='redlink'>more</a>";
newsdata_a[3] = "Dreaming of a Green Christmas <a href='news_dreaming_of_a_green_christmas.html' class='redlink'>more</a>";
newsdata_b[1] = "NLP Boosts CPM Training Success <a href='news_nlp_boosts_cpm_training.html' class='redlink'>more</a>";
newsdata_b[2] = "CPM Employees Front Charity initiative <a href='news_cpm_employees_to_front_charity_initiative.html' class='redlink'>more</a>";
newsdata_b[3] = "CPM's Really Got Talent <a href='news_cpms_got_talent.html' class='redlink'>more</a>";

function menu_toggle(id, action) {
 if (action == 1) {
  document.getElementById('submenu'+id).style.visibility = "visible";
 } else if (action == 0) {
  document.getElementById('submenu'+id).style.visibility = "hidden";
 }
}

function menu_hover(menuid, itemid, action) {
 if (action == 1) {
  document.getElementById('menuitem'+menuid+'_'+itemid).className = "countrymenuitem_lit";
 } else if (action == 0) {
  document.getElementById('menuitem'+menuid+'_'+itemid).className = "countrymenuitem";
 }
}

var DDSPEED = 5;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = ((currh / c.maxh)*0.9);
  c.style.filter = 'alpha(opacity=' + ((currh * 100 / c.maxh)*0.9) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

function menuitem_hl(menuid, itemid, action) {
 if (action == 1) {
  document.getElementById('menuitem'+menuid+'_'+itemid).style.backgroundColor = "#e81701";
  document.getElementById('menuitem'+menuid+'_'+itemid).style.color = "#fff";
 } else if (action == 0) {
  document.getElementById('menuitem'+menuid+'_'+itemid).style.backgroundColor = "";
  document.getElementById('menuitem'+menuid+'_'+itemid).style.color = "#000";
 }
}

function cpm_promise(id, action, no_of_fields) {
 if (action == 1) {
  document.getElementById('cpmpromise_text').innerHTML = text[id];
  for (var i=1;i<=no_of_fields;i++) {
   if (i == id) {
    document.getElementById('hl'+i).style.visibility = 'visible';
   } else {
    document.getElementById('hl'+i).style.visibility = 'hidden';
   }
  }
 } else if (action == 0) {
  document.getElementById('hl'+id).style.visibility = 'hidden';
 }
}

function button_rl(obj, action) {
 if (action == 1) { 
  document.getElementById(obj).style.visibility = 'visible';
 } else if (action == 0) {
  document.getElementById(obj).style.visibility = 'hidden';
 }
}

function image_rl(action) {
 if (action == 1) { 
  document.getElementById("link_moreaboutus").style.visibility = 'visible';
 } else if (action == 0) {
  document.getElementById("link_moreaboutus").style.visibility = 'hidden';
 }
}

function contactform_submit() {
 if ((document.getElementById('name').value == '') && ((document.getElementById('phonenumber').value == '') || (document.getElementById('email').value == ''))) {
  alert('Please provide us with your name, and a means to contact you - either a telephone number, or email address.');
 } else if (document.getElementById('name').value == '') {
  alert('Please provide us with your name.');
 } else if ((document.getElementById('phonenumber').value == '') && (document.getElementById('email').value == '')) {
  alert('Please provide us with a means to contact you - either a telephone number, or email address.');
 } else {
 document.getElementById("contactform").submit();
 }

}

function country_select() {
 window.open(countryurl[document.getElementById("countryselect").value]);
}

function setOpacity(divid,action,value) {

 if (action == 1) {
      document.getElementById(divid).style.opacity = value/10;
      document.getElementById(divid).style.filter = 'alpha(opacity=' + value*10 + ')';
 } else if (action == 0) {
      document.getElementById(divid).style.opacity = (1-(value/10));
      document.getElementById(divid).style.filter = 'alpha(opacity=' + (100-(value*10)) + ')';
 }

}

function setOpacity_div(divid,action) {

 var stagger = 0;
 if (action == 1) {
  stagger = 1000;
 }
 for (var k=0;k<11;k++) {
   setTimeout('setOpacity("'+divid+'",'+action+','+k+')',((50*k)+stagger));
 }
}

var infobox_open = Array();

function rollover_whatwedo(id,action) {

 if ((action == 0) && (infobox_open[id] == 1)) {
 } else {
  if ((action == 1) && (document.getElementById("infobox"+id).style.display == 'block')) {
  } else {
    if (action == 1) {
      document.getElementById("infobox"+id).style.display = 'block';
    } else if (action == 0) {
      setTimeout('document.getElementById("infobox'+id+'").style.display = "none"',500);
    }
    for (var k=0;k<11;k++) {
       setTimeout('setOpacity("infobox'+id+'",'+action+','+k+')',(50*k));
    }
  }
 }

}

function persist_whatwedo(id,action) {
 if (action == 1) {
  infobox_open[id] = 1;
 } else if (action == 0) {
  infobox_open[id] = 0;
  setTimeout('rollover_whatwedo('+id+',0)',500);
 }
}

// function rollover_whatwedo(id,action) {
// 
// if (action == 1) {
//         document.getElementById("whatwedo"+id+"a").style.display = 'none';
// 	document.getElementById("whatwedo"+id+"b").style.display = 'block';
// } else if (action == 0) {
//         document.getElementById("whatwedo"+id+"b").style.display = 'none';
// 	document.getElementById("whatwedo"+id+"a").style.display = 'block';
// }
// 
// }

function tactical_contentupdate(id,currentslide,nextslide) {
        document.getElementById("whatwedo"+id+"b").innerHTML = text[id][nextslide];
}

function rollover_teammember(id,action) {

if (action == 1) {
	document.getElementById("teammember"+id).style.visibility = 'visible';
	document.getElementById("image_teammember"+id).style.border = '2px solid #eb3f2b';
	document.getElementById("image_teammember"+id).src = '../images/image_uk_workforus_teammember'+id+'_rl.jpg';
} else if (action == 0) {
	document.getElementById("teammember"+id).style.visibility = 'hidden';
	document.getElementById("image_teammember"+id).style.border = '2px solid #fff';
	document.getElementById("image_teammember"+id).src = '../images/image_uk_workforus_teammember'+id+'.jpg';
}

}

function rollover_teammemberphoto(id,siteid,action) {

if (action == 1) {
	document.getElementById("teammember"+id).style.visibility = 'visible';
	document.getElementById("image_teammember"+id).style.border = '2px solid #eb3f2b';
	document.getElementById("image_teammember"+id).src = 'contentimages/'+siteid+'/'+teammemberimage_hl[id];
} else if (action == 0) {
	document.getElementById("teammember"+id).style.visibility = 'hidden';
	document.getElementById("image_teammember"+id).style.border = '2px solid #fff';
	document.getElementById("image_teammember"+id).src = 'contentimages/'+siteid+'/'+teammemberimage_normal[id];
}

}

function rollover_contact(id,action) {

if (action == 1) {
	// document.getElementById("image_talktous0"+id).src = "../images/image_talktous0"+id+"b.jpg";
} else if (action == 0) {
	// document.getElementById("image_talktous0"+id).src = "../images/image_talktous0"+id+"a.jpg";
}

}

function news_update(position) {
	setTimeout('setOpacity_div("news_a",0);',5000);
	setTimeout('setOpacity_div("news_b",0);',5000);
	setTimeout('document.getElementById("news_a").innerHTML = "'+newsdata_a[position]+'";',5500);
	setTimeout('document.getElementById("news_b").innerHTML = "'+newsdata_b[position]+'";',5500);
	if (position == 3) { position = 0; }
	setTimeout('setOpacity_div("news_a",1)',5000);
	setTimeout('setOpacity_div("news_b",1)',5000);
	setTimeout('news_update('+(position+1)+');',8000);
}

function cycle_quotes(position) {
	setTimeout('setOpacity_div("quote",0);',5000);
	setTimeout('document.getElementById("quote_image").src = "../contentimages/'+siteid+'/'+quoteimage[position]+'";',5500);
	setTimeout('document.getElementById("quote_text").innerHTML = "'+quotedata[position]+'";',5500);
	setTimeout('document.getElementById("quote_author").innerHTML = "'+quoteauthor[position]+'";',5500);
	// alert(quotedata[position]);
	if (position == (quotedata.length-1)) { position = 0; }
	setTimeout('setOpacity_div("quote",1)',5000);
	setTimeout('cycle_quotes('+(position+1)+');',8000);
}

function directions_popup(location) {
  window.open("directions_"+location+".html", "directions", "status=1,width=365,height=600,resizable=0");
}

function subscription_popup() {
  window.open("subscriptionform.html", "subscription", "scrollbars=1,status=1,width=700,height=600,resizable=0");
}

function menu_control(menuid, submenuid) {

  var id;

  if (submenuid == 0) {
    id=menuid;
  } else {
    id=menuid+"_"+submenuid;
  }
  // var bullet_image_src = document.getElementById("bullet"+id).src.split("/");
  // if (bullet_image_src[(bullet_image_src.length-1)] == "bullet_default.png") {
  //  document.getElementById("bullet"+id).src = "../images/bullet_open.png";
  // } else if (bullet_image_src[(bullet_image_src.length-1)] == "bullet_open.png") {
  //  document.getElementById("bullet"+id).src = "../images/bullet_default.png";
  // }
  animatedcollapse.toggle("menu"+id);

}
