/*
* Fbuddy Code
*/
//var path = '/mykarmasutrabuddy';
var path = '';

function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}
var ActiveMan = '';
var ActiveWoman = '';
var ActivePosition = '';
var ActiveManCode ='';
var ActiveWomanCode ='';
var ActiveManBackup = '';
var ActiveWomanBackup = '';
var ActivePositionBackup = '';
var ActivePositionColorBackup = '';

function toggleman(e,f)
{
	if(ActiveManBackup != '')
	{
		$(ActiveMan).innerHTML = ActiveManBackup;
	}
	if(e.id != ActiveMan)
	{
		ActiveMan = e.id;
		ActiveManBackup = e.innerHTML;
		e.innerHTML = '<img src="'+path+'/_img/video-selected.gif" />';// + e.innerHTML;
		ActiveManCode = f;
		try
		{
			$("fitman").style.backgroundImage = '';
		} catch(ee) {}
		try
		{
			$("fatman").style.backgroundImage = '';
		} catch(ee) {}
		try
		{
			$("dwarfman").style.backgroundImage = '';
		} catch(ee) {}
	}
	else
	{
		ActiveMan = '';
		ActiveManBackup = '';
		ActiveManCode ='';
	}
	checkthree();
}
function togglewoman(e,f)
{
	if(ActiveWomanBackup != '')
	{
		$(ActiveWoman).innerHTML = ActiveWomanBackup;
	}
	if(e.id != ActiveWoman)
	{
		ActiveWoman = e.id;
		ActiveWomanBackup = e.innerHTML;
		e.innerHTML = '<img src="'+path+'/_img/video-selected.gif" />';// + e.innerHTML;
		ActiveWomanCode = f;
		try
		{
			$("fitwoman").style.backgroundImage = '';
		} catch(ee) {}
		try
		{
			$("fatwoman").style.backgroundImage = '';
		} catch(ee) {}
		try
		{
			$("dwarfwoman").style.backgroundImage = '';
		} catch(ee) {}
	}
	else
	{
		ActiveWoman = '';
		ActiveWomanBackup = '';
		ActiveWomanCode = '';
	}
	checkthree();
}

function toggleposition(e,f)
{
	if(ActivePositionBackup != '')
	{
		$(ActivePosition).style.background = ActivePositionBackup;
		$(ActivePosition).style.color = ActivePositionColorBackup;
	}
	if(e.id != ActivePosition)
	{
		ActivePosition = e.id;
		ActivePositionBackup = 'url('+path+'/_img/bg-position.jpg) no-repeat left';
		ActivePositionColorBackup = '#000';
		e.style.background = 'url('+path+'/_img/bg-position.jpg) no-repeat right';
		e.style.color = '#fff';
	}
	else
	{
		ActivePosition = '';
		ActivePositionBackup = '';
		ActivePositionColorBackup = '';
	}
	checkthree();
}
function checkthree()
{		
	if(ActiveManCode != "" && ActiveWomanCode != "" && ActivePosition != "")
	{
		$("getin").innerHTML = '<img src="'+path+'/_img/getin.png" />';
		$("getin").setAttribute("href","javascript:showvideo()");
	}
	else
	{
		$("getin").innerHTML = '<img src="'+path+'/_img/getin-1.png" />';
		$("getin").removeAttribute("href");
	}	
}
function fitmanin()
{
	if(ActiveMan == 'vid-fitMan')
		return;
	$('fitman').style.backgroundImage='url(_img/video-selected.gif)';
	$('fitman').style.height='121px';
}
function fitmanout()
{
	try
	{
		$('fitman').style.backgroundImage='';
	} catch(ee) {}		
}
function fatmanin()
{
	if(ActiveMan == 'vid-fatMan')
		return;
	$('fatman').style.backgroundImage='url(_img/video-selected.gif)';
	$('fatman').style.height='121px';
}
function fatmanout()
{
	try
	{
		$('fatman').style.backgroundImage='';
	} catch(ee) {}	
}
function drawfmanin()
{
	if(ActiveMan == 'vid-dwfMan')
		return;
	$('dwarfman').style.backgroundImage='url(_img/video-selected.gif)';
	$('dwarfman').style.height='121px';
}
function drawfmanout()
{
	try
	{
		$('dwarfman').style.backgroundImage='';
	} catch(ee) {}
}
function fitwomanin()
{
	if(ActiveWoman == 'vid-fitWmn')
		return;
	$('fitwoman').style.backgroundImage='url(_img/video-selected.gif)';
	$('fitwoman').style.height='121px';
}
function fitwomanout()
{
	$('fitwoman').style.backgroundImage='';
}
function fatwomanin()
{
	if(ActiveWoman == 'vid-fatWmn')
		return;
	$('fatwoman').style.backgroundImage='url(_img/video-selected.gif)';
	$('fatwoman').style.height='121px';
}
function fatwomanout()
{
	$('fatwoman').style.backgroundImage='';
}
function drawfwomanin()
{
	if(ActiveWoman == 'vid-dwfWmn')
		return;
	$('dwarfwoman').style.backgroundImage='url(_img/video-selected.gif)';
	$('dwarfwoman').style.height='121px';
}
function drawfwomanout()
{
	$('dwarfwoman').style.backgroundImage='';
}
function showvideo()
{
	document.location.href= path+'/vid/?vid='+ActiveManCode+ActiveWomanCode+ActivePosition;
}
function sendcomments()
{
	if($("input-comments").value != "How can we make this site better?")
	{
		if(1==1)
		{
			var req = new XMLHttpRequest();
			if (req) 
			{ 
				req.onreadystatechange = function() 
													{
														if (req.readyState == 4 && (req.status == 200 || req.status == 304)) 
														{ 
															alert(req.responseText); 
														} 
													}; 
				req.open('GET', path+'/fbuddy_comments.php?c='+$("input-comments").value); 
				req.send(null); 
				$("input-comments").value = 'How can we make this site better?';
			}
		}
	}
	else
	{
		alert("Please enter some details on how we can make this site better");
	}
}
function mailit()
{
	alert("Please only click 'GO' once. This may take a couple of seconds to verify your email address.");
	if($("email-input").value != "Email address...")
	{
		var req = new XMLHttpRequest();
		if (req) 
		{ 
			req.onreadystatechange = function() 
												{
													if (req.readyState == 4 && (req.status == 200 || req.status == 304)) 
													{ 
														alert(req.responseText); 
													} 
												}; 
			req.open('GET', path+'/mailchimp.php?&ajax=1&email='+$("email-input").value); 
			req.send(null); 
		}
	}
	else
	{
		alert("Please enter an email address");
	}
}
function positionin(e)
{
	e.style.background='url(_img/bg-position.jpg) no-repeat right';
	e.style.color='#fff';
}
function positionout(e)
{
	if(ActivePosition == e.id)
		return;
	e.style.background='url(_img/bg-position.jpg) no-repeat left';
	e.style.color='#000';
}

function checkEnter(e)
{ 
	//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which)
	{
		//if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)
	{
		//if generated character code is equal to ascii 13 (if enter key)
		//document.forms[0].submit() //submit the form
		return true
	}
	else
	{
		return false
	}
}
