/* Scroll a page to page */
function scroll_page_top() {
	window.fbAsyncInit = function() {
 		 FB.Canvas.scrollTo(0,0);
	}
}
/*  This function used to create xmlhttp object */
function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
	  return new XMLHttpRequest();
  	} if (window.ActiveXObject) {
		  return new ActiveXObject("Microsoft.XMLHTTP");
	 }
	return null;
}
function invite_friends_fancy(id,url)
{
	document.getElementById(id).href=url;
}

function update_like(urllink,userid,like){
	alert(urllink);
	alert(userid);
	alert(like);
	 var xmlhttp;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	document.getElementById(id).innerHTML = "";
	var url = urllink+"updates.php?update="+id+"&page="+page_no;
	xmlhttp.onreadystatechange=function() {
	if(document.getElementById(id))	
		document.getElementById(id).innerHTML = '<img style="margin-left:155px;vertical-align:middle" src="'+urllink+'images/loading.gif" border="0">';

	 if (xmlhttp.readyState==4) {
	    document.getElementById(id).innerHTML = xmlhttp.responseText;
			      //load_scores(xmlhttp.responseText,urllink);
		  
	 }
  };
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
}
/* this function used to load today top/monthly top/recent top players */
function get_scores_update(urllink,current_tab,purpose,tab,tab1) {
	var tab_split = current_tab.split('-');
	id= tab_split[0];
	page_no = tab_split[1];
    var xmlhttp;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	document.getElementById(id).innerHTML = "";
	var url = urllink+"updates.php?update="+id+"&page="+page_no;
	xmlhttp.onreadystatechange=function() {
	if(document.getElementById(id))	
		document.getElementById(id).innerHTML = '<img style="margin-left:155px;vertical-align:middle" src="'+urllink+'images/loading.gif" border="0">';

	 if (xmlhttp.readyState==4) {
	    document.getElementById(id).innerHTML = xmlhttp.responseText;
			      //load_scores(xmlhttp.responseText,urllink);
		  
	 }
  };
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
/* this function used to load today scores/month */

function get_scores(urllink,purpose,tab,tab1) {

    var xmlhttp;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	var url = urllink+"today_score_ajax.php?purpose="+purpose;
	xmlhttp.onreadystatechange=function() {
	if(document.getElementById("today_monthly_scores"))	
		document.getElementById("today_monthly_scores").innerHTML = '<img style="margin-left:155px;vertical-align:middle" src="'+urllink+'images/loading.gif" border="0">';
	 if (xmlhttp.readyState==4) {
		  document.getElementById(tab).className='selected';
	  	  document.getElementById(tab1).className='';
		  document.getElementById(tab).style.background="#F7EB1B none repeat scroll 0 0";
  		  document.getElementById(tab1).style.background="none";
		  document.getElementById("today_monthly_scores").innerHTML = xmlhttp.responseText;
		  
	      //load_scores(xmlhttp.responseText,urllink);
		  
	 }
  };
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function tabchage(current_tab,tab,start,end,tabs,url)
{
	
	for(var i=start;i<=end;i++)
	{
		if(tab=="tab"+i) 
		document.getElementById("tab"+i).className='selected';
		else
		document.getElementById("tab"+i).className='';
		
	}

 //  increaseiFramesize();
    if(tabs==1) {
	 myTabs1.activate(current_tab);
	 	if(current_tab == "today_scores") {
			get_scores(url,'today_scores','tab8','tab9');
		}
	 return true;
	}
	
	if(tabs==2)
		myTabs3.activate(current_tab);
	if(tabs==3)
		myTabs5.activate(current_tab);

	 
}
function increaseiFramesize()
 {
	top_updates_height=0;
    pageHeight = document.getElementById('body').offsetHeight;
    pageWidth = document.getElementById('body').offsetWidth;
	bottom_updates_height = document.getElementById('bottom_updates').offsetHeight;
	if(document.getElementById('top_updates'))
		top_updates_height = document.getElementById('top_updates').offsetHeight;
 	
	var obj = new Object();
	obj.width = pageWidth;
	obj.height =  pageHeight+bottom_updates_height+top_updates_height;
	FB.Canvas.setSize(obj)	
   
 }
function close_box(){
	 	window.top.window.$.fancybox.close(); 
}
/* validate group invite form */
function group_invite(str) {
	var frmvalidator = new CustomValidation(str);
    var field_name = ["group_id"];
    var field_type = ["dropdown"];
    bool = frmvalidator.addItem(field_name, field_type);
	if(bool == true ) {
	  close_box();
	  return true;
	}
	return false;

}
		
/* my account form field validation */
function my_account_form_submit(str) {
   var frmvalidator = new CustomValidation(str);
   var field_name = ["firstName", "lastName", "age","address", "city", "state", "country", "zip","paypal_email"];
    var field_type = ["text", "text","text", "text","alpha_numeric", "alpha_numeric", "text", "text","email"];
    bool = frmvalidator.addItem(field_name, field_type);
	bool1=radio_validation("gender");
	if(bool == true && bool1 == true) {
	 // scroll_page_top();
	  window.location.hash = 'top';
	  return true;
	}
	return false;
}
/* validate gender field in my profile */
function radio_validation(field) {
if (document.getElementById("male").checked == false && document.getElementById("female").checked == false) {
	 document.getElementById("gender1").style.color = '#ff0000';
	 document.getElementById("gender1").innerHTML = 'Please select gender';
     return 0;
}else{
	 document.getElementById("gender1").style.border = '';
	 document.getElementById("gender1").innerHTML = '';
     return 1
}
}

/* create group form field validation */
function create_group_form_submit(str) {
   var frmvalidator = new CustomValidation(str);
   var field_name = ["group_name"];
    var field_type = ["min3"];
    bool = frmvalidator.addItem(field_name, field_type);
	if(bool == true){
		  return true;
   }
	return false;
}

/* create/edit prize money form field validation */
function prize_money_form_submit(str) {
   var frmvalidator = new CustomValidation(str);
   var field_name = ["StartDateMonth-StartDateYear","monthly_prize_money","group_monthly_prize_money"];
    var field_type = ["select","float","float"];
    bool = frmvalidator.addItem(field_name, field_type);
	if(bool == true)
	  return true;
	return false;
}

/* hide message */
function HideMessage() {
 if (document.getElementById('lblresult')) {
  document.getElementById('lblresult').style.display = "none";
 }
}

/* redirect page from one page to another */
function redirect_page(page_name) {
 location.href = page_name ;
}

/* confirm for deleting a record */
function confirmation(delid,pagename) {
	var answer = confirm("Do you want to delete this record?")
	if (answer){
		window.location = pagename+"/id/"+delid;
	}
}

/* Accept Friend Request */

function accept_friend_request(member_id,group_id,pagename,hide) { 
     jQuery(hide).fadeOut(300);
	 window.location = pagename+"/accept_id/"+member_id+"-"+group_id;
}

function accept_request(member_id,group_id,pagename,hide) { 
	jConfirm('Do you want to accept this friend request?', 'Confirmation Dialog', 
	    function(r) {
		if(r==true)
		{  
	      jQuery(hide).fadeOut(300);
		 window.location = pagename+"/accept_id/"+member_id+"-"+group_id;
		}
		
		});
}
/* Reject Friend Request */
function reject_request(id,pagename,hide) {
jConfirm('Are you sure you want to reject this request?', 'Confirmation Dialog', 
	    function(r) {
		if(r==true)
		{  
	    jQuery(hide).fadeOut(300);
		window.location = pagename+"/reject_id/"+id;
		}
		
		});
		
}
function setborder(id) {
	for(i = 1; i <= 2; i++){
		if(id == i){
			document.getElementById('country'+i).className= "border2px";
		}
		else{
			document.getElementById('country'+i).className= "";
		}
	}
}
jQuery(document).ready(function(){
  jQuery("#toolhelp a").tooltip({ 
    bodyHandler: function() { 
        return jQuery(jQuery(this).attr("href")).html(); 
    }, 
    showURL: false 
  });
  });  	
   /* Show Tool tip */
	function show_tooltip(value,id)
	{   
	   jQuery(id).mouseover(function() {
	     document.getElementById('data').innerHTML=value;
		   	jQuery('#tools').mouseover();
		});
	}
	/* Hide Tool Tip */
	function hide_tooltip(id)
	{
	   document.getElementById('data').innerHTML='';
	     jQuery(id).mouseout(function() {
		   	jQuery('#tools').mouseout();
		});
		 
	}

/* country change  */
function country_change(id,id1,urllink){
    var xmlhttp;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	var url = urllink+"country_time.php?country="+id;
	//alert(url);
		xmlhttp.onreadystatechange=function() {
	document.getElementById("country_name").innerHTML = 'Loding...';
	 if (xmlhttp.readyState==4) {
	 setborder(id);
	 var text = xmlhttp.responseText.split('|');
	 document.getElementById("country_name").innerHTML = text[0];
	 document.getElementById("start_date").innerHTML = text[1] ;
	 document.getElementById("end_date").innerHTML = text[5] ;
 	 document.getElementById("current_time").innerHTML = text[2] ;
	 document.getElementById("timeleft").innerHTML = text[3];
  	 document.getElementById("end_time").innerHTML = text[4] ;
     }
  };
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
return;
 
}

	


