/* ------------------------------------------------------------------------------------------------------------------------------- */
function displayPrivacy() {
	var myBars = 'directories=no,location=no,menubar=no,status=yes,titlebar=yes,toolbar=no';
	var myOptions ='scrollbars=yes,width=600,height=220,resizable=yes';
	var myFeatures = myBars + ',' + myOptions;
	var refWindow = open('http://www.dragondoor.com/includes/privacy_policy.html', 'ref_Win', myFeatures);
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function newletterSubscribe() {
	var myBars = 'directories=no,location=no,menubar=no,status=yes';
	myBars += ',titlebar=yes,toolbar=no';
	var myOptions ='scrollbars=yes,width=660,height=630,resizable=yes';
	var myFeatures = myBars + ',' + myOptions;
	var refWindow = open('http://www.dragondoor.com/includes/newsubpop.html', 'ref_Win', myFeatures);
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function pavel_news() {
	var myBars = 'directories=no,location=no,menubar=no,status=yes';
	myBars += ',titlebar=yes,toolbar=no';
	var myOptions ='scrollbars=yes,width=545,height=420,resizable=yes';
	var myFeatures = myBars + ',' + myOptions;
	var refWindow = open('http://www.dragondoor.com/includes/newsubpop_pavel.html', 'ref_Win', myFeatures);
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function justpavel_news() {
	var myBars = 'directories=no,location=no,menubar=no,status=yes';
	myBars += ',titlebar=yes,toolbar=no';
	var myOptions ='scrollbars=yes,width=545,height=380,resizable=yes';
	var myFeatures = myBars + ',' + myOptions;
	var refWindow = open('http://www.dragondoor.com/includes/newsubpop_justpavel.html', 'ref_Win', myFeatures);
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function justheartcure_news() {
	var myBars = 'directories=no,location=no,menubar=no,status=yes';
	myBars += ',titlebar=yes,toolbar=no';
	var myOptions ='scrollbars=yes,width=545,height=380,resizable=yes';
	var myFeatures = myBars + ',' + myOptions;
	var refWindow = open('http://www.dragondoor.com/includes/newsubpop_justheartcure.html', 'ref_Win', myFeatures);
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function displayPic(imgsrc,width,height) {
	var myBars		= 'directories=no,location=no,menubar=no,status=yes,titlebar=yes,toolbar=no';
	var myOptions	='scrollbars=yes,width='+width+',height='+height+',resizable=yes';
	var myFeatures	= myBars + ',' + myOptions;
	var refWindow	= open('http://www.dragondoor.com/blank.html', 'ref_Win', myFeatures);
	var content		= '<html><body><img src="'+imgsrc+'"><br><center> ';
	content			+= '<a href="javascript:window.close()">Close this window </a></center></body></html>';
	refWindow.document.write(content);
	refWindow.document.close();
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function displayPopup(pagesrc,width,height) {
	var myBars		= 'directories=yes,location=yes,menubar=yes,status=yes,titlebar=yes,toolbar=yes';
//	var myBars		= 'directories=no,location=no,menubar=no,status=yes,titlebar=yes,toolbar=no';
	var myOptions	='scrollbars=yes,width='+width+',height='+height+',resizable=yes';
	var myFeatures	= myBars + ',' + myOptions;
//	var refWindow	= window.open('http://www.dragondoor.com/blank.html', 'ref_Win', myFeatures);
	var refWindow	= window.open('', 'ref_Win', myFeatures);
	//var content		= '<html><body><img src="'+imgsrc+'"><br><center> ';
	//content			+= '<a href="javascript:window.close()">Close this window </a></center></body></html>';
	refWindow.document.open();
	refWindow.document.write(pagesrc);	
	refWindow.document.close();
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function displayBarePopup(pagesrc,width,height) {
	//var myBars		= 'directories=yes,location=yes,menubar=yes,status=yes,titlebar=yes,toolbar=yes';
	var myBars		= 'directories=no,location=no,menubar=no,status=yes,titlebar=yes,toolbar=no';
	var myOptions	='scrollbars=yes,width='+width+',height='+height+',resizable=yes';
	var myFeatures	= myBars + ',' + myOptions;
	var refWindow	= window.open('', 'ref_Win', myFeatures);
	refWindow.document.open();
	refWindow.document.write(pagesrc);	
	refWindow.document.close();
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function displayInPopup(pagesrc,width,height) {
	//var myBars		= 'directories=yes,location=yes,menubar=yes,status=yes,titlebar=yes,toolbar=yes';
	var myBars		= 'directories=no,location=no,menubar=no,status=yes,titlebar=yes,toolbar=no';
	var myOptions	='scrollbars=yes,width='+width+',height='+height+',resizable=yes';
	var myFeatures	= myBars + ',' + myOptions;
	var refWindow	= window.open(pagesrc, 'ref_Win', myFeatures);
}


/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function showEmailFilterPopup() {
	displayInPopup('http://www.dragondoor.com/emailfilter_popup.html',600,700);
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
/*	Jan 31.2005
	Bad Cookie processing
	- remove the clientId cookie when equal to 184953 or 199822
*/
var name, value;
/* ------------------------------------------------------------------------------------------------------------------------------- */
function fixbadcookie() {
	cookie		= document.cookie;
	start		= cookie.indexOf('clientId',0);
	end			= parseCookie(cookie,start);
	csize		= end - start;

	subcookie	= cookie.substr(start,csize);
	formatCookie(subcookie);

	if (value=='184953' || value=='199822') {
		deletecookie()
	}
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function parseCookie(cookie,idx) {
	index = cookie.indexOf(';',idx);
	if (index<0) {
		index = cookie.length;
	}
	return index;
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function formatCookie(cookie) {
	idx	= cookie.indexOf('=',0);
	size	= cookie.length;
	if (idx>1) {
		name	= cookie.substr(0,idx);
		value	= cookie.substr(idx+1,size);
	} else {
		name	= cookie.substr(0,size);
		value	= '';
	}
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function deletecookie() {
	expireDate=new Date;
	expireDate.setYear(expireDate.getYear()-1);
	document.cookie = "clientId='';" + ";expires=" + expireDate.toGMTString() +";path=/; domain=.dragondoor.com";
	//alert('deleted bad cookie');

}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function showhide(id) {
	items	= document.getElementById(id);
	if (items) {
		if (items.style.display == 'none'){
			items.style.display		= '';
			//items.style.position	= 'relative';
		} else {
			items.style.display		= "none";
			//items.style.position	= 'absolute';
		}
	}
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function showElement(id) {
	var element	= document.getElementById(id);
	if (element) {	element.style.display		= '' }
}

function hideElement(id) {
	var element	= document.getElementById(id);
	if (element) {	element.style.display		= 'none'; }
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------------------------- */
function writeToElement(id,data,mode) {
	var element	= document.getElementById(id);
	if (element) {
		if (mode) {
			if (mode.match(/a/i)) {	element.innerHTML	+= data;
			} else {				element.innerHTML	= data;	}
		} else {
			element.innerHTML	= data;
		}
	}
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function scrollToElement(id){
	var element = document.getElementById(id);
	var selectedPosX = 0;
	var selectedPosY = 0;

	while(element != null){
		selectedPosX    += element.offsetLeft;
		selectedPosY    += element.offsetTop;
		element       	= element.offsetParent;
	}
	window.scrollTo(selectedPosX,selectedPosY);
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
// navigation header selections
function mover_menuitem(target) {
	target.style.backgroundColor	= '#DDDDDD';
}

function mout_menuitem(target) {
	target.style.backgroundColor	= '#FFFFFF';
}
/* ------------------------------------------------------------------------------------------------------------------------------- */


/* ------------------------------------------------------------------------------------------------------------------------------- */
function splitText(){
	// processes a text string and split it into 2 columns
	// - called by /qigong/news/qigongtip_landing.html

	msg	= '';

	//reference the page elements
	src				= document.getElementById('c0');
	col1			= document.getElementById('c1');
	col2			= document.getElementById('c2');

	content			= src.innerHTML;

	col1_buffer	= '';
	col2_buffer = '';
	contentlength	= content.length;
	load2			= false;
	for (i=0;i<contentlength;i++) {
		if ( i > ((contentlength-15)/2) && !load2) {
			load2	= (content.charAt(i)==' ' ? true : false);
			msg		= 'Load2<br>';
		}
		msg	+= i+', ';
		if (load2) {
			col2_buffer	+= content.charAt(i);
		} else {
			col1_buffer	+= content.charAt(i);
		}
	}

	col1.innerHTML	= col1_buffer;
	col2.innerHTML	= col2_buffer;
	//col2.innerHTML		= msg;

}
/* ------------------------------------------------------------------------------------------------------------------------------- */
function selectNews(checkbox) {
	// customer newsletter selection code used in the Qigong Landing page
	box			=	document.getElementById(checkbox);
	checked		= box.checked;

	if (boxclick==true) {
		boxclick	= false;
	} else {
		if (checked==true) {
			box.checked	= false;
		} else {
			box.checked	= true;
		}
	}
	//document.qigong.slist_qigongsecrets.checked = true
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function printdiv(id) {
	width	= 800;
	height	= 600;

	printdiv	= document.getElementById(id);
	plinks	= '<table width=540><tr><td><a href="javascript:window.print()">Print</a></td><td align=right><a href="javascript:window.close()">Close</a></td></tr></table></center>'

	content	 = '<html><body>';
	content	+= plinks;
	content += printdiv.innerHTML;
	content	+= '</body></html>';
	displayPopup(content,width,height);

}

/* ------------------------------------------------------------------------------------------------------------------------------- */
// Tracking Cookie creation - 26/08/2005
// writeTrackIdCookie(trackid);
// writeOrigTrackIdCookie(trackid);
// writeClientIdCookie();

function writeTrackIdCookie(trackid) {
	var cookies		= document.cookie;
	document.cookie = "trackId="+ trackid + ";path=/; domain=.dragondoor.com";
}

function writeOrigTrackId(trackid) {
	expireDate			= new Date;
	yr					= expireDate.getYear();
	yr					= yr<2000 ? yr+1902 : yr+2;
	expireDate.setYear(yr);
	document.cookie		= "origTrackId=" + trackid + ";expires=" + expireDate.toGMTString() +";path=/; domain=.dragondoor.com";
}

function writeClientIdCookie(trackid) {
	expireDate			= new Date;
	yr					= expireDate.getYear();
	yr					= yr<2000 ? yr+1902 : yr+2;
	expireDate.setYear(yr);
	document.cookie		= "clientId=" +trackid + ";expires=" + expireDate.toGMTString() +";path=/; domain=.dragondoor.com";
}


/* ------------------------------------------------------------------------------------------------------------------------------- */
function getCookieValue(name) {
	cookie		= document.cookie;
	start		= cookie.indexOf(name,0);
	end			= parseCookie(cookie,start);
	csize		= end - start;

	subcookie	= cookie.substr(start,csize);
	regex		= /=(.+)/;
	value		= regex.exec(subcookie);

	if (value) {
		return value[1] 
	} else {
		return 0
	}
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function getLandingId() {
	// parse the landing id from the url
	url	= document.URL;
	regex	= /\?l=(\d+)/;
	id		= regex.exec(url);
	if (id) {	return id[1];
	} else {	return 0;}
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function appendTracking() {
	// append a tracking/landing id to select links to maintain tracking across domains
	regex			= /dragondoor/;
	var domain		= regex.exec(document.URL);
	dragondoor		= domain ? true : false;

	var trackId		= getCookieValue('trackId');
	var landId		= getLandingId();
	trackId			= trackId>0 ? trackId : landId;

	var localdomains	= new RegExp("telldragondoor\.com|telldragondoor\.info|qigongrecharge\.com|tacticalstrength\.us|tacticalpt\.com|tacticalconditioning\.com|kettleball\.com|kettleballs\.com|fromrussiawithtoughlove\.com|comradepavel\.com|russiankettlebell\.com|russiankettlebells\.com|kettlebellnation\.com|kettlebell-nation\.com|russiankettleball\.com|russiankettleballs\.com|xtremeyoga\.com|russiankettlebellchallenge\.us|abpavelizer\.com|powertothepeople\.us|tacticalfitness\.us|kettlebellbash\.com|russiankettlebellchallenge\.com|bulletproofabs\.com|healingsecrets\.com|paveltacticalstrength\.com|powercals\.com|bestfitnessmarketing\.com|qigongclasses\.com|footballsuccess\.com|maximummuscleminimumfat\.com|majorfatloss\.com|minimumfat\.com|energybreakthrough\.com|energybreakthroughs\.com|hard-style\.com|hard-style\.us|hardstyle\.us|powerbypavel\.com|vitalics\.com|sixfiguretrainingsuccess\.com|strengthsuccess\.com|strengthtrainingsuccess\.com|flexibilitysuccess\.com|mosteffectivediets\.com|thenakedwarrior\.com|strength-nutrition-qigong-kettlebells-martial-articles\.com|fix-your-yeast-infections-forever\.com|fix-your-yeast-infections\.com|fix-your-digestion-forever\.com|fix-your-immune-system-forever\.com|fix-your-immune-system\.com|fix-your-cholesterol-forever\.com|fix-your-heart-forever\.com|beat-the-flu-forever\.com|relieve-irritable-bowel-syndrome-forever\.com|relieveirritablebowelsyndrome\.com|combat-cancer-forever\.com|manage-your-weight-forever\.com|bestqigong\.com|qigong-news\.com|strength-news\.com|rkcnews\.com|kettlebellnews\.com|kettlebell-kettlebells\.com|rkcbypavel\.com|loadedstretching\.com|strengthstretching\.com|un-lock\.com|pavelsentme\.com|johnducanesentme\.com|dragondoorsentme\.com|pavelsystem\.com|pavelsystem\.net|pavelsystem\.org|pavelsystem\.us|pavelsystem\.info|pavelsystem\.biz|heartcure\.info|heartcure\.org|heartcure\.us|heartcure\.biz|faststartaffiliate\.com|faststartnow\.com|bestaffiliatesecrets\.com|106lbkettlebell\.com|106lbkettlebells\.com|48kgkettlebell\.com|48kgkettlebells\.com|26lbkettlebell\.com|26lbkettlebells\.com|12kgkettlebell\.com|12kgkettlebells\.com|35lbkettlebell\.com|35lbkettlebells\.com|16kgkettlebell\.com|16kgkettlebells\.com|44lbkettlebell\.com|44lbkettlebells\.com|20kgkettlebell\.com|20kgkettlebells\.com|53lbkettlebell\.com|53lbkettlebells\.com|24kgkettlebell\.com|24kgkettlebells\.com|62lbkettlebell\.com|62lbkettlebells\.com|28kgkettlebell\.com|28kgkettlebells\.com|70lbkettlebell\.com|70lbkettlebells\.com|32kgkettlebell\.com|32kgkettlebells\.com|88lbkettlebell\.com|88lbkettlebells\.com|40kgkettlebell\.com|40kgkettlebells\.com|9lbkettlebell\.com|9lbkettlebells\.com|4kgkettlebell\.com|4kgkettlebells\.com|13lbkettlebell\.com|13lbkettlebells\.com|6kgkettlebell\.com|6kgkettlebells\.com|18lbkettlebell\.com|18lbkettlebells\.com|8kgkettlebell\.com|8kgkettlebells\.com|kettlebellkettlebells\.biz|kettlebellkettlebells\.us|kettlebellkettlebells\.org|kettlebellkettlebells\.net|kettlebellkettlebells\.com|chikungqigong\.com|qigongqigong\.com|qigongchikung\.org|qigongchikung\.com|chikungqigong\.org|russianreds\.biz|russianreds\.us|russianreds\.tv|russianreds\.org|russianreds\.net|russianreds\.com|enterthekettlebell\.com|enterthekettlebell\.net|enterthekettlebell\.org|enterthekettlebell\.us","g");

	if (trackId>0) {

		if (dragondoor) {
			var ignoredlinks	= new RegExp("dragondoor|#|cart.pl?|mailto:|prod_order.pl?|prod_list.pl?|articles.pl|thumbs.pl|mapquest|javascript:","g");
			var kbkbs			= new RegExp("http://www.kettlebellkettlebells.com/#order","g");
			for  (var i=0;i < document.links.length;i++ ) {
				if (!document.links[i].href.match(ignoredlinks) && document.links[i].href.match(localdomains)) {
					document.links[i].href	= document.links[i].href+'?l='+trackId;
				}

				if (document.links[i].href.match(kbkbs)) {
					document.links[i].href	= 'http://www.kettlebellkettlebells.com?l='+trackId+'#order';
				}
			}

		} else {
			var qMark = new RegExp("#|cart.pl?|mailto:|prod_order.pl?|prod_list.pl?|articles.pl|thumbs.pl|mapquest|javascript:","g");
			var qJava = new RegExp("javascript:onClick=carpCookie()","g");
			var qCart = new RegExp("prod_order.pl?","g");
			for  (var i=0;i < document.links.length;i++ ) {
				if (!document.links[i].href.match(qMark) && document.links[i].href.match(localdomains)) {
					document.links[i].href	= document.links[i].href+'?l='+trackId;
				}
				if (document.links[i].href.match(qJava)) {
					document.links[i].href	= "javascript:onClick=trackCarpCookie(\'"+$trackId+"\')";
				}
				if (document.links[i].href.match(qCart)) {
					document.links[i].href	= document.links[i].href+'&l='+trackId;
				}
			}
		}
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
// GA & PAP link rewriting
/* ------------------------------------------------------------------------------------------------------------------------------- */
function getPAPIDs(mode) {

	// read the PAP cookie and return the aid/cid to be added to links
	var papcookie 	= readCookie('PAPCookie_Sale');
	if (papcookie) {
		papcookie	= unescape(papcookie);
		var cookie	= eval('(' + papcookie + ')');
		if (cookie) {
			if (cookie.a && cookie.c) {
				if (mode) { return cookie;	
				} else  { 	return "a_aid=" + cookie.a + "&a_cid=" + cookie.c;	}
			}
		}
	}
	return;
}
/* ------------------------------------------------------------------------------------------------------------------------------- */


/* ------------------------------------------------------------------------------------------------------------------------------- */
function setGoogleLinks() {
	// set up cross domain links for google analytics
	// and Post Affiliate Pro

	if (!isDev()) {
		var links		= document.getElementsByTagName('a');
		rewriteGoogleLinks(links);

		links			= document.getElementsByTagName('area');
		rewriteGoogleLinks(links);
	}

}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------ */
function rewriteGoogleLinks(links) {

	// get the TLD
	var domain_array	= document.domain.split('.');
	var lastpart		= domain_array.length - 1;
	var pagetld			= domain_array[lastpart -1] + '.' + domain_array[lastpart];

	var currenturl		= document.URL;

	for (var i=0;i<=links.length;i++) {
		if (links[i]) {
			href	= links[i].href;
			linkid	= links[i].id;

			var skiplink	= false;
			if (linkid) {
				skiplink	= linkid.match('inst_url') ? true : false;
			}

			if (href) {
				
				if (href.match(/http/) && !skiplink) {
	
					// get the href ref's TLD
					var href_array		= href.split('/');
					var domain_array	= href_array[2].split('.');
					var lastpart		= domain_array.length - 1;
					var linktld			= domain_array[lastpart - 1] + '.' + domain_array[lastpart];

					// replace the link when the link domain doesn't match the current URL's domain
					if (pagetld != linktld ) {
						//href	+= papstring ? '?' + papstring : '';
						links[i].href	= 'javascript:__utmLinker(\'' + href + '\');';
					}
				}
			}
		}
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------ */



/* ------------------------------------------------------------------------------------------------------------------------------- */
function toggleReviewRankingRows(group,show,hide,sid,eid) {

	// toogle the length of the specified review rankings
	showElement(show+group);
	hideElement(hide+group);
	
	for (lvar=sid;lvar<eid;lvar++) {
		showhide(group+lvar);
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function isDev() {
	var devcookie	= getCookieValue('devmode');
	if (devcookie == 'true') {
		return true;
	};
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function isDeveloper() {
	if (isDev()) {
		return true;
	}
	return false;

}

/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function init_testing() {
	var devmode	= isDev();
	if (devmode) {
		var devdiv	= document.getElementById('devdiv');
		if (devdiv) {	
				showElement('devdiv');
				}
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------------------------- */
