function maxlength(this_field)
{
	if(this_field.length > 350)
	{
		this_field.style = "border:1px solid red;";
	}
	else
	{
		this_field.style = "border:1px solid #A5B85F;";
	}
	
}

function rollOver(which)
{ 
	which.src = which.src.replace("_of","_ov"); 
}

function rollOut(which)
{ 
	which.src = which.src.replace("_ov","_of"); 
}

function fill_field(visible_field, visible_value, hidden_field, hidden_value, list_to_hide)
{
	document.getElementById(visible_field).value = visible_value;
	document.getElementById(hidden_field).value = hidden_value;
	show_hide_layer(document.getElementById(list_to_hide), 'hide');
}

function lost_focus(has_focus, this_layer)
{
	switch(has_focus)
	{
		case false:
			clearTimeout(my_timer);
		break;
		
		case true:
			my_timer = setTimeout("show_hide_layer(document.getElementById('"+this_layer+"'),'hide', 'none')", 2500);
		break;
	}
}

function show_hide_layer(this_layer, action)
{
	switch(action)
	{
		case 'show':
			this_layer.style.display = 'block';
			if(this_layer.id == 'seasonfilter')
			{
				document.getElementById('h_seasonfilter').disabled = false;
			}
		break
		
		case 'hide':
			this_layer.style.display = 'none';
			if(this_layer.id == 'seasonfilter')
			{
				document.getElementById('h_seasonfilter').disabled = true;
			}
		break;
	}
}

function show_list(thislist)
{
	lists_arr = new Array('product_filter_list')
	//alert(document.getElementById('size_list').style.display);
	if(document.getElementById(thislist))
	{
		objStyle = document.getElementById(thislist).style;
	}
	
	for(i=0; i<lists_arr.length; i++)
	{
		if(thislist == lists_arr[i] && objStyle.display != 'block')
		{
			document.getElementById(thislist).style.display = 'block';
		}
		
		else
		{
			document.getElementById(lists_arr[i]).style.display = 'none';
		}
	}
}

function add_grey_line(listID)
{
	var array_li = document.getElementById(listID).getElementsByTagName('li');
	var count = array_li.length;
	var impair=1;
	
	for(var i=0;i<count;i++){
		if(impair==1){
			array_li[i].className = "impair";
			impair=0;
		}else{
			impair=1;
		}
	}
}

function add_blue_line(listID, currentURL)
{
	var array_li = document.getElementById(listID).getElementsByTagName('li');
	var count = array_li.length;

	for(var i=1;i<count;i++){
		if(array_li[i].getElementsByTagName('a')[0].href==currentURL){
			array_li[i].style.backgroundColor='#cee1ec';
		}
	}
}

function add_tracking_tag(listID)
{
	var array_li = document.getElementById(listID).getElementsByTagName('li');
	var count = array_li.length;

	for(var i=1;i<count;i++){
		catName = array_li[i].getElementsByTagName('a')[0].innerHTML;
		array_li[i].getElementsByTagName('a')[0].onclick = function() {cmCreatePageviewTag("blog", catName, "select");}
	}
}

function add_selected(thislink, action)
{
	switch(action)
	{
		case 'add':
			if(thislink.className.search('selected') == -1)
			{
				thislink.className = thislink.className + ' selected';
			}
		break;
		
		case 'remove':
				thislink.className = thislink.className.replace('selected', '');
		break;
	}
}

//Semble ne jamais être appelée
/*
function callShare(param)
{
	//alert(param);	
	//cmCreateConversionEventTag(param);
}
*/
/*
function callRecipe(param)
{
	//alert(param);
}
*/

function callPlayVideo(param1, param2)
{
	cmCreatePageElementTag(param1, 'WCTV', 'play');
}

function callPause(param1, param2)
{
	cmCreatePageElementTag(param1, 'WCTV', 'pause');
}

function callEndVideo(param1, param2)
{
	cmCreatePageElementTag(param1, 'WCTV', 'end');
}

