// JavaScript Document
//Function use in match contribution
function showForm(id)
{
  var elem_id = gEBI('ajax_form_' + id);
  elem_id.style.display = '';
}

 function GetVarValue(field)  
 { 
   
    var match_contribution_type = document.getElementById('type_id').value;
    
    if(match_contribution_type == 'reports')
    {
      document.getElementById('title').style.display = '';
      document.getElementById('summary').style.display = '';
      document.getElementById('content').style.display = '';
      document.getElementById('url').style.display = 'none';
      document.getElementById('sitename').style.display = 'none';
    
    }
    else if(match_contribution_type == 'statistics')
    {
      document.getElementById('title').style.display = '';
      document.getElementById('summary').style.display = '';
      document.getElementById('content').style.display = '';
      document.getElementById('url').style.display = 'none';
      document.getElementById('sitename').style.display = 'none';
    }
    else if(match_contribution_type == 'highlights')
    {
      document.getElementById('title').style.display = '';
      document.getElementById('summary').style.display = '';
      document.getElementById('content').style.display = 'none';
      document.getElementById('url').style.display = '';
      document.getElementById('sitename').style.display = '';
    }
    else if(match_contribution_type == 'preview')
    {
      document.getElementById('title').style.display = '';
      document.getElementById('summary').style.display = '';
      document.getElementById('content').style.display = '';
      document.getElementById('url').style.display = 'none';
      document.getElementById('sitename').style.display = 'none';
    }
    else
    {
      document.getElementById('title').style.display = 'none';
      document.getElementById('summary').style.display = 'none';
      document.getElementById('content').style.display = 'none';
      document.getElementById('url').style.display = 'none';
      document.getElementById('sitename').style.display = 'none';
    }
}

function checkFields()
{
  
  if(document.getElementById('type_id').value == '')
  {
    var type = "Select Type\n";
  }
  else
  {
    var type = "";
  }
  
  if(document.getElementById('selLeagues').value == 0)
  {
    var league = "Select Leagues\n";
  }
  else
  {
    var league = "";
  }
 
  var error = type+league;
  
  if(error == '')
  {
    return true;
  }
  else
  {
    alert (error);
  
    return false;
  }
}
//This function use in match contribution for 
//displaying all teams of specific leagues.
function GetAllTournament(id)
{ 

  if(id =='')
  {
    alert("Please Select League");
    
  }
  else
  {
   
  var url = website_url+'ajax/matchcontributions/allTournament/';
 
  new Ajax.Request(url,{
      method: 'post',
      parameters: {id:id},
      onSuccess: function(transport) {
            var response = transport.responseText;    
            //alert(response);
             document.getElementById('tournamentDiv').innerHTML = "&nbsp;&nbsp;"+response; 
             document.getElementById('tournament').style.display = '';
      },
      onFailure: function(){ alert('Something went wrong...') }
    });
  
  }
}

function GetTournamentTeamDropdowns(tournament_id)
{
  //alert("hi");
  GetTournamentTeam(tournament_id,1);
  GetTournamentTeam(tournament_id,2);
}

function showTeams(dropdown)
{
  //alert("hi"+dropdown);
  if(dropdown == 2)
            { 
             document.getElementById('teamtables').style.display = '';
             
            } 
}
//This function use in match contribution for 
//displaying all teams of specific leagues.
function GetTournamentTeam(tournament_id,dropdown)
{ 
  //alert("first"+dropdown);
  if(tournament_id =='')
  {
    alert("Please Select Team");
    
  }
  else
  {
   
  var url = website_url+'ajax/matchcontributions/allTeam/';
 
  new Ajax.Request(url,{
      method: 'post',
      parameters: {tournament_id:tournament_id,dropdown:dropdown},
      onSuccess: function(transport) {
            var response = transport.responseText;    
             //alert(response);
             document.getElementById('team_'+dropdown).innerHTML = "&nbsp;&nbsp;"+response; 
             showTeams(dropdown);
            
      },
      onFailure: function(){ alert('Something went wrong...') }
    });
  
  }
}


/*print part of Page*/

function printPartOfPage(elementId,hidden_field)
{
  
 var hidden = document.getElementById(hidden_field);
 
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, '');
 
 printWindow.document.write(hidden.innerHTML); 
 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}

function openpopup(url,width,height,toolbar,scrollbars) 
{
  //alert("hi"+url);
  if( width==null || width==0)
  {
    width = 500;
  }
  if(height==null || height==0)
  {
    height = 500;
  }
  if( toolbar==null)
  {
    toolbar = 0;
  }
  if(scrollbars==null)
  {
    scrollbars = 0;
  }
  
  window.open(
        url, 'abcdef',
        'width='+width+',height='+height+',toolbar='+toolbar+',location=0,directories=0,status=0,menubar='+scrollbars+',scrollbars=0,resizable=0');
  
      
}

