
function get_id(id_name)
{
	if (document.all)
	{
		element_id = eval("document.all." + id_name);
	}
	else if (document.getElementById)
	{
		element_id = eval("document.getElementById('" + id_name + "')");
	}
	else if (document.layers)
	{
		element_id = eval("document." + id_name);
	}
	
	return element_id;
	
}


function toogle_div(div_id, status)
{
	id = get_id(div_id);
	
	switch (status)
	{
		case 1:
		{
			id.style.display = 'block';
			break;
		}
		case -1:
		{
			id.style.display = 'none';
			break;
		}
		default:
		{
			if (id.style.display == 'none')
			{
				id.style.display = 'block';
			}
			else
			{
				id.style.display = 'none';
			}
			break;
		}
		
	}
	
	return true;
}


function external_links() 
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];
		if ((anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external")))
		{
			anchor.target = "_blank";
		}
	}
	
}
window.onload = external_links;


function open_popup(url) 
{

	w = 520;

	h = 520;

	sw = screen.width;

	sh = screen.height;

	l = (sw - w) / 2;

	t = (sh - h) / 2;

	window.open(url, 'evomediasoft', 'width='+w+',height='+h+',top='+t+',left='+l+',scrollbars=no,resizable=no');	

}


var xmlhttp;
var httpdiv;

function get_url2div(url, div)
{
	httpdiv = div;
	try
	{
		xmlhttp = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				return false;
			}
		}
	}
	
	if (xmlhttp != null)
	{
		xmlhttp.onreadystatechange = url2div_statechange;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}
	
	return true;
}

function url2div_statechange()
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
//			alert(httpdiv);
			get_id(httpdiv).innerHTML = xmlhttp.responseText;
		}
	}
	
	return true;
}

function home_answer(id, max, base_div, q_div)
{
	var i;
	var j = '';
	for(i = 1; i <= max; i++)
	{
		if (id == i)
		{
			j = i + '';
			get_id (base_div + j + '').style.display = "block";
			get_id (q_div + j + '').className = "q_div_sel";
		}
		else
		{
			j = i + '';
			get_id (base_div + j + '').style.display = "none";
			get_id (q_div + j + '').className = "q_div_simple";
		}
	}
	return true;
}


function populate_city_list(){
	
	state_select = document.getElementById('src_state');
	state_id = state_select.selectedIndex;
	
	
	var url_sir = "http://bcr.tenispartener.ro/_public/populate_city_list.php?state=" + state_id;
	var html = $.ajax({
		url: url_sir,
		async: false
	}).responseText;
	
	
	city_select = document.getElementById('city_select_div');
	
	city_select.innerHTML = html;
}

function display_div(){
	$('#friend_id').removeClass('hidden');
}

function hide_div(){
	$('#friend_id').addClass('hidden');
}

function toogle_offer(id, description, short_description){
	if (document.getElementById('offer_link' + id).innerHTML == 'TOATA OFERTA <img src="http://bcr.tenispartener.ro/_public/resources/imgs/ro/arrow.jpg">'){
		document.getElementById('offer_link' + id).innerHTML = 'INCHIDE';
		document.getElementById('prod_description' + id).innerHTML = description;
	}
	else {
		document.getElementById('offer_link' + id).innerHTML = 'TOATA OFERTA <img src="http://bcr.tenispartener.ro/_public/resources/imgs/ro/arrow.jpg">';
		document.getElementById('prod_description' + id).innerHTML = short_description;
	}
}

function reset_err_message(base_www, img_res){
	
	document.getElementById('login_err').innerHTML='';
	document.getElementById('reset_pass_err').innerHTML = '';
	
	document.getElementById('reset_pass_cnt_container').innerHTML = '<div id="reset_pass_cnt"><h1>Resetare parola</h1>	<form name="reset_pass_frm" method="post" action="' + base_www + 'action/reset_password"><table class="reset_pass_tbl" ><tr><td class="qlog_td1" style="padding-left: 30px;  "><strong>Adresa e-mail:</strong></td><td style="text-align:left; " valign="top" ><input type="text" name="email" class="reset_pass_input"  value="" /></td>   </tr></table><input type="hidden" name="reset_pass_hdn" value="1" /><div class="buton_login_div"><img style="cursor:pointer" src="'+ img_res +'btn-316-r.jpg" onclick="document.reset_pass_frm.submit()" /></div></form>        </div>';

}

