/** POPUP FOR CONVERTERS */
function converterPopUp(url){
	open(url,"","height=220,width=320,scrollbars=0; window.focus()");
}


/** ENCRYPT EMAIL ADDRESSES FOR SPAM CONTROL */
function CryptMailto(e){
	var n = 0;
	var r = "";
	var s = "mailto:"+e;

	e = e.replace( /@/, " [at] ");
	e = e.replace( /\./g, " [dot] ");

	for( var i=0; i < s.length; i++ ){
		n = s.charCodeAt( i );
		if( n >= 8364 )
			n = 128;

		r += String.fromCharCode(n+1);
	}
	
	document.write("<a href=\"javascript:linkTo_UnCryptMailto('"+ r +"');\">"+ e +"</a>");
}

function UnCryptMailto( s ){
	var n = 0;
	var r = "";
	
	for( var i = 0; i < s.length; i++){
    		n = s.charCodeAt( i );
    		if( n >= 8364 )
			n = 128;
    
    		r += String.fromCharCode( n - 1 );
	}
	
	return r;
}

function linkTo_UnCryptMailto( s ){
	location.href=UnCryptMailto( s );
}

/** POPULATES EVENT ADDRESS FORM */
function use_saved_event_address(address,country_code){

	document.getElementById('address').value=address;
	document.getElementById('country_code').value=country_code;
}

/** HIDES DIV */
function hide_div(div_id){
	//document.getElementById(div_id).style.visibility='hidden';
	document.getElementById(div_id).style.display='none';
}

/** SHOW DIV */
function show_div(div_id){
	//document.getElementById(div_id).style.visibility='visible';
	document.getElementById(div_id).style.display='block';
}

/** ON USER.ADD-VIDEO.PHP, THIS DETERMINES WHICH SELECT MENU APPEARS, SINGLE OR MULTI */
function user_video_trick_select(thisForm){
	
	// SINGLE TRICK
	if(thisForm.uv_uvc_id.value == 1){
    
		show_div('trick_select_container');
		show_div('uv_featured_trick_container');
		hide_div('uv_featured_tricks_container'); 
		hide_div('successful_trick_msg'); 
	}
	// COMBO OR TUTORIAL
	if(thisForm.uv_uvc_id.value == 2 || thisForm.uv_uvc_id.value == 8){
    
		show_div('trick_select_container');
		hide_div('uv_featured_trick_container');
		show_div('uv_featured_tricks_container'); 
		hide_div('successful_trick_msg'); 
	}
	// FORM, SAMPLER, SHOWREEL, OR CRASH COMBO
	if(thisForm.uv_uvc_id.value == 3 || thisForm.uv_uvc_id.value == 4 || thisForm.uv_uvc_id.value == 5 || thisForm.uv_uvc_id.value == 7){
	
		show_div('trick_select_container');
		hide_div('uv_featured_trick_container');
		show_div('uv_featured_tricks_container'); 
		show_div('successful_trick_msg'); 
	}
	// CRASH TRICK
	if(thisForm.uv_uvc_id.value == 6){
	
		show_div('trick_select_container');
		hide_div('uv_featured_trick_container');
		hide_div('uv_featured_tricks_container'); 
		hide_div('successful_trick_msg'); 
	}
	
}

function selectAll(field,_v){

	for(var i=0;i<document.getElementById(field).length;i++)
		document.getElementById(field)[i].selected=_v;

}

function checkAll(field,_v){
	for(var i=0;i<document.getElementsByName(field).length;i++)
		document.getElementsByName(field)[i].checked=_v;

}

function toggleDiv(box,div) {
	if (box.checked)
		show_div(div);
	else
  		hide_div(div);
}

function setOpacity(opacity) {

	if (navigator.appName.indexOf("Netscape")!=-1 &&parseInt(navigator.appVersion)>=5)
    		document.getElementById('maincontent').style.MozOpacity=opacity/100
 	else
    		document.getElementById('maincontent').style.filter = 'alpha(opacity=' + value + ')';

		//document.getElementById('maincontent').style.opacity = value;
		//document.getElementById('maincontent').style.filter = 'alpha(opacity=' + value + ')';
}


