// funny bunny homepage JS
var site_root = 'http://www.tooshocking.com/';

function xmlHttp()
{
	var xmlHttp;
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		xmlHttp = new XMLHttpRequest();
	} 
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		 catch (e) 
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{
				// Something went wrong
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
	return xmlHttp;
}
function XMLParser(text)
{
	var xmlDoc;
	try //Internet Explorer
  	{
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false";
	  xmlDoc.loadXML(text);
  	}
	catch(e)
 	{
		try //Firefox, Mozilla, Opera, etc.
		{
		  parser=new DOMParser();
		  xmlDoc=parser.parseFromString(text,"text/xml");
		}
		catch(e)
		{
		  alert(e.message);
		  return;
		}
	}
	return xmlDoc;
}

function checkEmailFormat(email)
{
	var EmailRegex = new RegExp("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$");
	if(EmailRegex.test(email))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function subscribeNewsletter()
{
	var ajaxRequest = xmlHttp();
	
	email = document.getElementById('nl_email').value;
	daily = document.getElementById('nl_daily').value;
	weekly = document.getElementById('nl_weekly').value;
	
	document.getElementById('nl_response').style.display = 'none';
	
	if(checkEmailFormat(email))
	{
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				xml = XMLParser(ajaxRequest.responseText);
				
				 email_avail = xml.getElementsByTagName("response")[0].attributes.getNamedItem("status").nodeValue;
				 text = xml.getElementsByTagName("response")[0].childNodes[0].nodeValue;
				 
				 if(email_avail == 1)
				 {
					 document.getElementById('nl_response').className = 'nl_errors';
					 document.getElementById('nl_response').style.display = 'block';
					 
				 }
				 if(email_avail == 0)
				 {
					 document.getElementById('nl_response').className = 'nl_success';
					 document.getElementById('nl_response').style.display = 'block';
					 document.getElementById('nl_form').style.display = 'none';
				 }
				 document.getElementById('nl_response').innerHTML = text;
				
			}
		}
		ajaxRequest.open("GET", "/newsletterSubscribe.php?e="+email+"&d="+daily+"&w="+weekly+"&rand="+Math.random(), true);
		ajaxRequest.send(null);
	}
	else
	{
		document.getElementById('nl_response').style.display = 'block';
		document.getElementById('nl_response').innerHTML = 'Please Enter a Valid Email';
	}
	
}

function newsletterAutoControl(waitTime)
{
	waitTime = waitTime*1000;
	
	setTimeout("newsletterModalControl('open', 'no')", waitTime);
	
}
function newsletterModalControl(method, forceOpen)
{
	nl_cookie = 'no';
	
	if(method == 'close')
	{
		document.getElementById('light').style.display='none';
		document.getElementById('fade').style.display='none';
		setCookie('nl_rmb', 'yes', 30);		
	}
	
	if(method == 'open')
	{
		nl_cookie = getCookie('nl_rmb');
				
		if(forceOpen == 'yes')
		{			
			document.getElementById('light').style.display='block';
			document.getElementById('fade').style.display='block';
			
		}
		
		if(nl_cookie == 'yes')
		{
			
		}
		else
		{
			document.getElementById('light').style.display='block';
			document.getElementById('fade').style.display='block';
		}
	}
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
function homeVideoTabs(tab, p) {	
	
	var ajaxRequest = xmlHttp();
	
	ajaxRequest.open("GET", site_root+"homeVideoTabs.php?tab="+tab+"&p="+p+"&id="+Math.random(), true);
	ajaxRequest.send(null);
	ajaxRequest.onreadystatechange = function(){
	
	
		if(ajaxRequest.readyState == 4)
		{			
			
			if(ajaxRequest.status == 200)
			{
				
				document.getElementById("middle_video").innerHTML = ajaxRequest.responseText;
				document.getElementById("loading").style.display = 'none';
				
				document.getElementById("popular").className="tab_normal";
				document.getElementById("rated").className="tab_normal";
				document.getElementById("discussed").className="tab_normal";
				
				document.getElementById(tab).className="tab_selected";
								
			}
			else 
			{
				document.getElementById("middle_video").innerHTML = "Server Not Responding";
			}
		}
	}
}
function addClicks(id){
	
	ajaxRequest = xmlHttp();
	
	ajaxRequest.open("GET", site_root+"addPlugClick.php?id="+id+"&rn="+Math.random(), true);
	ajaxRequest.send(null);
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if(ajaxRequest.status == 200)
			{
				
			}
			else
			{
			
			}
		}
	}
}
function loginShow(id, lid)
{
	
	if(document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
		document.getElementById(lid).innerHTML = "Login -";
	}
	else
	{
		document.getElementById(id).style.display = 'none';	
		document.getElementById(lid).innerHTML = "Login +";
	}
}
homeVideoTabs('popular', '0');

$(document).ready(function(){
		$("body").click(function() {								 
					 
		if($.cookie("opened") != "true")
		{
			newwindow = window.open('http://www.evilchili.com/videos/32551/Snowmobile_Bucks_The_Rider','mywindowts','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
			newwindow.blur();
			$.cookie("opened", "true");
		}
			
		});
});