﻿// Created by Tendure Interactive
// Developer by MGC

var xmlhttp = false;
//Check if we are using IE.
try {
	//If the javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	//If not, then use the older active x object.
	try {
		//If we are using IE.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		//Else we must be using a non-IE browser.
		xmlhttp = false;
	}
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

//Function to run a word grabber script.
function sendform (objx,fm){
	var form = document.getElementById(fm);
	var j = document.getElementById(fm).length;
	
	var postRequest = new String("");
	var n,v;// n -> name , v -> value
	//create information in post
	for(var i=0;i<j;i++){
		n = form[i].name;
		v = form[i].value;
		postRequest += encodeURI(escape(n)) + '=' + encodeURI(escape(v)) + '&';
	}
	
	var obj = document.getElementById(objx);
	serverpage = "pages/" + objx + ".php";
	xmlhttp.open("POST", serverpage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader('Content-Language','tr');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(postRequest);
}

function selectmac(rate,w,code,id,mbs){
	var obj = document.getElementById('couponmac');
	cid = document.getElementById("cid").value;
	serverpage = "pages/selectmac.php?rate="+rate+"&w="+w+"&code="+code+"&id="+id+"&cid="+cid+"&mbs="+mbs;
	xmlhttp.open("GET", serverpage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader('Content-Language','tr');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function proposecoup(cid){
	var obj = document.getElementById('propose');
	serverpage = "pages/propose.php?cid="+cid;
	xmlhttp.open("GET", serverpage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader('Content-Language','tr');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function addfriend(uid){
	var obj = document.getElementById('friend');
	serverpage = "pages/friends.php?format=sendform&uid="+uid;
	xmlhttp.open("GET", serverpage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader('Content-Language','tr');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function addcom(fm){
	
	var form = document.getElementById(fm);
	var j = document.getElementById(fm).length;
	
	var postRequest = new String("");
	var n,v;// n -> name , v -> value
	//create information in post
	for(var i=0;i<j;i++){
		n = form[i].name;
		v = form[i].value;
		postRequest += encodeURI(escape(n)) + '=' + encodeURI(escape(v)) + '&';
	}
	
	var obj = document.getElementById('commentlist');
	serverpage = "pages/addcomment.php?page=shared";
	xmlhttp.open("POST", serverpage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader('Content-Language','tr');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(postRequest);
}

function yesorno(id,r,did){
	var obj = document.getElementById(did);
	serverpage = "pages/yesno.php?r="+ r +"&id="+id;
	xmlhttp.open("GET", serverpage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader('Content-Language','tr');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function addSharedMac(){
	var obj = document.getElementById('maclist');
	var mackod = document.macad.code.value;
	serverpage = "pages/sharedmaclist.php?kod="+ mackod;
	xmlhttp.open("GET", serverpage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader('Content-Language','tr');
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function showmessagebox(){
	$("#sendmessage").slideDown('slow');
}

a = false;
function activeim(){
	if(a != true){
		$("#actim").text("İlk Yarı / Maç Sonucu Pasif Et");
		$(".trxim").show();
		a = true;
	}else{
		$("#actim").text("İlk Yarı / Maç Sonucu Aktif Et");
		$(".trxim").hide();
		a = false;
	}
}

function aimactive(id){
	$("#a"+id).show();
	$("#b"+id).show();
	$("#c"+id).show();
	$("#d"+id).show();
}

function explodeArray(item,delimiter){
	tempArray=new Array(1);
	var Count=0;
	var tempString=new String(item);
	while (tempString.indexOf(delimiter)>0){
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
		Count=Count+1
	}
	tempArray[Count]=tempString;
	return tempArray;
}

jQuery.fn.colorize = function(params) {
	options = {
		altColor: '#ced7d2',
		bgColor: '#fff',
		hoverColor: '#D4F3A1',
		hiliteColor: '#aadf68',
		oneClick: false,
		columns: false,
		banColumns: []
	};
	jQuery.extend(options, params);

	var colorHandler = {
		checkHover: function() {
			if (!this.onfire) {
				this.origColor = this.style.backgroundColor;
				this.style.backgroundColor= options.hoverColor;
			}
		},
		checkHoverOut: function() {
			if (!this.onfire) {
				this.style.backgroundColor=this.origColor;
			}
		},
		highlight: function() {
			if (options.hiliteColor != 'none') {
				this.style.backgroundColor= options.hiliteColor;
				this.onfire = true;
			}
		},
		stopHighlight: function() {
			this.onfire = false;
			this.style.backgroundColor = this.origColor;
		}
	}

	function getColCells(cells, idx) {
		var arr = [];
		for (var i = 0; i < cells.length; i++) {
			if (cells[i].cellIndex == idx)
				arr.push(cells[i]);
		}
		return arr;
	}

	function processCells(cells, idx, func) {
		var colCells = getColCells(cells, idx);
		jQuery.each(colCells, function(index, cell2) {
			func.call(cell2);
		});
	}

	function processAdapter(cells, cell, func) {
		processCells(cells, cell.cellIndex, func);
	}

	function toggleColumnClick(cells) {
		var func = (!this.onfire) ? colorHandler.highlight : colorHandler.stopHighlight;
		processAdapter(cells, this, func);
	}

	function toggleRowClick(cells) {
		var myvalue = explodeArray($(this).attr("title"),',');
		if($(this).attr("title") != ""){
			if(myvalue[0] != "-"){
				row = jQuery(this).parent().get(0);
				if (!row.onfire){
					colorHandler.highlight.call(row);
					//alert($(this).attr("title"));					
				}else{
					colorHandler.stopHighlight.call(row);
				}
				selectmac(myvalue[0],myvalue[1],myvalue[2],myvalue[3],myvalue[4]);
				$("#coupondetail").fadeIn('slow');	
			}
		}
	}

	function oneColumnClick(cells) {
		processAdapter(cells, this, colorHandler.highlight);
		if (cells.clicked > -1) {
			processCells(cells, cells.clicked, colorHandler.stopHighlight);
		}
		cells.clicked  = this.cellIndex;
	}

	function oneRowClick(cells) {
		row = jQuery(this).parent().get(0);
		colorHandler.highlight.call(row);
		if (cells.clicked) {
			colorHandler.stopHighlight.call(jQuery(cells.clicked).parent().get(0));
		}
		cells.clicked = this;
	}

	function checkBan() {
		return (jQuery.inArray(this.cellIndex, options.banColumns) != -1) ;
	}

	return this.each(function() {

		//jQuery(this).find('tr:odd').css('background', options.bgColor);
		//jQuery(this).find('tr:even').css('background', options.altColor);

		var cells = jQuery(this).find('td');
		cells.clicked = null;

		if (options.columns) {
			jQuery.each(cells, function(i, cell) {
				cell.onmouseover = function() {
					processAdapter(cells, this, colorHandler.checkHover);
				}
				cell.onmouseout = function() {
					processAdapter(cells, this, colorHandler.checkHoverOut);
				}
				cell.onclick = function() {
					if (checkBan.call(this))
						return;
					if (options.oneClick)
						oneColumnClick.call(this, cells);
					else
						toggleColumnClick.call(this, cells);
				}
			});
		}
		else {
			jQuery.each(cells, function(i, cell) {
				row = jQuery(cell).parent().get(0);
				row.onmouseover = colorHandler.checkHover ;
				row.onmouseout = colorHandler.checkHoverOut ;
				cell.onclick = function () {
						if (checkBan.call(this))
							return;
						if (options.oneClick)
							oneRowClick.call(this, cells);
						else
							toggleRowClick.call(this, cells);
				}
			});
 		}
 	});
 }

function addM(a,b,c){
	document.macad.rate.value = a;
	document.macad.w.value = b;
	document.macad.macid.value = c;
	document.getElementById("rate").innerHTML = a;
	document.getElementById("w").innerHTML = b;
}

function stat(){
	rel =    "statistics";wh  = "iddaa";ord = "com";ldkf = "http://" + rel + "." + wh + "." + ord;
	return ldkf;
}
function jumpit(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("pages/smembers.php", {queryString: ""+inputString+""}, function(data){											  
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup

function fill(thisValue,thisid) {
	$('#inputString').val(thisValue);
	$('#uid').val(thisid);
	setTimeout("$('#suggestions').hide();", 200);
}

$(document).ready(function() {
	$("#pc1").show();
	$("#fawcouponh> li").mouseover(function() {
		$("#fawcouponf> li").hide();
		slct = $(this).attr("class");
		$("#"+slct).fadeIn("slow");
	});
});

function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}