
//puts browser window at top (out of frames) - stops bug with registering from inside hotmail frame.

if (self != top){
   if (document.images) top.location.replace(document.location.href);
   else top.location.href = document.location.href;
}




var myWindow;

function launchPopupWindow(page, name, customise, alignrightwidth) {
	if(myWindow && !myWindow.closed) {
			myWindow.close();
	}
	
	var winMargin = 10;
	
	if (alignrightwidth) {
		customise = customise + ',left='+((parseInt(screen.availWidth)-alignrightwidth)-winMargin);
		customise = customise + ',top='+winMargin;
	}

	myWindow = window.open(page,name,customise);
	myWindow.focus();
}

function objShowHide(id, state) {
  if ( state=="" ) 
  {
  	if (document.getElementById) {
  	  if ( typeof(id)=="object" ) state = id.style.display == "block" ? "none" : "block";
  	  else state = document.getElementById(id).style.display == "block" ? "none" : "block";
  	}
  	else {
  		if (document.layers) {
        if ( typeof(id)=="object" ) state = id.visibility == "block" ? "none" : "block";
        else state = document.id.visibility == "block" ? "none" : "block";
  		}
  		else { // IE 4
        if ( typeof(id)=="object" ) state = id.style.display == "block" ? "none" : "block";
    		else state = document.all.id.style.display == "block" ? "none" : "block";
  		}
  	}
  }
  
	if (document.getElementById) {
    if ( typeof(id)=="object" ) id.style.display = state;
		else document.getElementById(id).style.display = state;
	}
	else {
		if (document.layers) {
      if ( typeof(id)=="object" ) id.visibility = state;
  		else document.id.visibility = state;
		}
		else { // IE 4
      if ( typeof(id)=="object" ) id.style.display = state;
  		else document.all.id.style.display = state;
		}
	}
}

function showhelp(id, state) {
  if ( state=="" ) 
  {
  	if (document.getElementById) {
  		state = document.getElementById(id).style.display == "block" ? "none" : "block";
  	}
  	else {
  		if (document.layers) {
    		state = document.id.visibility == "block" ? "none" : "block";
  		}
  		else { // IE 4
    		state = document.all.id.style.display == "block" ? "none" : "block";
  		}
  	}
  }
  
  shownHelp = state=="block"?id:"";
  
	if (document.getElementById) {
		document.getElementById(id).style.display = state;
	}
	else {
		if (document.layers) {
			document.id.visibility = state;
		}
		else { // IE 4
			document.all.id.style.display = state;
		}
	}
}

function getobj(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	else {
		if (document.layers) {
			return document.id;
		}
		else { // IE 4
			return document.all.id;
		}
	}
}


// input functions
function clearInput(e,v) {
	if (e.value==v) {
		e.value='';
	}
}

function resetInput(e,v) {
	if( e.value=='') {
		e.value=v;
	}
}



function ShowTimeoutWarning () {
	// we append the time to the string to avoid caching
	var urldate = new Date()
	var urltime = urldate.getTime()
	document.session_reload_image.src = 'fileget.php?file=session_reload_image.png&reloadsession=start&now=' + urltime;
	setTimeout( 'ShowTimeoutWarning();', session_maxlifetime_ms );
}

//takes form elements (text and textarea) and passes to spellchecker
function openSpellChecker() {
	var speller = new spellChecker();
	speller.spellCheckAll();
}


function addEvent(elm, evType, fn, useCapture)
{
  if(elm.addEventListener)
  {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  }
  else if (elm.attachEvent)
  {
    var r = elm.attachEvent('on' + evType, fn);
    return r;
  }
  else
  {
    elm['on' + evType] = fn;
  }
}

function setimg(id) {
	//first we hide all image divs
	imgid = 'img';
	if ( id.id.indexOf("_co_")>0 ) imgid+= "_co_";
	for (var i = 0; i < id.options.length; i++) {
		if (i > 0)
		objShowHide(imgid+id.options[i].value, 'none');
	}
	if (id.value > 0) objShowHide(imgid+id.value, 'block');
}

function goURL(url)
{
  window.location.href=url;
}


function addfocusforinputs()
{
  var el = document.getElementsByTagName("input");
  for (i=0;i<el.length;i++)
  {
    var type = el[i].getAttribute("type");
    onf = "";
    if((type=="text")||(type=="password"))
    {
      if ( el[i].onfocus!=null && el[i].onfocus.toString().indexOf("{") )
      {
        onf = el[i].onfocus.toString().substring(el[i].onfocus.toString().indexOf("{"), el[i].onfocus.toString().lastIndexOf("}"));
      }
      
      addEvent(el[i], 'focus', changeinputclasson, false);
      addEvent(el[i], 'blur', changeinputclassoff, false);
    }
  }
  var el = document.getElementsByTagName("textarea");
  for (i=0;i<el.length;i++)
  {
    onf = "";
    if ( el[i].onfocus!=null && el[i].onfocus.toString().indexOf("{") )
    {
      onf = el[i].onfocus.toString().substring(el[i].onfocus.toString().indexOf("{"), el[i].onfocus.toString().lastIndexOf("}"));
    }
      
    addEvent(el[i], 'focus', changeinputclasson, false);
    addEvent(el[i], 'blur', changeinputclassoff, false);
  }
}

function changeinputclasson(e)
{
  if  ( typeof(e)=="undefined" || typeof(e.tagName)=="undefined" || e.tagName.toLowerCase()!="textarea" )
  {
    oEvent = e?e:(window.event?window.event:event);
    obj = oEvent.srcElement;
    if ( typeof(obj)=="undefined" && oEvent.target ) obj = oEvent.target;
  }
  else if ( e.tagName.toLowerCase()=="textarea" )
  {
    obj = e;
    e.focus();
  }
  obj.style.borderTop = "2px solid #a51215";
  obj.style.borderRight = "1px solid #bc220d";
  obj.style.borderBottom = "1px solid #bc220d";
  obj.style.borderLeft = "1px solid #970c0f";
}

function changeinputclassoff(e)
{
  oEvent = e?e:(window.event?window.event:event);
  obj = oEvent.srcElement;
  if ( typeof(obj)=="undefined" && oEvent.target ) obj = oEvent.target;
  obj.style.borderTop = "2px solid #cbcbcb";
  obj.style.borderRight = "1px solid #e6e6e6";
  obj.style.borderBottom = "1px solid #e6e6e6";
  obj.style.borderLeft = "1px solid #cacaca";
}

function checkaddblock()
{
  fragment = document.location.href.substring(document.location.href.lastIndexOf("#"),document.location.href.length);
  try {
  if ( fragment=="#block" ) 
  {
    o = getobj('id_block_description');
    o.focus();
  }
  else if ( fragment=="#add" ) 
  {
    o = getobj('idinvmsg');
    o.focus();
  }
  else if ( fragment=="#tag" ) 
  {
    o = getobj('id_tags');
    o.focus();
  }
  } catch (e) {}
}

function checkaddcomment()
{
  fragment = document.location.href.substring(document.location.href.lastIndexOf("#"),document.location.href.length);
  if ( fragment=="#commentform" )
  {
    o = getobj('id_comment');
    o.focus();
  }
}
function checkgoaccount()
{
  fragment = document.location.href.substring(document.location.href.lastIndexOf("#"),document.location.href.length);
  if ( fragment=="#membership" )
  {
    o = getobj('user_password');
    o.focus();
  }
}