//////////////////////////////////////////////////////////////////////////////////////
// functii login noi /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

/*
 * seteaza campul hidden 'destination_field' cu valoarea parametrului destination
 * astfel ca, la submit, sistemul sa stie unde sa redirectioneze userul dupa ce
 * s-a efectuat login-ul
 */
function setDestination(destination){
	var destField = document.getElementById('destination_field');
	destField.value = destination;
	
}

///////////////////////////////////////////////////////////////////////////////////////
// sfarsit functii login noi //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////
//functii foto-video ///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

function change_gallery(){
var dropdownIndex = document.getElementById('select_gallery').selectedIndex;
var dropdownValue = document.getElementById('select_gallery')[dropdownIndex].value;
window.location = "http://bcr.tenispartener.ro/ro/gallery/" + dropdownValue;
}

function centerPhoto(id, src){
var img_elem = document.getElementById("thumb" + id);
var img = new Image();
img.src = src;
if (img.complete){
img_elem.style.marginTop = (87 - img.height) / 2 + 'px';
img_elem.style.marginBottom = (87 - img.width) / 2 + 'px';
}
}

function play_video(id){
var url_sir = "http://bcr.tenispartener.ro/_public/fotovideo_video_play.php?id="+id;
var html = $.ajax({
url: url_sir,
async: false
}).responseText;
document.getElementById('video_div').innerHTML=html;
}

function showImage(src, id, type, imgRes, basew, srcThumb, index2, noItems, page, nextPage, prevPage){

document.getElementById('main_image').innerHTML="<img style='margin-left:2px;margin-top:2px;' src='"+src+"' width='475' height='318'/>";
document.getElementById(id).innerHTML='<div id="arr'+id+'" class="div_arrow"><img class="arrow" src="'+imgRes+'arrow-1.jpg"/></div><div id="thumb_div'+id+'" class="selected_thumb_div"><a href="#" onclick="showImage(\'' + src + '\', '+ id +', \''+type+'\', \''+imgRes+'\', \''+basew+'\', \''+srcThumb+'\', ' + index2 + ', ' + noItems + ', '+page+','+nextPage+','+prevPage+')"><img id="thumb'+id+'" class="thumb selected" src="'+srcThumb+'" /></a></div>';
document.getElementById(id).style.marginTop = '-12px';

var kids = $('#thumbs_list').children();

for (i=0; i<kids.length; i++){

if (kids[i].id != id){

$('#thumb'+kids[i].id).removeClass('selected');
$('#arr'+kids[i].id).html('');
document.getElementById(kids[i].id).style.marginTop = '0px';
$('#thumb_div'+kids[i].id).removeClass('selected_thumb_div');
}
}



var url_sir = "http://bcr.tenispartener.ro/_public/fotovideo_homeitems.php?id="+id+"&type="+type;
var html = $.ajax({
url: url_sir,
async: false
}).responseText;
//alert(html);	
var myObject = eval('(' + html + ')');

var title = myObject.title;
var description = myObject.description;
var itemIndex = myObject.selectedIndex;

$('#description').html(description);
$('#title').html(title);

if (type == 'video'){
$('#type').html('VIDEO');
}
else {
$('#type').html('FOTO');
}
var href=basew+type+'/';
if (type == 'video'){
href += 'categorie=-turneu=-data=/';
href+= itemIndex;
}

if (type == 'gallery'){
href += '/'+id;
}
$('#aplay').attr('href', href);


var nextIndex = (index2+1 > noItems) ? 1 : index2 + 1;
var prevIndex = (index2 == 1) ? noItems : index2-1 ;

var nextId = myObject.nextId;
var nextType = myObject.nextType;
var nextSrc = myObject.nextSrc;
var nextThumb = myObject.nextThumb;
var prevId = myObject.prevId;
var prevType = myObject.prevType;
var prevSrc = myObject.prevSrc;
var prevThumb = myObject.prevThumb;

var changePagePrev = false;
if (index2 % 5 == 1){
changePagePrev = true;
}

var changePageNext = false;
if (index2 % 5 == 0 || (index2 % 5 == noItems % 5 && nextPage==1) ){
changePageNext = true;
}

var functionOnPrev = 'showImage(\''+ prevSrc +'\', ' + prevId + ', \'' + prevType + '\', \'' + imgRes + '\', \'' + basew + '\', \'' + prevThumb + '\', ' + prevIndex + ', ' + noItems + ', '+page+','+nextPage+','+prevPage+');';
if (changePagePrev){
functionOnPrev = 'redirect(\''+ basew + 'acasa/'+ prevPage + '\', \'prev\');';
}

var functionOnNext = 'showImage(\''+ nextSrc +'\', ' + nextId + ', \'' + nextType + '\', \'' + imgRes + '\', \'' + basew + '\', \'' + nextThumb + '\', ' + nextIndex + ', ' + noItems + ', '+page+','+nextPage+','+prevPage+');';
if (changePageNext){
functionOnNext = 'redirect(\''+ basew +'acasa/' + nextPage + '\', \'next\');';
}

var afisIndex = index2 + (page - 1) * 5;
//alert (prevId + '(' +prevIndex + ')' + ' ' + id +  '(' +index2 + ')' + ' ' + nextId + '(' + nextIndex + ')' );

$('#nav').html('<div><span id="index">' + afisIndex + '</span> din ' + noItems + '</div><a href="#" onclick="'+ functionOnPrev + ' return false;"><img src="' + imgRes + 'btn-319_r.jpg" alt="prev" /></a> <a id="anext" href="#" onclick="' + functionOnNext + ' return false;"><img src="' + imgRes + 'btn-320_r.jpg" alt="next" /></a>');

}

