
$(document).ready(function(){
  //To detect flash
 // var plg =   pluginlist;
//  if(plg == ""){        
  //  document.getElementById('media-container').innerHTML = '<img src="assets/images/flash-banner.gif" alt="" />';
  //  document.getElementById('media-container').style.border = '1px solid #EFEFEF';
//  }
 var basicObj = new basicFunctions();
 var pageName = basicObj.getPage();
 basicObj.updatePlayerCount();
 /*$("#closepopup").click(function(){
   basicObj.hidePopup();
 }); */
 if(pageName == 'index.php' || pageName == '' ){
  document.getElementById('home').style.color = '#D81C2A';
  //basicObj.showPopup();
 }
 else if(pageName == 'aboutus.php'){
   document.getElementById('about').style.color = '#D81C2A';
 }
 else if(pageName == 'our-team.php'){
   document.getElementById('ourteam').style.color = '#D81C2A';
 }
 else if(pageName == 'products.php' || pageName == 'gaming.php' || pageName == 'gamingnetwork.php' || pageName == 'gamingtechnology.php'){
   document.getElementById('products').style.color = '#D81C2A';
 }
 else if(pageName == 'services.php' || pageName == 'games-servicesapi.php' || pageName == 'manage-services.php' || pageName == 'application-services.php' || pageName == 'professional-services.php'){
   document.getElementById('services').style.color = '#D81C2A';
 }
 else if(pageName == 'clientele.php'){
   document.getElementById('clients').style.color = '#D81C2A';
 }
 else if(pageName == 'partners.php'){
   document.getElementById('partners').style.color = '#D81C2A';
 }
 else if(pageName == 'careers.php' || pageName == 'currentopenings.php'){
   document.getElementById('careers').style.color = '#D81C2A';
 }
 else if(pageName == 'news.php' || pageName == 'iphoneappforhob.php' || pageName == 'igtsignsdeal.php' || pageName == 'news2010.php'|| pageName == 'news2009.php' || pageName == 'news2008.php' || pageName == 'news2007.php' || pageName == 'news2006.php' || pageName == 'IGAawards2011.php' || pageName == 'cozygamesenterssocialgaming.php' || pageName == 'newssep2010.php' || pageName == 'newssep2010-two.php' || pageName == 'newsmay2010.php' || pageName == 'newsjan2010.php' || pageName == 'may2011-news.php' || pageName == 'may2011-5thnews.php'){
   document.getElementById('news').style.color = '#D81C2A';
 }
 else if(pageName == 'contact.php'){
   document.getElementById('contact').style.color = '#D81C2A';
 }
 if(pageName =='news-accordion.php' || pageName =='news.php'|| pageName =='IGAawards2011.php' || pageName =='cozygamesenterssocialgaming.php' || pageName == 'newssep2010.php' || pageName == 'newssep2010-two.php' || pageName =='newsmay2010.php' || pageName =='newsjan2010.php' || pageName =='news2009.php' || pageName =='news2008.php' || pageName =='news2007.php' || pageName =='news2006.php' || pageName == 'may2011-news.php' || pageName == 'may2011-5thnews.php' || pageName == 'iphoneappforhob.php' || pageName == 'igtsignsdeal.php' || pageName =='news2010.php'){
   $("#currentnews-accordion").accordion({header: "h3", autoHeight:false});
   $("#archivenews-accordion").accordion({header: "h3", autoHeight:false});
 }
//To make ajax call in markets-two
  $("#link-products").click(function(){
     basicObj.loadPage('products.html');
  });
  $("#link-markets").click(function(){
     basicObj.loadPage('markets.html');
  });
  $("#link-platforms").click(function(){
     basicObj.loadPage('platforms.html');
  });
});
var basicFunctions  = new Function();
// Function to get UA
basicFunctions.prototype.getUserAgent = function(){
var uaName = window.navigator.appName;
return uaName;
}
// Function to get host
basicFunctions.prototype.getHost = function(){
  var host = window.location.host;
  var protocol = window.location.protocol;
  var url = protocol+"//"+host; 
  return url;
}
//function to the page name
basicFunctions.prototype.getPage = function(){
  var path = window.location.href;
  var pos = path.lastIndexOf("/")+1;
  var page = path.substr(pos);
  page = page.split('#'); 
  return page[0];
}
basicFunctions.prototype.showPopup = function(){
  $("#overlay").fadeIn('fast');
  $("#popup-container").fadeIn(3000).delay(2000);
}
basicFunctions.prototype.hidePopup = function(){
  $("#popup-container").fadeOut(3000);
  $("#overlay").fadeOut('slow');
}
basicFunctions.prototype.loadPage = function(pageUrl){
  $.ajax({
    url:pageUrl,
    cache:false,
    success:function(data){
      $("#ajax-container").html(data);
    },
    error:function(){
      console.log("OOPs an error has occurred");
    }
  });
}
basicFunctions.prototype.updatePlayerCount = function(){  
  var monthlyCount='';
  var category;
  var tempCount;
  try{
  $.ajax({
    url:'/assets/xml/playercount.xml',
    cache:'false',
    dataType:'xml',
    success:function(xml){
      $(xml).find('monthlycount').each(function(){
        category = $.trim($(this).find('category').text());
        monthlyCount = $.trim($(this).find('count').text());
        if(monthlyCount !== ''){
          tempCount = '<li>'+monthlyCount+'</li>';
          category = "#"+category;
          $(category).html(tempCount);
        }
      });      
    },
    error:function(){     
    // console.log('An Error has occurred');
    }
  });
}catch(exp){
  alert(exp);
}
}
/*IE7 compatible code to invoke keydown event to close popup*/
/*$(function(){
  var nObj = new basicFunctions();
  $(document).keydown(function(event){    
    if(event.keyCode == 27){
      nObj.hidePopup();     
    }
  });
});*/
// index page events change
/*function ChangeDiv()
{
	var count 	= 	$("#newstext > div").size();
	var rand	=	Math.floor(Math.random()*count)
	var divname = 	"event"+(rand+1);
	$("#"+divname).show("slow").siblings().hide("slow");	
}
setInterval ( "ChangeDiv()", 2500 ); */

function validateContactform(){
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

if($('#first_name').val() == ''){
  alert('Please Enter First Name');
  $('#first_name').focus();
  return false;
}
else if($('#last_name').val() == ''){
  alert('Please Enter Last Name');
  $('#last_name').focus();
  return false;
}
else if($('#company').val() == ''){
  alert('Please Enter company Name');
  $('#company').focus();
  return false;
}
else if($('#email').val() == ''){  
  alert('Please Enter Email');
  $('#email').focus();
  return false;
}
else if(!filter.test($('#email').val())){
  alert('Please Enter Valid Email');
  $('#email').focus();
  return false;
}
else if($('#phone').val() == ''){
  alert('Please Enter Phone Number');
  $('#phone').focus();
  return false;  
}
else if(isNaN($('#phone').val()) == true){
  alert('Please Enter valid Phone Number');
  $('#phone').focus();
  return false;
}
else if($('#message').val() == ''){
  alert('Please Enter Message');
  $('#message').focus();
  return false;  
}
else {
  return true;
  $('form-contact').submit();
}
}
