var currentState;

function SetState(state){
    currentState = escape(state);
}

function GetState(ordinal){
    var returnState = window.location.hash;
	returnState = strip(unescape(returnState));
	var params = returnState.split(",");
	return params[ordinal];
}

function HasState(){
    var testState = window.location.hash;
    if (testState != null){
        if (testState != ""){
                return true;
        }
    }
    else
        return false;
}

function strip(data){
    var result = "";
    var i = 0;
    for(i=0; i<=data.length; i++)
        if(data.charAt(i) != "#")
            result += data.charAt(i);   
    return result
}

function GoTo(url){
    window.location.hash = currentState;
    window.location.href = url;
}

/*
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
  var c = ca[i];
  while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
 
alert(readCookie("MemberGUID"));
*/


function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = 365 * expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : ".break.com" ) +
		( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}




var memberCookie = getCookie("MemberActive");
var memberRememberCookie = getCookie("MemberAuthentication");

//alert("session" + memberCookie);
//alert("remember ME" + memberRememberCookie);

function checkingCookies(){
if(document.cookie)
{

}
else{
window.location="http://info.break.com/static/live/v1/pages/ageverification_gotd.html";
}
}

function checkingCookiesMovies(){
if(document.cookie)
{

}
else{
window.location="http://info.break.com/static/live/v1/pages/ageverification_movies_nsfw.html";
}
}

function checkingCookiesPictures(){
if(document.cookie)
{

}
else{
window.location="http://info.break.com/static/live/v1/pages/ageverification_pictures_nsfw.html";
}
}


function logInOut(){
//if((memberCookie || memberRememberCookie) != null) 
//{
//document.getElementById('logInLayer').style.display="none";
//document.getElementById('logOutLayer').style.display="block";
//}
//else{
//document.getElementById('logInLayer').style.display="block";
//document.getElementById('logOutLayer').style.display="none";
//}
}

function memberEnterIn(){
if((memberCookie || memberRememberCookie || cookieOver) != null) 
{

}
else{
window.location="http://info.break.com/static/live/v1/pages/ageverification_gotd.html";
}
}

function memberEnter(){
if((memberCookie || memberRememberCookie) != null) 
{
window.location="http://girls.break.com/";
}
else{
window.location="http://info.break.com/static/live/v1/pages/ageverification_gotd.html";
}
}

function memberEnterBreakingNews(){
if((memberCookie || memberRememberCookie) != null) 
{
window.open("http://girls.break.com/")
}
else{
window.open("http://info.break.com/static/live/v1/pages/ageverification_gotd.html")
}
}


function memberMoviesEnter(){
if((memberCookie || memberRememberCookie) != null) 
{
window.location="http://www.break.com/movies_nsfw/movies_nsfw.html";
}
else{
window.location="http://info.break.com/static/live/v1/pages/ageverification_movies_nsfw.html";
}
}

function memberMoviesEnterIn(){
if((memberCookie || memberRememberCookie) == null) 
{
window.location="http://info.break.com/static/live/v1/pages/ageverification_movies_nsfw.html";
}
}


function memberPicturesEnter(){
if((memberCookie || memberRememberCookie) != null)  
{
window.location="http://www.break.com/pictures_nsfw/pictures_nsfw.html";
}
else{
window.location="http://info.break.com/static/live/v1/pages/ageverification_pictures_nsfw.html";
}
}

function memberPicturesEnterIn(){
if((memberCookie || memberRememberCookie) == null)  
{
window.location="http://info.break.com/static/live/v1/pages/ageverification_pictures_nsfw.html";
}
}

function ReformatImg(id) 
{
	 
        if(document.images["imageResize"].width > 435)
        {
          document.images["imageResize"].width = '435';
        }
		/*		
	    if((document.getElementById("imageResize").style.width = document.images["imageResize"].width) > 435)
	    {
	      document.getElementById('imageResize').style.width = '435';
	    }
	   */
}


/////////////////////////////////////
//Read feedback cookie
/////////////////////////////////////
function readFeedbackCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}
////////////////////////////////////
// Is Logged In
////////////////////////////////////
function IsLoggedIn()
{       
  var memberCookie = getCookie("MemberActive");
  var memberRememberCookie = getCookie("MemberAuthentication");   
  var memberIdCookie = getCookie("MemberID");
  return (((memberCookie || memberRememberCookie) != null)&&(memberIdCookie != null))? true:false;               
}

// JScript File
function addEvent(obj, evType, fn){
			 if (obj.addEventListener){
				 obj.addEventListener(evType, fn, true);
				 return true;
			 } else if (obj.attachEvent){
				 var r = obj.attachEvent("on"+evType, fn);
				return r;
			 } else {
				return false;
			 }
		}

