/*
// var Browser={
//   CodeName:(navigator.appCodeName),
//   BrowseName:navigator.appName,
//   BrowserVersion:navigator.appVersion,
//   BrowserCookies:navigator.cookieEnabled,
//   Platform:navigator.platform,
//   UserAgent:navigator.userAgent
// }

//alert(Browser);
*/
function _$() {
	var elements = new Array();
		alert(arguments);
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string'){
			element = document.getElementById(element);
		      }
		if (arguments.length == 1){
			return element;
		}
		elements.push(element);
	}
	return elements;
}

function boxDisplay(toHide,toShow,FX){
hide=toHide.split('.');

for(el in hide){
if(FX=='noFX'){
  document.getElementById(hide[el]).style.display='none';
}else{
$('#'+hide[el]).hide('slow');
}
}
show=toShow.split('.');
for(el in show)
{
if(FX=='noFX'){
 document.getElementById(show[el]).style.display='block';
}else{
$('#'+show[el]).show('slow');
}
}

}


var alertContents=Array(0,1);

var JSON_NIKI={
	http_request_referer:false,
	http_request:Array(0,1),
	DoRequest:function(url, parameters,rtype,callback,loader){

	var process_id=JSON_NIKI.http_request.length;
	JSON_NIKI.http_request[process_id] = false;
	if (window.XMLHttpRequest){
	  JSON_NIKI.http_request[process_id] = new XMLHttpRequest();
	  if (JSON_NIKI.http_request[process_id].overrideMimeType) {
		JSON_NIKI.http_request[process_id].overrideMimeType('text/xml');
	  }
	}else if(window.ActiveXObject){
	  try { JSON_NIKI.http_request[process_id] = new ActiveXObject("Msxml2.XMLHTTP"); }
	  catch (e){
	    try { JSON_NIKI.http_request[process_id] = new ActiveXObject("Microsoft.XMLHTTP"); }
	    catch (e) {}
	  }
	}
	if (!JSON_NIKI.http_request[process_id])
	{
	alert('Giving up :( Cannot create an XMLHTTP instance');
	return false;
	}

		alertContents[process_id]=function(){
			if (JSON_NIKI.http_request[process_id].readyState == 4 ){
				if (JSON_NIKI.http_request[process_id].status == 200){
				xmldoc  = JSON_NIKI.http_request[process_id].responseXML;
// alert(JSON_NIKI.http_request[process_id].responseXML);
					try{    eval(xmldoc.getElementsByTagName("JavaScript")[0].firstChild.nodeValue); }
					catch(e){
//					    alert(e+"\n"+JSON_NIKI.http_request[process_id].responseText); 
					}
				}else{
				}
			}
		}
		JSON_NIKI.http_request[process_id].onreadystatechange = alertContents[process_id];
		if(rtype=='get'){
			JSON_NIKI.http_request[process_id].open("GET", url+"?"+parameters, true);
		}else{

			JSON_NIKI.http_request[process_id].open('post', url, true);
			try{ JSON_NIKI.http_request[process_id].overrideMimeType("text/xml"); }catch(e){} /// IE DOES NOT SUPPORT THIS

 			JSON_NIKI.http_request[process_id].setRequestHeader("AJX-HTTP-REFERER",JSON_NIKI.http_request_referer);
 			JSON_NIKI.http_request[process_id].setRequestHeader("Content-length", parameters.length);
 			JSON_NIKI.http_request[process_id].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 			JSON_NIKI.http_request[process_id].setRequestHeader("Connection", "close");
		}
//  alert(parameters);
	JSON_NIKI.http_request[process_id].send(parameters);
	},

	terminate_request:function(process_id,loader){
		JSON_NIKI.http_request[process_id].abort();
		document.getElementById(loader).innerHTML="<CENTER><br \/><br \/><br \/><br \/>Proces Terminated<br \/>";
	}
}


function PadDigits(n, totalDigits)
    {
        n = n.toString();
        var pd = '';
        if (totalDigits > n.length)
        {
            for (ia=0; ia < (totalDigits-n.length); ia++)
            {
                pd += '0';
            }
        }
        return pd + n.toString();
    }

function calendar_callback(d,m,Y,calback,div){
 date = new Date();  today = date.getDate();  tomonth = date.getMonth();  toyear = date.getFullYear();
i=toyear+""+PadDigits((parseInt(tomonth)+1),2)+""+PadDigits(today,2);i=parseInt(i);
j=Y+PadDigits((parseInt(m)+1),2)+PadDigits(d,2);j=parseInt(j);
  if(i<j){
    window.location="http://"+document.domain+"/matches_date_results/"+Y+"-"+PadDigits((parseInt(m)+1),2)+"-"+PadDigits(d,2)+""; // feature
  }else if(i>j){
    window.location="http://"+document.domain+"/matches_date_results/"+Y+"-"+PadDigits((parseInt(m)+1),2)+"-"+PadDigits(d,2)+""; // past
  }else{
    window.location="http://"+document.domain+"/matches_date_results/"+Y+"-"+PadDigits((parseInt(m)+1),2)+"-"+PadDigits(d,2)+""; // past
  }
}

