// JavaScript Document

function gotoLoc(pageName)
{
	location.href = pageName;
}

function go2anchor()
{
	varArray = document.location.href.split('?');
	if (varArray[1] != null)
	{
		varVar = varArray[1].split('||');
		if (varVar[2] == '0')
		{
			varVar[2] = null;
		}
		showFeature(varVar[0],varVar[1],varVar[2]);
	}
}

function highlightItem(item2highlight)
{
	currentItem = document.getElementById(item2highlight);
	currentItem.style.cursor = 'pointer';
	currentItem.style.color = '#28639f';
	currentItem.style.fontWeight = 'bold';
}

function unhighlightItem(item2highlight)
{
	currentItem = document.getElementById(item2highlight);
	currentItem.style.color = '#ffffff';
}

var homePix = new Array();
homePix[0] = "Yoga-Lady-Cropped";
homePix[1] = "man_boxing";
homePix[2] = "man_wrestler";
homePix[3] = "swimmers";
homePix[4] = "woman_kickboxing";
homePix[5] = "woman_tennis";
//homePix[6] = "swimmers";

function getPic()
{
	var imageDir = '_images/';
	picIndex = Math.floor(Math.random()*homePix.length);
	var fileType = '.jpg';
	document.getElementById('home_img').src = imageDir + homePix[picIndex] + fileType;
}

function showFeature(featureName,cnt,divFlags)
{
	featureNo = featureName.split('_');
	for (f_cnt=0;f_cnt<cnt;f_cnt++)
	{
		if(f_cnt == featureNo[1])
		{	
			document.getElementById(featureNo[0] + '_' + f_cnt).style.display = 'inline';
		}
		else
		{
			document.getElementById(featureNo[0] + '_' + f_cnt).style.display = 'none';
		}
	}
	if (divFlags != null)
	{
		divNameFlag = divFlags.split(',');
		for (a_cnt=0;a_cnt<divNameFlag.length;a_cnt++)
		{
			name_flag = divNameFlag[a_cnt].split('|');
			if (name_flag[1] == '0')
			{
				document.getElementById(name_flag[0]).style.display = 'none';
			}
			else
			{
				document.getElementById(name_flag[0]).style.display = 'inline';
			}
		}
	}
}

function showNews(articleName,openClose)
{
	if (openClose == 'open')
	{
		document.getElementById(articleName).style.display = 'inline';	
	}
	else
	{
		document.getElementById(articleName).style.display = 'none';	
	}
}

function popUp(winURL,winWidth,winHeight) 
{
	widthWin = 'width = ' + winWidth;
	heightWin = 'height = ' + winHeight;
	window.open(winURL,'screenShotWin',widthWin + ',' + heightWin);
}

/* Obfuscator */
var deobf_a = new Array('a|*','i|+','p|6','b|~','q|8','j|_','c|`','k|=','x|%','d|!','r|:','l|\\','y|-','e|@','s|>','m|^','f|#','n|/','g|$','z|5','h|&','t|?','o|3','u|7','v|;','w|.');
var pear_a = new Array('^3?+3/>3#?','`3/@%+3/\\\\`');
var apple_b = new Array('/@?','`3^');
var banana_c = ",";
var pineapple_d = "|";

function deObfuskator(obfWord,parts)
{
	obfWordChar = obfWord.split('');
	lenDeobf = deobf_a.length;
	var deobfStr = '';
	for (i=0;i<obfWordChar.length;i++)
	{
		for (j=0;j<lenDeobf;j++)
		{
			charSym = deobf_a[j].split(pineapple_d);
			if (parts == 0)
			{
				if (charSym[1] == obfWordChar[i])
				{
					deobfStr += charSym[0];
				}
			}
			else
			{
				if (charSym[0] == obfWordChar[i])
				{
					deobfStr += charSym[1];
				}	
			}
		}
	}
	return deobfStr;
}

function postWrite(span,cim)
{
	var spanID = document.getElementById(span);
	posta = deObfuskator('^*+\\?3') + ':' + cim;
	spanID.innerHTML = '<a href="' + posta + '">' + cim + '</a>';
}

function postObf(a,b)
{
	bloop = '^3?+3/>3#?';
	blop = '/@?';
	var post_to = '';
	post_to += deObfuskator(a);
	post_to += '@';
	post_to += deObfuskator(bloop);
	post_to += '.';
	post_to += deObfuskator(blop);
	postWrite(b,post_to);
}