function emailCheck (emailStr) {
	//alert("inside method: " + emailStr)
	emailStr = emailStr.replace(" ","");
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	//alert("User: " + user)
	//alert("UserPat: " + userPat)
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    //alert("The username doesn't seem to be valid.")
	    return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
			//alert("Destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
	    return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   alert(errStr)
	   return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function UpdateButtonState(strValue,bIsEnabled, sId)
{
	var objBtn = document.getElementById(sId)
	objBtn.value = strValue;
	objBtn.disabled = (bIsEnabled)?false:true;
}
function ClearTextFields(strFieldsArray)
{
	if(strFieldsArray==null ||
		strFieldsArray=="")
		return;
		
	var listOfFields = strFieldsArray.split(",")
	
	if(listOfFields.length==0)
		return;
		
	for(i=0;i<listOfFields.length;i++)
	{
		var frmField = document.getElementById(listOfFields[i]);
		frmField.value = "";		
	} 	
}

function SwapImage(objImg, src)
{
  objImg.src=src;
}
function SwapImage2(objImg, src, objLink, href)
{
  alert(objImg.src)
  alert(objLink);
  objImg.src=src;
  objLink.href= href;
}
   // stop browsers from crashing on errors
   function stopError() {
           return true;
   }
   window.onerror = stopError;
   

function addLoadEvent(func){
   var oldOnload = window.onload;
   
   if(typeof(window.onload) != "function")
      window.onload = func;
   else{
      window.onload = function(){
         if(oldOnload)
            oldOnload();
         func();
      }
   }
}

/**
 * @author ieling
 */

function SetUrlParam(pParamName, pParamValue)
{
	var sQuery = this.window.location.search;
	var sNewQuery= "";
	
	if(sQuery.length > 0)
	{
		sQuery = sQuery.substring(1);
		
		var sParams = sQuery.split("&");
		
		alert("sparam.length: " + sParams.length);
		for(var i = 0; i < sParams.length; i++)
		{
			var sParamPair = sParams[i].split("=");
			sParamName = unescape(sParamPair[0]);
			sParamValue = unescape(sParamPair[1]);
			
			if(sParamName != pParamName)
			{
				sNewQuery += escape(sParamName) + "=" + escape(sParamValue) + "&";
			}
		}
	}
	
	sNewQuery += escape(pParamName) + "=" + escape(pParamValue);
	this.window.location.search  = "?" + sNewQuery;
}

function GetUrlParam(pParamName)
{
	var sParamValue = "";
	var sQuery = this.window.location.search.substring(1);
	if(sQuery.length > 0)
	{
		var sParams = sQuery.split("&");
		for(var i = 0; i < sParams.length; i++)
		{
			var sParamPair = sParams[i].split("=");
			sParamName = unescape(sParamPair[0]);
			sParamValue = unescape(sParamPair[1]);
			
			if(sParamName == pParamName)
			{
				return sParamValue;
			}
		} 
	}
	
	return "";
}

function BuildUrlParam(pName, pValue)
{
	return escape(pName) + "=" + escape(pValue);
}

//////////////////////////////////
//Hide div
//////////////////////////////////
function HideDiv(divId)
{
	var oDiv = document.getElementById(divId);
	oDiv.style.display = "none";          
}
//////////////////////////////////
//Show div
//////////////////////////////////
function ShowDiv(divId)
{
	var oDiv = document.getElementById(divId);
	oDiv.style.display = "inline";
}  
//////////////////////////////////
//Toggle box  
//////////////////////////////////
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
	if(document.layers)	   //NN4+
	{
		document.layers[szDivID].visibility = iState ? "show" : "hide";
	}
	else if(document.getElementById)	  //gecko + IE 5+
	{
		var obj = document.getElementById(szDivID);
		obj.style.visibility = iState ? "visible" : "hidden";
	}
	else if(document.all)	// IE 4
	{
		document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
	}
}
//////////////////////////////////
//Hide box
//////////////////////////////////
function hideBox(szDivID, iState) // 1 visible, 0 hidden
{
	if(document.layers)	   //NN4+
	{
		document.layers[szDivID].visibility = iState ? "show" : "hide";
	}
	else if(document.getElementById)	  //gecko + IE 5+
	{
		var obj = document.getElementById(szDivID);
		obj.style.visibility = iState ? "visible" : "hidden";
	}
	else if(document.all)	// IE 4
	{
		document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
	}
}


///////////////////////////////////
// FCOmma : Adds commas to a given large integer.
//////////////////////////////////
   function FComma(SS) {
    var T = "", S = String(SS), L = S.length - 1, C, j, P = S.indexOf(".") - 1;
    if (P < 0) {
        P = L;
    }
    for (j = 0; j <= L; j++) {
        T += C = S.charAt(j);
        if (j < P && (P - j) % 3 == 0 && C != "-") {
            T += ",";
        }
    }
    return T;
	}