function callNextVideo(param)
{
	findNextThumb();
	param = param.replace(/["']{1}/gi,"");	//strip all quotes
	var splittedString = param.split(','); //split at commas
	cmCreatePageElementTag('SHOW-'+splittedString[1]+'-'+splittedString[2]+'-next', 'WCTV'); //track
}

function callFullScreen(param1, param2)
{
	cmCreatePageElementTag(param1, param2, 'full');
}

function callFullScreenAction(this_action)
{
	/*
	//if(compteur%2 != 1) // sortie du mode fullscreen
	if(this_action == "'fullScreen'") // sortie du mode fullscreen
	{
		//alert(this_action);
		document.write(this_action);
		compteur = 0;
	}
	*/
}

function callArchives(param)
{
	window.location.href = base_url+"/shows/";
}

function callShareAction(params){
	var brokenstring 	= params.split(',');
	//alert('url_prefixe = '+ url_prefixe+',\n url_sufixe = '+url_sufixe+',\n params = '+params);
	brokenstring[0]		= brokenstring[0].replace(url_prefixe, "");
	url_sufixe			= brokenstring[0].replace(/'/g, "");
	
	//Si on partage une émission...
	if (url_prefixe.indexOf('shows') != -1 && url_prefixe.indexOf('vignette') == -1) {
		//S'il y a déjà un "&v=" dans l'url, on supprime ce dernier...
		if (url_prefixe.indexOf('&v=') != -1) {
			var splittedUrl = url_prefixe.split('&v=');
			url_prefixe = splittedUrl[0];
		}
		//S'il n'y a pas de '?' dans l'url, on ajoute la thématique dans le prefixe.
		//(Si on est dans .../shows/)
		if (url_prefixe.indexOf('?') == -1 && url_prefixe.indexOf('shows') != -1) {
			url_prefixe += '?visible_emissionsfilter=' + post_title;
		}
		//Sert à contenir le numéro du vidéo passer en paramètre
		var currentEmiValue = currentEmi;
		//Si ce n'est pas déjà un entier...
		if (typeof currentEmiValue != "number") {
			//Supprimer "emi" de la string, le convertir en entier
			currentEmiValue = parseInt(currentEmi.replace('emi', ''));
		}
		//Ajouter 1 au vidéo...
		currentEmiValue++;
		//Finaliser le paramètre passé dans l'url
		url_sufixe += '&v=' + currentEmiValue;
	}
	
	if (url_sufixe.indexOf('http') != -1){ //Quickfix pour le partage d'une vignette
		openAddThisWindow(post_title, '', url_prefixe);
	} else {
		openAddThisWindow(post_title, url_sufixe, url_prefixe);
	}
	

	if(params == "'fullScreen'") // sortie du mode fullscreen
	{
		//alert(this_action);
		//document.write(params);
		compteur = 0;
	}
}

function callShare(url){
	//Suppression des guillemets et apostrophes de l'argument
	url = url.replace(/["']{1}/gi,"");
	//Sépare la String aux virgules
	var splittedString = url.split(',');
	//Tracking pour la page d'accueil
	if(splittedString[0] === "WebTV" && splittedString[4] != ''){
		cmCreatePageElementTag('HOME-share-'+splittedString[4], 'WCTV');
	}
	//Tracking pour la page des émissions
	if(splittedString[0] === "Shows"){
		//Contient le numéro du vidéo et indexe dans le tableau videoTitlesArr
		//alert(currentEmi);
		var currentEmiValue = currentEmi;
		//Si ce n'est pas déjà un entier...
		if (typeof currentEmiValue != "number") {
			//Supprimer "emi" de la string, le convertir en entier
			currentEmiValue = parseInt(currentEmi.replace('emi', ''));
		}
		alert('EMISSION-share-'+thematique+'-'+videoTitlesArr[currentEmiValue]);
		cmCreatePageElementTag('Shows-share-'+thematique+'-'+videoTitlesArr[currentEmiValue], 'WCTV');
	}
	
}

function exitFullscreen(aParam){
	//alert('---'+aParam);
}

function callLinkAction(url){
	//alert(url);
	url = url.slice(1,url.length-1);
	//alert(url);
	window.open(url, '_self');
	
	/*
	*/
}

function callRecipe(url){
	//alert(url);
	params = url.slice(url.indexOf(',')+2, url.length-1);
	cmCreatePageviewTag('home', 'vignette', params);
}

function callThumb(ttl)
{
	if(ttl.search('"') >=0)
	{
		params = ttl.slice(1, ttl.length-1);
	}
	else
	{
		params = ttl;
	}
	//alert(params);
	cmCreatePageviewTag('home', 'vignette', params);
}

function updateTitle(ttl)
{
	ttl = ttl.slice(1,ttl.length-1);
	document.getElementById('vignette_title').innerHTML = ttl;
	post_title = ttl;
	url_sufixe = escape(ttl);
	//alert(ttl);
}

function openAddThisWindow(v1,v2,url)
{
    var addthis_pub="kraftprod";
    var addthis_config = {ui_cobrand: "WCTV", ui_language: "en"}
    var title = v1;
    url = url + v2;
    return addthis_open(screwthis, '', url, title);
}

function removeElement(aDiv) 
{
	var vToDelete = document.getElementById(aDiv);
    var vParent = vToDelete.parentNode;
    vParent.removeChild(vToDelete);
}

function findClickThumb(clicked)
{
	if(loadVideoCheck==1){
		currentEmi = clicked;
		switchThumbColor(clicked);
	}
}

function findNextThumb()
{
	currentEmi = parseInt(currentEmi.replace('emi',''));
	currentEmi = currentEmi+1;
	currentEmi = 'emi'+currentEmi;
	switchThumbColor(currentEmi);
}

function switchThumbColor(thumbID)
{
	for(i=0;i<highLightLoop;i++){
		document.getElementById('emi'+i).style.backgroundColor='#a5b85f';
	}
	document.getElementById(thumbID).style.backgroundColor='#667324';
}

function thisMovie(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}

function jsDisplayError(numError)
{
	if(loadVideoCheck==1){
	loadVideoCheck=0;
	//alert(thisMovie("appFlashId"));
	thisMovie("appFlashId").selectVideo(numError);
	setTimeout(function(){loadVideoCheck=1;},2000);
	}
}

function displayMessage(msg)
{
	alert("MSG :"+msg);
}

function setFocusOnFlash()
{
	var fl = document.getElementById('appFlashId');
	if (fl) { fl.focus(); }
}

function isReady()
{
	return true;
}

function empty_field(thisfield)
{
	if(thisfield.value == 'Search')
	{
		thisfield.value = '';	
	}
}

function refill_field(thisfield)
{
	if(thisfield.value == '')
	{
		thisfield.value = 'Search';
	}
}

function change_pnum(this_value, id)
{
	document.getElementById(id).value = parseInt(document.getElementById(id).value) + this_value;
}

function submitPager(pagenumber)
{
	  	document.getElementById('pagen').value = pagenumber;
	  	document.getElementById('pagerblog').submit();
}

function handleEnter(inField, e, newpage, total)
{
	var charCode;
	if(e && e.which){
		charCode = e.which;
		}else if(window.event){
			e = window.event;
			charCode = e.keyCode;
		}
		if(charCode == 13){
			if(inField.value!=newpage&&parseInt(inField.value)<=total&&parseInt(inField.value)>0){
				submitPager(parseInt(inField.value));
			}
		}
}

function switch_image(id, src, url, key, txt_src, txt_alt)
{
	var this_text;
	//document.getElementById(id).src = src;
	document.getElementById(id).style.backgroundImage = "url("+src+")"
	document.getElementById(id).alt = txt_alt;
	//document.getElementById(key).href = url;
	//document.getElementById('revoir_emission').style.display = 'block';
	//document.getElementById('bg_revoir_emission').style.display = 'block';
	
	if(key == 'semaine_derniere_recipe_link')
	{
		switch(txt_src)
		{
			case 'normal':
				this_text = 'Revoir cette recette';
				img_link = './wp-content/themes/qqm/images/bo_play.png';
			break;
			
			case 'exclusive':
				this_text = 'Consulter la fiche recette';
				img_link = './wp-content/themes/qqm/images/bullet_arrow_recette.png';
			break;
			
			case 'interview':
			case 'chronique':
				this_text = 'Rejouer la vidéo';
				img_link = './wp-content/themes/qqm/images/bo_play.png';
			break;
		}
		//document.getElementById('semaine_derniere_quote').innerHTML = this_text;
		//document.getElementById('bo_semaine_derniere').src = img_link;
		
	}
	
}


/*
 * cmdatatagutils.js 
 * $Id: cmdatatagutils - 8604995 - 90222822 - 20090424.txt 116205 2009-04-24 13:53:39Z croberts $
 * $Revision: 116205 $
 *
 * Version 4.1.0
 *
 * Coremetrics Tag v4.0, 8/7/2006
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 *	CRoberts	04/23/2009	Added custom tag and parameter in pageview for Foresee.
 *
 */
 
var cm_exAttr=new Array;  
var cm_ClientID = "90222825";
var cm_TrackLink = "A";
var cm_TrackImpressions = "RS";
var cm_JSFEnabled = true;

var cmJv = "1.0";
if (typeof(isNaN) == "function") cmJv = "1.1";
if (typeof(isFinite) == "function") cmJv = "1.2";
if (typeof(NaN) == "number") cmJv = "1.3";
if (typeof(decodeURI) == "function") cmJv = "1.5";
if (typeof(Array.forEach) == "function") cmJv = "1.6";
if (typeof(Iterator) == "object") cmJv = "1.7";

var cmCheckCMEMFlag = true;
  
/* TAG GENERATING FUNCTIONS */

/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	cm_HOST="data.coremetrics.com/eluminate?";
	cm_JSFPCookieDomain = "kraftfoods.com";
}

function cmCreateForeseeTag(respondentID, measureName) {

        var cm = new _cm("tid", "7", "vn2", "e3.1");
        cm.li = "100003";
        cm.ps1 = respondentID;
        cm.ps2 = measureName;
	cmMakeTag(["tid","7","li","100003","ps1",respondentID,"ps2",measureName]);
}

function cmCreateManualImpressionTag(pageID, trackSP, trackRE) {
		// insert code to get pageID from cmTagControl if pageID is null
		cmMakeTag(["tid","9","pi",pageID,"cm_sp",trackSP,"cm_re",trackRE,"st",cm_ClientTS]);
}

function cmCreateManualLinkClickTag(href,name,pageID) {	
	if (cmCreateLinkTag == null && cM != null) {
		var cmCreateLinkTag = cM;
	}
	if (cmCreateLinkTag != null) {		
		var dt = new Date();
		cmLnkT3 = dt.getTime();
		href=cG7.normalizeURL(href,true);
		cmCreateLinkTag(cm_ClientTS, cmLnkT3, name, href, false, pageID);
	}
}

/* manual PageviewTag for off site page tagging.  Allows client to supply URL and Referring URL
*/
function cmCreateManualPageviewTag(pageID, categoryID,DestinationURL,ReferringURL) {
	cmMakeTag(["tid","1","pi",pageID,"cg",categoryID,"ul",DestinationURL,"rf",ReferringURL]);
}

function cmCreatePageElementTag(elementID, elementCategory, pageID, pageCategoryID, elementLocation,attributes) {
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","15","eid",elementID,"ecat",elementCategory,"pflg","0","pid",pageID,"pcat",pageCategoryID,"eloc",elementLocation,"cm_exAttr",cm_exAttr]);
}

function cmCreateProductElementTag(elementID, elementCategory, productID, productCategoryID, elementLocation,attributes) {
	if (attributes){
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","15","eid",elementID,"ecat",elementCategory,"pflg","1","pid",productID,"pcat",productCategoryID,"eloc",elementLocation,"cm_exAttr",cm_exAttr]);
}

/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */
function cmCreateTechPropsTag(pageID, categoryID,attributes) {
	if(pageID == null) { pageID = cmGetDefaultPageID(); }
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","6","pi",pageID,"cg",categoryID,"pc","Y","cm_exAttr",cm_exAttr]);
}

/*
 * Creates a Pageview tag with the given Page ID
 *
 * pageID	: required. Page ID to set on this Pageview tag
 * categoryID	: optional. Category ID to set on this Pageview tag
 * searchString	: optional. Internal search string enterred by user to reach
 *				  this page.
 *
 * 
 */
function cmCreatePageviewTag(pageID, categoryID, searchString, searchResults, respondentID, attributes) {
	if (pageID == null) { pageID = cmGetDefaultPageID(); }
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","1","pi",pageID,"cg",categoryID,"se",searchString,"sr",searchResults,"pv1", respondentID, "cm_exAttr",cm_exAttr]);
}

/*
 * Creates a Pageview tag with the default value for Page ID. 
 * Format of Page ID is "x/y/z/MyPage.asp"
 *
 * 
 */
function cmCreateDefaultPageviewTag(categoryID) {
	cmCreatePageviewTag(cmGetDefaultPageID(), categoryID);
}

/*
 * Creates a Productview Tag
 * Also creates a Pageview Tag by setting pc="Y"
 * Format of Page ID is "PRODUCT: <Product Name> (<Product ID>)"
 *
 * productID	: required. Product ID to set on this Productview tag
 * productName	: required. Product Name to set on this Productview tag
 * categoryID	: optional. Category ID to set on this Productview tag 
 *
 * 
 */
function cmCreateProductviewTag(productID, productName, categoryID,attributes) {
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","5","pi","PRODUCT: "+productName+" ("+productID+")","pr",productID,"pm",productName,"cg",categoryID,"pc","Y","cm_exAttr",cm_exAttr]);
}


/*
 * Variables and Arrays to support Lineitem Aggregation
 */
var __sArray = new Array();
var __skuString = "";
var __ex=new Array();

function __cmGetPIPC(__pr,__cg)
{
	var __pI, i;
	var cmAttr1=new Array();
	var cmAttr2=new Array();
	for (i=0;i<__ex.length;++i){
		cmAttr1=cmAttr1+__ex[i];
	}		
	for (__pI = 0; __pI < __sArray.length; ++__pI) {
		if (__ex.length>0){
			cmAttr2=new Array();		
			for (i=__sArray[__pI].length-__ex.length*2+1;i<__sArray[__pI].length;i=i+2){
				cmAttr2=cmAttr2+__sArray[__pI][i];
			}
	
			if (__pr == __sArray[__pI][1] && __cg == __sArray[__pI][9] && cmAttr1==cmAttr2){
				return __pI;
			}
		} else {
		if (__pr == __sArray[__pI][1] && __cg == __sArray[__pI][9]) return __pI;
	}
	}	
	return -1;
}

function cmAddShop(__v)
{
	var __i = __cmGetPIPC(__v[1],__v[9]);
	if (__i == -1) {
		if (__ex.length>0){
			for (var i=0; i<__ex.length; ++i){
				__v[__v.length]="s_a"+(i+1);
				__v[__v.length]=__ex[i];
			}
		}
		__sArray[__sArray.length] = __v;
	}
	else {
		var __oQ = __sArray[__i][5];
		var __oP = __sArray[__i][7];
		__sArray[__i][5] = parseInt(__sArray[__i][5]) + parseInt(__v[5]);
		__sArray[__i][7] = (((__v[7]*__v[5])+(__oP*__oQ))/__sArray[__i][5]);
	}
}

/*
 * Creates a Shop tag with Action 5 (Shopping Cart)
 *
 * productID	: required. Product ID to set on this Shop tag
 * quantity	: required. Quantity to set on this Shop tag
 * productPrice	: required. Price of one unit of this product
 * categoryID	: optional. Category to set on this Shop tag
 *
 * 
 */
function cmCreateShopAction5Tag(productID,productName,productQuantity,productPrice,categoryID,attributes)
{
	var pattern = /[^\-0-9\.]/gi;
    productPrice = productPrice.toString().replace(pattern, "");
	var cm_slotNum;
	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}	

	cmAddShop(["pr",productID,"pm",productName,"qt",productQuantity,"bp",productPrice,"cg",categoryID,"sn",cm_slotNum,"at","5","tid","4","pc","N"]);
}

/*
 * Creates a Shop tag with Action 9 (Order Receipt / Confirmed)
 *
 * productID	: required. Product ID to set on this Shop tag
 * productName	: required. Product Name to set on this Shop tag
 * quantity	: required. Quantity to set on this Shop tag
 * productPrice	: required. Price of one unit of this product
 * customerID	: required. ID of customer making the purchase
 * orderID	: required. ID of order this lineitem belongs to
 * orderTotal	: required. Total price of order this lineitem belongs to
 * categoryID	: optional. Category to set on this Shop tag
 *
 */
function cmCreateShopAction9Tag(productID,productName,productQuantity,productPrice,customerID,orderID,orderTotal,categoryID,attributes)
{
	var cm_slotNum;
	var pattern = /[^\-0-9\.]/gi;
	var pattern1 = /^\s+|\s+$/gi;
    productPrice = productPrice.toString().replace(pattern, "");
	orderTotal = orderTotal.toString().replace(pattern, "");
	productID = productID.toString().replace(pattern1, "");
	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}
	
	cmAddShop(["pr",productID,"pm",productName,"qt",productQuantity,"bp",productPrice,"cg",categoryID,"sn",cm_slotNum,"cd",customerID,"on",orderID,"tr",orderTotal,"at","9","tid","4","pc","N"]);
	cmCalcSKUString();
}

function cmDisplayShop5s()
{
	cmDisplayShops();
}

function cmDisplayShop9s()
{
	cmCalcSKUString();
	cmDisplayShops();
}

function cmCalcSKUString()
{
	__skuString = "";
	var __skuStringArray = new Array();
	for (var i = 0; i < __sArray.length; ++i) {
		// aggregate
		var __skuStringArrayIndex = -1;
		for (var y = 0; y < __skuStringArray.length; ++y) {
			if (__sArray[i][1] == __skuStringArray[y][0] ) {
				__skuStringArrayIndex = y;
			}
		}
		if (__skuStringArrayIndex == -1) {
			// it doesn't exist, so add it
			var newArrayIndex = __skuStringArray.length;
			__skuStringArray[newArrayIndex] = new Array();
			__skuStringArray[newArrayIndex][0] = __sArray[i][1];
			__skuStringArray[newArrayIndex][1] = __sArray[i][7];
			__skuStringArray[newArrayIndex][2] = __sArray[i][5];
		}
		else {
			// it exists, so update it
			var __oP = __skuStringArray[__skuStringArrayIndex][1];
			var __oQ = __skuStringArray[__skuStringArrayIndex][2];
			__skuStringArray[__skuStringArrayIndex][2] = parseInt(__sArray[i][5]) + __oQ;
			__skuStringArray[__skuStringArrayIndex][1] = (((__sArray[i][7]*__sArray[i][5])+(__oP*__oQ))/__sArray[i][5]);		
		}
	}
	for (var x = 0; x < __skuStringArray.length; ++x) {
		__skuString += "|"+__skuStringArray[x][0]+"|"+__skuStringArray[x][1]+"|"+__skuStringArray[x][2]+"|";
	}
}

function cmDisplayShops()
{
	var i;
	for (i = 0; i < __sArray.length; ++i) {
		for (var l=0;l<__sArray[i].length;++l){
			if (__sArray[i][l]=="sn"){
				__sArray[i][l+1]=i.toString();
			}
		}
		cmMakeTag(__sArray[i]);
	}
	__sArray = new Array();
}


/*
 * Creates an Order tag
 *
 * orderID			: required. Order ID of this order
 * orderTotal		: required. Total of this order (minus tax and shipping)
 * orderShipping	: required. Shipping charge for this order
 * customerID		: required. Customer ID that placed this order
 * customerCity		: optional. City of Customer that placed this order
 * customerState	: optional. State of Customer that placed this order
 * customerZIP		: optional. Zipcode of Customer that placed this order
 *
 */
function cmCreateOrderTag(orderID,orderTotal,orderShipping,customerID,customerCity,customerState,customerZIP,attributes)
{
	var pattern = /[^\-0-9\.]/gi;
    orderShipping = orderShipping.toString().replace(pattern, "");
	orderTotal = orderTotal.toString().replace(pattern, "");
	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","3","osk",__skuString,"on",orderID,"tr",orderTotal,"sg",orderShipping,"cd",customerID,"ct",customerCity,"sa",customerState,"zp",customerZIP,"cm_exAttr",cm_exAttr]);
	__skuString = "";
}

/*
 * Creates a Conversion Event tag
 *
 * eventID			: required. Conversion event ID
 * actionType		: required. 1=conversion initiation, 2=conversion completion
 * categoryID		: optional. Category for the event
 * points			: optional. Point value to assign to conversion.
 */
 function cmCreateConversionEventTag(eventID, actionType, categoryID, points,attributes)
 {
 	if (attributes){
		var cm_exAttr=new Array;
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","14","cid",eventID,"cat",actionType,"ccid",categoryID,"cpt",points,"cm_exAttr",cm_exAttr]);
 }

/*
 * Creates a Registration tag and/or a Newsletter tag
 *
 * customerID		: required for Registration. ID of Customer to register.
 * customerEmail	: required for Newsletters. Optional for Registration.
 * customerCity		: optional. City of Customer that placed this order
 * customerState	: optional. State of Customer that placed this order
 * customerZIP		: optional. Zipcode of Customer that placed this order
 * newsletterName	: required for Newsletters. The name of the Newsletter.
 * subscribe		: required for Newsletters. Either "Y" or "N"
 *
 */
function cmCreateRegistrationTag(customerID, customerEmail, customerCity, customerState, customerZIP, newsletterName, subscribe, seible_ID)
{
	cmMakeTag(["tid","2","cd",customerID,"em",customerEmail,"ct",customerCity,"sa",customerState,"zp",customerZIP,"nl",newsletterName,"sd",subscribe,"rg11",seible_ID]);
}

/* Creates an Error Tag
 *
 */
function cmCreateErrorTag(pageID, categoryID)
{
	if(pageID == null) {
		pageID = cmGetDefaultPageID();
	}
	cmMakeTag(["tid","404","pi",pageID,"cg",categoryID,"pc","Y"]);
}

function cmMakeTag(__v)
{
	var cm = new _cm("vn2", "e4.0");
	var i;
	for (i = 0; i < __v.length; i += 2) {
		var _n = __v[i];
		var _v = __v[i + 1];
		cm[_n] = _v;
	}
	
	var datestamp = new Date();	
	var stamp = (Math.floor(Math.random() * 11111111)) + datestamp.valueOf();	
	cm.rnd = stamp;
	
	if (cm.tid == "6") {
		cm.addTP();
		document.cookie = "cmTPSet=Y; path=/";
	}

	if (cm.tid == "1") {
		if (cI("cmTPSet") != 'Y') {
			cm.tid = "6";
			cm.pc = "Y";
			cm.addTP();
			document.cookie = "cmTPSet=Y; path=/";
		}
	}

	if (cm.tid != "4" && typeof(cm.cm_exAttr)!="undefined"){
		switch(cm.tid){
			case "6":
				prefix="pv";
				break;
			case "1":
				prefix="pv";
				break;
			case "5":
				prefix="pr";
				break;
			case "3":
				prefix="o";
				break;
			case "14":
				prefix="c";
				break;
			case "15":
				prefix="e";
				break;
			default:
				break;
		}		
		var attrNum=cm.cm_exAttr.length;
		if (attrNum>15){
			attrNum=15;
		}
		for (i=0;i<attrNum;i++){
			Attval=prefix+"_a"+(i+1);
			cm[Attval]=cm.cm_exAttr[i];
		}
		cm.cm_exAttr=null;
	}	
	if ((cm.pi == null) && (cm.pc == "Y")) {
		cm.pi = cmGetDefaultPageID();
	}

	try{
		if (parent.cm_ref != null) {
			cm.rf = parent.cm_ref;
			if (cm.pc == "Y") {
				parent.cm_ref = document.URL;
			}
		}
	
		// if parent had mmc variables and this is the first pageview, add mmc to this url
		if(parent.cm_set_mmc) {
			cm.ul = document.location.href + 
					((document.location.href.indexOf("?") < 0) ? "?" : "&") + 
					parent.cm_mmc_params; 
			if (cm.pc == "Y") {
				parent.cm_ref = cm.ul;
				parent.cm_set_mmc = false;
			}
		}
	}
	catch(err){}

	if (cm.ul == null) {
		cm.ul = window.location.href;
	}

	//check for zero price and zero quantity
	cmSafeZero(cm,["qt","bp","tr","sg"]);

	//check for manual_cm_mmc parameter;
	if (this.manual_cm_mmc != null) {
		cm.ul = cm.ul + ((cm.ul.indexOf("&") == -1) ? ((cm.ul.indexOf("?") == -1) ? "?" : "&") : "&") + "cm_mmc=" + this.manual_cm_mmc;
	}

	// convert MMC parameters to lowercase;
	cm.ul = cm.ul.replace(/cm_mmc/gi,"cm_mmc");
	cm.ul = cm.ul.replace(/cm_ven/gi,"cm_ven");
	cm.ul = cm.ul.replace(/cm_cat/gi,"cm_cat");
	cm.ul = cm.ul.replace(/cm_pla/gi,"cm_pla");
	cm.ul = cm.ul.replace(/cm_ite/gi,"cm_ite");
	if (cmCheckCMEMFlag){cmStartTagSet();}
    cm.writeImg();
	if (cmCheckCMEMFlag) {
		cmCheckCMEMFlag = false;	
		cmCheckCMEM();
		cmSendTagSet();		
	}
	
}

// HELPER FUNCTIONS -----------------------------------------------------------
/* These functions are used by the tag-generating functions and/or may be used
 * in in general as convenience functions
 */

/*
 * Creates an acceptable default Page ID value to use for Pageview tags.
 * The default Page ID is based on the URL, and consists of the path and
 * filename (without the protocol, domain and query string).
 * 
 * example:
 * returns "x/y/MyPage.asp" for the URL http://www.mysite.com/x/y/MyPage.asp
 */
function cmGetDefaultPageID() 
{ 
	var pageName = window.location.pathname; 

	// eliminates everything after "?" (for Opera browswers)
	var tempIndex1 = pageName.indexOf("?");
	if (tempIndex1 != -1) {
		pageName = pageName.substr(0, tempIndex1);
	}
	// eliminates everything after "#" (for Opera browswers)
	var tempIndex2 = pageName.indexOf("#");
	if (tempIndex2 != -1) {
		pageName = pageName.substr(0, tempIndex2);
	}
	// eliminates everything after ";"
	var tempIndex3 = pageName.indexOf(";");
	if (tempIndex3 != -1) {

		pageName = pageName.substr(0, tempIndex3);
	}

	var slashPos = pageName.lastIndexOf("/");
	if (slashPos == pageName.length - 1) {
		pageName = pageName + "default.asp"; /****************** SET TO DEFAULT DOC NAME */
	}

	while (pageName.indexOf("/") == 0) {
		pageName = pageName.substr(1,pageName.length);
	}

	return(pageName); 
} 

function cmIndexOfParameter (parameter, inString) 
{
	return inString.indexOf(parameter);
}

function cmExtractParameter (parameter, inString) 
{
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return null;
    }
	var s = inString;
	var begin = s.indexOf(parameter);
	var end = s.indexOf("&", begin);
	if (end == -1) {
		end = s.length;
	}
	var middle = s.indexOf("=", begin);
	return s.substring(middle + 1, end);
}

function cmRemoveParameter (parameter, inString) 
{
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return inString;
    }
	var s = inString;
	var begin = s.indexOf(parameter);
	var start = (begin - 1);
	var end = s.indexOf("&", begin);
	if (end == -1) {
		end = s.length;
	}
	if (s.substring(start, begin) == "?") {    // retain leading "?"
		start = (start + 1);
		end = (end + 1);
	}
	return s.substring(0, start) + s.substring(end, s.length);
}

function cmCheckCMEM() 
{
	if (cmIndexOfParameter("cm_em",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_em",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}
		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
	if (cmIndexOfParameter("cm_lm",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_lm",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}		
		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
}

function cmSafeZero(cm, checkArray) 
{
	// put logic here to convert number 0 to string "0"
	for (var i = 0; i < checkArray.length; ++i) {
		if ((cm[checkArray[i]] != null) && (cm[checkArray[i]] == 0)) {
			cm[checkArray[i]] = "0";
		}
	}
}

if (defaultNormalize == null) { var defaultNormalize = null; }

function myNormalizeURL(url, isHref) 
{
	var newURL = url;
	// ... transform newURL here ...
	if (defaultNormalize != null) {
		newURL = defaultNormalize(newURL, isHref);
	}
	return newURL;
}

// install normalization
if (document.cmTagCtl != null) 
{
    var func = "" + document.cmTagCtl.normalizeURL;
    if (func.indexOf('myNormalizeURL') == -1) {
        defaultNormalize = document.cmTagCtl.normalizeURL;
        document.cmTagCtl.normalizeURL = myNormalizeURL;
    }
}

/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.1.1
Last Update: 4 October 2007

Changes:
1.1.1 fixes a problem with Get_Cookie that did not correctly handle case
where cookie is initialized but it has no "=" and thus no value, the 
Get_Cookie function generates a NULL exception. This was pointed out by olivier, thanks

1.1.0 fixes a problem with Get_Cookie that did not correctly handle
cases where multiple cookies might test as the same, like: site1, site

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required

function Get_Cookie( check_name )
{
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
    path="/"
	if (expires)
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
	
	cookie_str = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );

	document.cookie = cookie_str;
	//document.write(cookie_str);
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function check_cookie_n_rewrite(name)
{
	//alert(Get_Cookie(name));
	if(Get_Cookie(name) == null)
	{
		//Set_Cookie( name, value, expires, path, domain, secure )
	}
	
	rewrite_url(document.location.href);
	
}

function rewrite_url(hrefValue)
{
	//alert(hrefValue);
}

function Reset_Cookie( name, value, expires, path, domain, secure ) 
{
	while(Get_Cookie(name) != null)
	{
		Delete_Cookie( name, path, domain );
	}
	
	Set_Cookie( name, value, expires, path);
}

function isObject(targetID)
{

   var isFound = false;
   var el = document.getElementById(targetID);
   
   if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")){
   
      isFound = true;
   
   }
   
   return isFound;
}

//Support function: creates an empty
//element to replace embedded SWF object

function replaceSwfWithEmptyDiv(targetID)
{
   var el = document.getElementById(targetID);
   
   if(el){
   
      var div = document.createElement("div");
      el.parentNode.insertBefore(div, el);
 
      //Remove the SWF
      swfobject.removeSWF(targetID);
   
      //Give the new DIV the old element's ID
      div.setAttribute("id", targetID);
   }
}

function change_videos_a_explorer(xml_from, link_title, parentNodeAdd, parentNodeRemove, webtv, src_name)
{
	loadThumbs = false;
	loadSWF('appFlashId', xml_from, link_title);
	add_selected(parentNodeAdd, 'add');
	add_selected(parentNodeRemove, 'remove');
	ajax_get_player_thumbnails(src_name, cats, cat_ids)
	cmCreatePageElementTag(webtv,'WCTV');
}

function preloading(){
	for (x=0; x<preloading.arguments.length; x++){
		myimages[x] = new Image();
		myimages[x].src = preloading.arguments[x];
	}
}

function switch_movie(this_id)
{
	if(document.getElementById('appFlashId') && alreadyrunflag == 1)
	{
		//alert(document.getElementById('appFlashId'));
		findClickThumb('emi'+this_id);
		jsDisplayError(this_id);
	}

}

var alreadyrunflag=0 //flag to indicate whether target function has already been run

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1;}, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1
    }
  }
}

else if(/Safari/i.test(navigator.userAgent)){ //Test for Safari
  var _timer=setInterval(function(){
  if(/loaded|complete/.test(document.readyState)){
    clearInterval(_timer)
    alreadyrunflag=1 // call target function
  }}, 10)
}