function redirect(url, from){
window.location=url+'/'+from;
}
function strpos( haystack, needle, offset){
var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
return i === -1 ? false : i;
}


function videoList(page, filters, selected){

var url_sir = "http://bcr.tenispartener.ro/_public/video_list.php?page="+page+"&filters="+filters+"&selected="+selected;
var html = $.ajax({
url: url_sir,
async: false
}).responseText;
$('#video_list_container').html(html);
}

function cyclePhotos(){
document.getElementById('anext').onclick();

}
/////////////////////////////////////////////////////////////////////////////////////////
//sfarsit functii foto-video ///////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
//functii meniu /////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
function findPoz(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);

	}
	return [curleft,curtop];
}

function align(id_buton, id_submenu){
	var cucu = document.getElementById(id_buton);
	var pos = findPoz(cucu);
	
	var bubu = document.getElementById(id_submenu);
	var left = pos[0]-1;
	bubu.style.left = left+'px';
}

function select_button(id_button, img_res, id_submenu, keep_selected){
	submenu = document.getElementById(id_submenu);
	if (submenu.style.display == 'none'){
		$('#'+id_button).removeClass('menu_item');
		$('#'+id_button).addClass('menu_item_sel1');
		$('#'+id_button+'_a').html('<img class="menu_arrow" src="'+img_res+'arrow_menu_selected.jpg"');
		//numai pentru fotovideo, care are butonul de new pe el
		if (id_button == 'buton_fotovideo'){
			$('#div_new').html('<img src="'+img_res+'magazin-new_highlight.jpg" />');
		}
	}
	else if (!keep_selected){
		deselect_button(id_button, img_res);
	}
}

function deselect_button(id_button, img_res, keep_selected){
	if (!keep_selected){
		$('#'+id_button).removeClass('menu_item_sel1');
		$('#'+id_button).addClass('menu_item');
		$('#'+id_button+'_a').html('<img class="menu_arrow" src="'+img_res+'arrow_menu.jpg"');
		//numai pentru fotovideo, care are butonul de new pe el
		if (id_button == 'buton_fotovideo'){
			$('#div_new').html('<img src="'+img_res+'magazin-new.jpg" />');
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////////
//sfarsit functii meniu /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