function redirectTo(id,urlpage)
{
var id = id;
var urlpage = urlpage;

//alert(id);
//alert(urlpage);

//var form = document.getElementById("frmselectbox");
//alert(form);
//form.submit();
window.location = website_url+urlpage+'/'+id+'/';  
}

function redirectArchive(urlpage)
{
var date = document.getElementById('start_date').value;

if(date=="")
{
  var urlpage = website_url+'news/archive/';
}
else
{
    var urlpage = website_url+'news/archive/date/'+date;
}
//var form = document.getElementById("frmselectbox");
//alert(form);
//form.submit();
window.location = urlpage;  
}

function redirectToTransferCenter(id)
{

//alert(id);
var urlpage = website_url+'news/viewtransfercenter/t_date/'+id;

window.location = urlpage;  
}


/* Book Mark Site */
function bookmark(title,url)
{

  if (window.sidebar) 
  {
    	window.sidebar.addPanel(title, url, "");
  }
  else if(window.opera && window.print)
  { 
  	var elem = document.createElement('a');
  	elem.setAttribute('href',url);
  	elem.setAttribute('title',title);
  	elem.setAttribute('rel','sidebar');
  	elem.click();
  } 
  else if(document.all)
  {
    window.external.AddFavorite(url, title);
  }
}

function getComponent(module_name, component_name, tpl, get_params, post_params, callback_func, elem_id)
{
  var url = website_url+'ajax/'+module_name+'/'+component_name+'/'+tpl+'/'+'?'+get_params;
  
  new Ajax.Request(url,{
      method: 'post',
      parameters: post_params,
      onSuccess: function(transport) {
            var response = transport.responseText;
            //alert(response);
            if (callback_func != undefined)
            {
              var eval_str = callback_func + "(response";
              if (elem_id != undefined)
              {
                eval_str += ", elem_id";
              }
              eval_str += ')';
              
              eval(eval_str);
            }
      },
      onFailure: function(){ alert('Something went wrong...') }
    });
}

function updateComponent(elem_id, module_name, component_name, tpl, get_params, post_params)
{
  var elem = gEBI(elem_id);
  if (elem != undefined)
  {
    getComponent(module_name, component_name, tpl, get_params, post_params, "updateElement", elem_id);
  }
  else
    return;
}

function updateElement(response, elem_id)
{
  var elem = gEBI(elem_id);
  
  if (elem != undefined)
  { 
    elem.innerHTML = response;
  }
  else
    return;
}

//Captch Reload Code 
function reload_captcha(element)
{
  url=website_url+'captcha.php?'+Math.round(Math.random()*10000+1);
  document.getElementById(element).src=url;
}

//check box
function showDiv(id,text_pos)
{
  div_id = document.getElementById(id);
  img_div_id = document.getElementById("img_"+id);
  if(div_id.style.display == "none")
  {
   img_div_id.src = icon_path+"drop_cross.gif";
   img_div_id.title = "Click to Close Options";
   div_id.style.display = "block";
   text_element = document.getElementById(text_pos);
   text_element_pos = findPos(text_element);
   
   div_id.style.left = text_element_pos[0];
   
   var browser=navigator.appName;
   if (browser=="Microsoft Internet Explorer")
   {
    div_id.style.top = text_element_pos[1] + 19;
   } 
   else
   {
    div_id.style.top = text_element_pos[1] + 10;
   } 
  }
  else
  {
    div_id.style.display = "none";
    img_div_id.src = icon_path+"drop.gif";
    img_div_id.title = "Click to Select Options";
  }
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function hideDiv(id)
{
  div_id = document.getElementById(id);
  if(div_id.style.display == "block")
  {
    div_id.style.display = "none";
  }
}

function showDiv_always(id)
{
  div_id = document.getElementById(id);
  div_id.style.display = "block";
}

function prepare_option(form_id) 
{
var formblock_op;

formblock_op= document.getElementById(form_id);
forminputs = formblock_op.getElementsByTagName('input');

return forminputs;
}

function select_options(formname,name, value) 
{

  forminputs = prepare_option(formname);
  
  for (i = 0; i < forminputs.length; i++) 
  {
    // regex here to check name attribute   
    
    var regex = new RegExp(name, "i");
    //alert(forminputs[i].getAttribute('name'));
    if (regex.test(forminputs[i].getAttribute('name')) || 1) 
    {
      //alert(forminputs[i]);
      if (value == 1) 
      {
         //alert('select');
        forminputs[i].checked = true;
      } 
      else 
      {
        forminputs[i].checked = false;
      }
    }
  }
}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function autoFill(from_id, to_id)
{
  var to_field = document.getElementById(to_id);
  var from_field = document.getElementById(from_id)
  if(to_field.value == '')
  {
    from_field = from_field.value.replace(/[^a-zA-Z 0-9]+/g,'');
  	from_field = from_field.toLowerCase();
  	from_field = String.replace(from_field," ","-");
  	to_field.value = from_field;
  }	
}