//enforce max characters on field
function ismaxlength(obj){

	var mlength=obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}


function letternumber(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function numbersonly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers only
else if ((("0123456789-.").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function nokeys(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("x").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function popUp(url) { open(url,"","height=450,width=450,scrollbars=1; window.focus()"); }
function converterPopUp(url) { open(url,"","height=220,width=320,scrollbars=0; window.focus()"); }

function openWin( windowURL, windowName, windowFeatures )
{
return window.open( windowURL, windowName, windowFeatures ) ;
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 // window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
 return myHeight;
}


function showColor(val) {
document.colorform.hexval.value = val;
document.all["colorbox"].style.backgroundColor = val;
}

function grabColor(field) {
field.value = document.colorform.hexval.value;
field.style.backgroundColor = field.value;
}

/*************** MARQUEE FIX HERE ***********************/

var oMarquees = [], oMrunning,
	oMInterv =        20,     //interval between increments
	oMStep =          1,      //number of pixels to move between increments
	oStopMAfter =     30,     //how many seconds should marquees run (0 for no limit)
	oResetMWhenStop = false,  //set to true to allow linewrapping when stopping
	oMDirection =     'left'; //'left' for LTR text, 'right' for RTL text

/***     Do not edit anything after here     ***/

function doMStop() {
	clearInterval(oMrunning);
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i];
		oDiv.mchild.style[oMDirection] = '0px';
		if( oResetMWhenStop ) {
			oDiv.mchild.style.cssText = oDiv.mchild.style.cssText.replace(/;white-space:nowrap;/g,'');
			oDiv.mchild.style.whiteSpace = '';
			oDiv.style.height = '';
			oDiv.style.overflow = '';
			oDiv.style.position = '';
			oDiv.mchild.style.position = '';
			oDiv.mchild.style.top = '';
		}
	}
	oMarquees = [];
}
function doDMarquee() {
	if( oMarquees.length || !document.getElementsByTagName ) { return; }
	var oDivs = document.getElementsByTagName('div');
	for( var i = 0, oDiv; i < oDivs.length; i++ ) {
		oDiv = oDivs[i];
		if( oDiv.className && oDiv.className.match(/\bdmarquee\b/) ) {
			if( !( oDiv = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			if( !( oDiv.mchild = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			oDiv.mchild.style.cssText += ';white-space:nowrap;';
			oDiv.mchild.style.whiteSpace = 'nowrap';
			oDiv.style.height = oDiv.offsetHeight + 'px';
			oDiv.style.overflow = 'hidden';
			oDiv.style.position = 'relative';
			oDiv.mchild.style.position = 'absolute';
			oDiv.mchild.style.top = '0px';
			oDiv.mchild.style[oMDirection] = oDiv.offsetWidth + 'px';
			oMarquees[oMarquees.length] = oDiv;
			i += 2;
		}
	}
	oMrunning = setInterval('aniMarquee()',oMInterv);
	if( oStopMAfter ) { setTimeout('doMStop()',oStopMAfter*1000); }
}
function aniMarquee() {
	var oDiv, oPos;
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i].mchild;
		oPos = parseInt(oDiv.style[oMDirection]);
		if( oPos <= -1 * oDiv.offsetWidth ) {
			oDiv.style[oMDirection] = oMarquees[i].offsetWidth + 'px';
		} else {
			oDiv.style[oMDirection] = ( oPos - oMStep ) + 'px';
		}
	}
}
if( window.addEventListener ) {
	window.addEventListener('load',doDMarquee,false);
} else if( document.addEventListener ) {
	document.addEventListener('load',doDMarquee,false);
} else if( window.attachEvent ) {
	window.attachEvent('onload',doDMarquee);
}




/* COOKIE FUNCTIONS */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