function submit_lg(id){
if(id!="0"){ window.location="http://"+document.domain+"/l_main/"+id; }
}

function selected_team(id){
if(id!="0"){ window.location="http://"+document.domain+"/team/"+id; }
}



function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if JavaScript 
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if CSS 
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}



function submit_form(obj) {
  path=obj.action;  var request = "";  var el = new Array();
  ez=el.concat(obj.getElementsByTagName("input"),obj.getElementsByTagName("select"),obj.getElementsByTagName("radio"),obj.getElementsByTagName("textarea"));
  for(i in ez){   for(j in ez[i]){	if((ez[i][j].name && ez[i][j].name!='undefined' && encodeURIComponent(ez[i][j].value)!='undefined')){ request+=ez[i][j].name+"="+encodeURIComponent(ez[i][j].value)+"&";     }} }
//alert(request);
  JSON_NIKI.DoRequest(''+path+'',request+"&RSP=SimpleSOAP");
return false;
}

function getElementsByClassName(classname, node) {
  if(!node) node = document.getElementsByTagName("body")[0];
  var a = [];
  var re = new RegExp('\\b' + classname + '\\b');
  var els = node.getElementsByTagName("*");
  for(var i=0,j=els.length; i<j; i++)
  if(re.test(els[i].className))a.push(els[i]);
  return a;
}


function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i") : null;
var oCurrent;
var oAttribute;
	for(var i=0; i<arrElements.length; i++){
	oCurrent = arrElements[i];
	oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
return arrReturnElements;
}


function validate(form){

  if(document.getElementById('username_is_bizzy').value+''=='1'){
    alert(document.getElementById('username_is_bizzy_alert').innerHTML);
    return false;
  }
//if(document.getElementById('f2_nickname')){  if(document.getElementById('f2_nickname').style.background-color=='#FF704D'){alert (document.getElementById('f2_nickname').value+' is in use');return false;};}
var i=getElementsByAttribute(document.body,'input','validate');
e='';
for (j in i){
var vtype =(i[j].getAttribute('validate'));
  if(vtype=='username'){
    var n=validate_username(i[j].value)
    e+=(n?'':'invalid username\n');
    if(!n){ i[j].style.background='#FF6666'; }else{ i[j].style.background=''; }
  }
  if(vtype=='password'){
    var n=validate_password(i[j].value)
    e+=(n?'':'invalid password\n');
    if(!n){ i[j].style.background='#FF6666'; }else{ i[j].style.background=''; }
  }
  if(vtype=='email'){
    var n=validate_email(i[j].value)
    e+=(n?'':'invalid email\n');
    if(!n){ i[j].style.background='#FF6666'; }else{ i[j].style.background=''; }
  }
}
// (e.length>0?alert(e):false); 
 return (e.length>0?false:true); 
}

function validate_username(username){
illegalChars = /\W/; 
if(username.length==0) return false;
return (illegalChars.test(username)?false:true);
}
function validate_password(password){
  if(!password) return false;
  return (password.length>1?true:false);
}
function validate_email(email){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  return ((email.search(validRegExp) == -1)?false:true); 
}



function insertIntoTextarea(emo){
obj=document.getElementById('comment_txt');
if(obj.innerHTML){ obj.innerHTML=obj.innerHTML+' '+emo+' ';}
else{ obj.value=obj.value+' '+emo+' '; }
}
//var i=getElementsByAttribute(document.body,'a','ajaxable');




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




// onMouseover="showtip(this,event,'0')" onMouseOut="hidetip() 		<----usage 1
// onMouseover="showtip(this,event,'text')" onMouseOut="hidetip() 	<----usage 2

           
     function showtip(current,e,num){


               elm=document.getElementById("tooltip");
               elml=current;
	       elm.innerHTML=num;
               elm.style.height=elml.style.height
//                elm.style.top=parseInt(elml.offsetTop+elml.offsetHeight+10)+'px'
//                elm.style.left=parseInt(elml.offsetLeft+elml.offsetWidth-80)+'px'
		z=getMouseXY(e);
                elm.style.top=parseInt(z[1]+10)+'px'
                elm.style.left=parseInt(z[0]+10)+'px'

               elm.style.visibility = "visible"
	       elm.style.display="block";


        }
	function hidetip(){
	  if(document.getElementById) 
	    {
	      elm.style.display="none";
	      elm.style.visibility="hidden"
	    }
	}



function getMouseXY(e) {

  var IE = document.all?true:false
  if (!IE) document.captureEvents(Event.MOUSEMOVE)
  document.onmousemove = getMouseXY;
  var tempX = 0
  var tempY = 0

  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  c= new Array(tempX,tempY);
  return c;
}