function obf(acceptVar,rejectVar,npVar,totVar)
{
	var a = deObfuskator(acceptVar,0);
	var b = deObfuskator('e',1);
	var c = deObfuskator(pear_a[rejectVar],0);
	var d = deObfuskator('w',1);
	var e = deObfuskator(apple_b[npVar],0);
	var cim = a.concat(b,c,d,e);
	var post_to = '';
	post_to += '<a href="' + deObfuskator('^*+\\?3',0) + ':' + cim + '"';
	if (totVar != '')
	{
		post_to += ' class="' + totVar + '"';
	}
	post_to += '>' + cim + '</a>';
	return (post_to);
}

// Facebook share popup script
function fbs_click() 
{
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

// Field validation
function validate_required(field,regvar,alerttxt)
{
	var regvar = new RegExp(regvar);
	if (regvar.test(field.value)==false)
	{
		alert(alerttxt);
		return false;
	}
	else 
	{
		return true;
	}
}

// Makes sure that only one checkbox is checked
// And, if there is a field to specify your answer
// it appears/disappears along with the checkbox selection
function singleClick(fieldName,otherFieldName)
{
	// Checkbox field of the current checkbox
	var fieldID = document.getElementById(fieldName);
	// If there is specify field for the current checkbox
	if(document.getElementById(otherFieldName))
	{					   
		// Specify field
		var otherfieldID = document.getElementById(otherFieldName);
		// Clear the value of the specify field
		// So that if the user changes their selection
		// the value of the previous field doesn't get submitted along with the new value
		otherfieldID.value = '';
	}
	// The amount of checkboxes in the group
	var boxCnt = 6;
	// If the checkbox exists
	// Run through all of the checkboxes
	for (i=0;i<boxCnt;i++)
	{
		var currentFieldID = i + '_Cnt'; 
		var currentField = document.getElementById(currentFieldID);

		var currentSpecifyID = i + '_specific';
		
		// If the checkbox is not the current checkbox
		if (fieldName != currentFieldID)
		{
			currentField.checked = false; // Uncheck box
			if (document.getElementById(currentSpecifyID))// If there is a specify field
			{
				document.getElementById(currentSpecifyID).style.visibility = 'hidden';// Hide the specify field
			}
		}
		else // If the checkbox is the current checkbox
		{
			if (document.getElementById(currentSpecifyID))
			{
				var specifyField = document.getElementById(currentSpecifyID);
				if (specifyField.style.visibility == 'visible')
				{
					specifyField.style.visibility = 'hidden';// Display the specify field
					currentSpecifyID.value = '';
				}
				else
				{
					specifyField.style.visibility = 'visible';// Hide the specify field
				}
			}
		}
	}
}

// Jumps from one form field to the next
function jumpFields(formName, fieldName, fieldValue, charLength, jumpLength)
{		
	if (fieldValue.length >= charLength) // If strLength or more
	{
		var myFormElements = document.forms[formName];
		for (i = 0; i < myFormElements.length; i++)
		{
			if (myFormElements.elements[i].name == fieldName)
			{
				myFormElements.elements[i + jumpLength].focus();
			}
		}
	}
}

// The div containing the table in which the image will be placed
var imageContainer = 'image_container';
// The div for the image caption
var captionContainer = 'caption';
// The div in which the image will be placed
var imageSpace = 'image_space';

// Shows the full screen shot image
function showFullImg(img_name,caption,e)
{
	var imgSpace = document.getElementById(imageSpace);
	imgSpace.innerHTML = '<img src="_images/_eclub/' + img_name + '" />';
	
	var capContainer = document.getElementById(captionContainer);
	capContainer.innerHTML = caption;

	var imgContainer = document.getElementById(imageContainer);
	imgContainer.style.position = 'absolute';
	imgContainer.style.zIndex = '2';
	imgContainer.style.top = '0px';
	imgContainer.style.left = '0px';
	imgContainer.style.display = 'inline';
	
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		mX = event.clientX;
		mY = event.clientY;
	}
	else 
	{
		mX = e.pageX;
		mY = e.pageY;
	}
	alert(mX);
}

function printEvent(e) {
   if (navigator.appName == "Microsoft Internet Explorer"){
    mX = event.clientX;
    mY = event.clientY;
  }
  else {
	document.captureEvents(Event.CLICK);
    mX = e.pageX;
    mY = e.pageY;
  }
  alert("Click at x = " + mX + " and y = " + mY);
}