var arrLayers = new Array("lyrServer", "lyrGame", "lyrView", "lyrFire");

function swapLayers(id, objThis) {
  for (var intI=0; intI<arrLayers.length; intI++) {
    if (arrLayers[intI]==id) {
      document.getElementById(id).style.display='block';
    } else {
      document.getElementById(arrLayers[intI]).style.display='none';
    }
  }
  return false;
}

function quoteSelection(user) { 
	theSelection = false;
	bname=navigator.appName;
	
	if (bname.indexOf("Microsoft")!=-1) {
	  theSelection = document.selection.createRange().text; // Get text selection
	}
	if (bname.indexOf("Netscape")!=-1) {
	  theSelection = document.getSelection();
	}
	
	if (user) {
		quote_text = '[quote=' + user + ']\n';
	} else{
		quote_text = '[quote]\n';
	}
	
	if (theSelection) {
	  // Add tags around selection 
	  emoticon( quote_text + theSelection + '\n[/quote]\n');
	  document.post.comment.focus();
	  theSelection = '';
	  //scrollTo(0,document.body.scrollHeight);
	  return;
	} else {
	  // Workaround for opera + we dont need to annoy the users with a javascript alert
	  if (typeof turska != "undefined" && turska) {
	  	emoticon( quote_text + turska + '\n[/quote]\n');
	  	document.post.comment.focus();
	  	turska = '';
	  	//scrollTo(0,document.body.scrollHeight);
	  } else {
		  return;
	  }
	}
}

function assignselectiontotempvar() {
	bname=navigator.appName;
	if (bname.indexOf("Microsoft")!=-1) {
	  return;
	} else {
	  turska = document.getSelection();
    }
}


function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function emoticon(text) {
	if (document.post.comment.createTextRange && document.post.comment.caretPos) {
	  var caretPos = document.post.comment.caretPos;
	  caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	  document.post.comment.focus();
	} else {
	  document.post.comment.value  += text;
	  document.post.comment.focus();
	}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function pg_repo() {
  var rp_width;
  rp_width = document.images['repo'].width;
//  alert(rp_width);
  if (rp_width > 200 & document.body.clientWidth < 1015 ) {
    document.getElementById("ap_1").align = "center"
  }
}

function OpenPPWindow(theURL,windowname,w,h,features) {
  if (! window.focus)return true;
  if (w >= screen.width) w = w - 30;
  if (h >= screen.height) h = h -30;
  //document.write(w,h)
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  if (typeof(theURL) == 'string')
    href=theURL;
  else
    href=theURL.href;
  properties = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+features
  //document.write(properties)
  window.open(href, windowname, properties);
  return false;
}

function rolloverButton (id, state) {
  if (document.getElementById) {
    var element_id = document.getElementById(id);
	if (state == 'over') {
	  element_id.className = 'cmt_buttonover'
	}else if (state == 'down') {
	  element_id.className = 'cmt_buttondown'
	}else {
	  element_id.className = 'cmt_button_norm'
	}
  }
}

function disableForm(theform) {
  if (document.all || document.getElementById) {
    for (i = 0; i < theform.length; i++) {
      var tempobj = theform.elements[i];
      if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") {
        tempobj.disabled = true;
	  }
    }
	//setTimeout('alert("How Many Time Do You Want To Press The Submit Button.")', 4000);
	return true;
  }  else {
    alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
	return false;
  }
}

function resize() {
 var rtempObj = eval("document.getElementById('pdg');");
 var tablewidth;
 tablewidth = document.body.clientWidth;
 rtempObj.style.display= ( tablewidth > 850 ? "block" : "none");
}

function getCookie(NameOfCookie)
{ if (document.cookie.length > 0) 
{ begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) 
{ begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); } 
}
return null; 
}

function setCookie(NameOfCookie, value, expiredays, path, domain) 
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + 
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString())+
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "");
}

function delCookie (NameOfCookie) 
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

function roadblock() {
  var roadblock_referer = getCookie('rb-referer');
  if (roadblock_referer == null) {
    setCookie('rb-referer',window.location,1,"",'ngagegaming.com');
    window.location.href="/roadblock.shtml";
  }
}

function rb_return() {
  var roadblock_referer = getCookie('rb-referer');
  if (roadblock_referer != null) {
    window.location.href=roadblock_referer;
  }
}

function rb_print() {
  var roadblock_referer = getCookie('rb-referer');
  if (roadblock_referer != null) {
    document.write(roadblock_referer);
  } else {
    document.write('ngagegaming');
  }
}
