if($('.chatonline')){
	$.getJSON(getBaseURL() + 'chatzone/buddylist', function(data) {
		/* */
		if(!IsEmpty(data) && !IsEmpty(data.row.length)) {
			var content = '';
			var i;
			for (i = 0; i < data.row.length; i++) {
				content = content + '<div onclick="javasript:jqcc.cometchat.chatWith(' + data.row[i].id + ')" class="chat_link">' + data.row[i].name + '</div>';
			}
			$('.chatonline').html(content);
		}
		/* */
	});
};
function checkAll(status, form) {
	if (status.checked) {
		for (i = 0; i < form.length; i++) {
			if(form[i].type == 'checkbox') {
				form[i].checked = true;
			}
		}
	} else {
		for (i = 0; i < form.length; i++) {
			if(form[i].type == 'checkbox') {
				form[i].checked = false;
			}
		}
	}
}
function send_private_message(form) {
	if (form.subject.value == '' || form.message.value == '') {
		alert('Completati campurile goale');
		return false;
	}
	return true;
}
function check_answer(form) {
	var checked = false;
	var answer = form.elements.answer;
	for (var i=0; i<answer.length; i++) {
		if (answer[i].checked) {
			checked = true;
      		break;
    	}
	}
	if(!checked)
		alert("Alege un raspuns. Da sau Nu?");
   return checked ;
}
function validTackling(form) {
	var valid = false;
	for (var i=0; i < form.length; i++) {
		if (form.user_id[i].checked) {
			valid = true;
		}
	}
	if (!valid) {
		alert('Trebuie sa selectezi un membru pentru al-l provoca.');
		return false;
	}
	return true;
}
function modal_window(title, message) {
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container',
		onShow: function (dialog) {
			$('.header span').html(title);
			$('.message', dialog.data[0]).append(message);
		}
	});
}
function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}
function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));

    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }
}

function change_clasamente(id, type) {
//	var names = ["ROMANIA", "ANGLIA", "SPANIA", "ITALIA", "GERMANIA", "FRANTA", "OLANDA", "TURCIA"];
	if(type == 'campionate') {
		var names = ["ROMANIA", "ANGLIA", "SPANIA", "ITALIA", "GERMANIA", "FRANTA"];
	} else if(type == 'euro') {
		var names = ["EUROqualificationgrpA", "EUROqualificationgrpB", "EUROqualificationgrpC", "EUROqualificationgrpD", "EUROqualificationgrpE", , "EUROqualificationgrpF", "EUROqualificationgrpG","EUROqualificationgrpH","EUROqualificationgrpI"];
	} else if(type == 'Champions League') {
		var names = ["ChampionsLeaguegrpA", "ChampionsLeaguegrpB", "ChampionsLeaguegrpC", "ChampionsLeaguegrpD", "ChampionsLeaguegrpE", , "ChampionsLeaguegrpF", "ChampionsLeaguegrpG","ChampionsLeaguegrpH"];
	} else if(type == 'Europa League') {
		var names = ["EuropaLeaguegrpA", "EuropaLeaguegrpB", "EuropaLeaguegrpC", "EuropaLeaguegrpD", "EuropaLeaguegrpE", , "EuropaLeaguegrpF", "EuropaLeaguegrpG","EuropaLeaguegrpH", "EuropaLeaguegrpI", , "EuropaLeaguegrpJ", "EuropaLeaguegrpK","EuropaLeaguegrpL"];
	}
	for(var i in names) {
		if(document.getElementById(names[i]) != null) {
			if (names[i] == id) {
				document.getElementById(names[i]).style.display = 'block';
			} else {
				document.getElementById(names[i]).style.display = 'none';
			}
		}
	}
}

function change_scorers(id) {
//	var names = ["ROMANIA", "ANGLIA", "SPANIA", "ITALIA", "GERMANIA", "FRANTA", "OLANDA", "TURCIA"];
	var names = ["ROMANIA__", "ANGLIA__", "SPANIA__", "ITALIA__", "GERMANIA__", "FRANTA__", "OLANDA__", "PORTUGALIA__", "TURCIA__", "RUSIA__", "CHAMPIONS_LEAGUE__"];
	for(var i in names) {
		if(document.getElementById(names[i]) != null) {
			if (names[i] == id) {
				document.getElementById(names[i]).style.display = 'block';
			} else {
				document.getElementById(names[i]).style.display = 'none';
			}
		}
	}
}


function change_cl_clasamente(id) {
	var names = ["cl_grupa_a", "cl_grupa_b", "cl_grupa_c", "cl_grupa_d", "cl_grupa_e", "cl_grupa_f", "cl_grupa_g", "cl_grupa_h"];
	for(var i in names) {
		if (names[i] == id) {
			document.getElementById(names[i]).style.display = 'block';
		} else {
			document.getElementById(names[i]).style.display = 'none';
		}
	}
}
function change_el_clasamente(id) {
	var names = ["el_grupa_a", "el_grupa_b", "el_grupa_c", "el_grupa_d", "el_grupa_e", "el_grupa_f", "el_grupa_g", "el_grupa_h", "el_grupa_i", "el_grupa_j", "el_grupa_k", "el_grupa_l"];
	for(var i in names) {
		if (names[i] == id) {
			document.getElementById(names[i]).style.display = 'block';
		} else {
			document.getElementById(names[i]).style.display = 'none';
		}
	}
}

function wc_clasamente(id) {
	var names = ["wcq_grupa_1", "wcq_grupa_2", "wcq_grupa_3", "wcq_grupa_4", "wcq_grupa_5", "wcq_grupa_6", "wcq_grupa_7", "wcq_grupa_8"];
	for(var i in names) {
		if (names[i] == id) {
			document.getElementById(names[i]).style.display = 'block';
		} else {
			document.getElementById(names[i]).style.display = 'none';
		}
	}
}
function ec_clasamente(id) {
	var names = ["ecq_grupa_1", "ecq_grupa_2", "ecq_grupa_3", "ecq_grupa_4", "ecq_grupa_5", "ecq_grupa_6", "ecq_grupa_7", "ecq_grupa_8", "ecq_grupa_9"];
	for(var i in names) {
		if (names[i] == id) {
			document.getElementById(names[i]).style.display = 'block';
		} else {
			document.getElementById(names[i]).style.display = 'none';
		}
	}
}
function IsEmpty(string) {
	if ((string == null) || (string.length == 0)) {
		return true;
	} else {
		return false;
	}
}
function cite(id) {
	var element = document.getElementById(id);
	if(element.style.display != 'none') {
		element.style.display = 'none';
	} else {
		element.style.display = 'block';
	}
}
