function rldContent(t, def) {
	if (t.value == def) {
		t.value = '';
	}
}

function rldContent2(t, def) {
	if (!t.value) {
		t.value = def;
	}	
}



function hideGalPic(n) {
	if (document.getElementById) {
		document.getElementById('picNoScript_' + n).style.display = 'none';
	}
}

function doNext() {
	var bts = document.getElementsByName(NDIV);
	var i;
	
	if(currentPic < (NUM_PICS)) {
		//document.getElementById(NDIV).style.textDecoration='none';
		//document.getElementById(NDIV).style.color='';
		
		for (i = 0; i < bts.length; i ++) {
			bts[i].style.textDecoration='underline';
			bts[i].style.color='';			
		}
		
	} else {
		for (i = 0; i < bts.length; i ++) {
			bts[i].style.textDecoration='line-through';
			bts[i].style.color=DISABLECOLOR;
		}		
		
		//document.getElementById(NDIV).style.color=DISABLECOLOR;
		//document.getElementById(NDIV).style.textDecoration='line-through';
	}
}

function doBack(){
	var bts = document.getElementsByName(BDIV);
	var i;	
	
	if(currentPic > 1) {
		for (i = 0; i < bts.length; i ++) {
			bts[i].style.textDecoration='underline';
			bts[i].style.color='';			
		}		
		//document.getElementById(BDIV).style.textDecoration='none';
		//document.getElementById(BDIV).style.color='';
	} else {
		for (i = 0; i < bts.length; i ++) {
			bts[i].style.textDecoration='line-through';
			bts[i].style.color=DISABLECOLOR;
		}			
		//document.getElementById(BDIV).style.color=DISABLECOLOR;
		//document.getElementById(BDIV).style.textDecoration='line-through';
	}
	//alert(bts[0].style.textDecoration);
}

function showDiv(nDiv) {	
	for(var i = 1; i <= NUM_PICS; i++) {
		
		//~ if (NUM_PICS > 1) {
			//~ document.getElementById(LINKID_PREF + i).style.backgroundPosition= '0 0';
			//~ document.getElementById(LINKID_PREF + i).className = '';
			
			//document.getElementById(LINKID_PREF + i).style.color= currentPicColor;
		//~ }
		
		var buttonid = i;
		var id = PICID_PREF + i;
		var node = document.getElementById(id);
		if(node && i==nDiv) {
			node.style.display='block';
			currentPic = i;
			document.getElementById(LINKID_PREF + i).style.backgroundPosition= '0 -112px';
			//document.getElementById(LINKID_PREF + currentPic).style.color= unselectedColor;
		} else if(node) {
			node.style.display='none';
			document.getElementById(LINKID_PREF + i).style.backgroundPosition= '';
		}
	}
	doBack();
	doNext();
}

function showRelDiv(nDiv) {
	for(var i = 1; i <= NUM_PICS; i++) {
		
		var buttonid = i;
		var id = PICID_PREF + i;
		var node = document.getElementById(id);
		if(node && i==nDiv) {
			node.style.display='block';
			currentPic = i;
		} else if(node) {
			node.style.display='none';
		}
	}
	doBack();
	doNext();		
}

function showDivPrev() {
	if(currentPic > 1) {
		if (!RelGall) {
			showDiv(currentPic - 1);
		} else {
			showRelDiv(currentPic - 1);
		}
	}
}

function showDivNext() {
	if(currentPic < NUM_PICS) {
		//alert(RelGall);
		if (!RelGall) {
			showDiv(currentPic + 1);
		} else {
			showRelDiv(currentPic + 1);
		}				
	}
}

function GallInit() {
	var i;

	for (i = 1; i < 20; i ++) {
		if (document.getElementById(NAV_DIV + i)) {
			document.getElementById(NAV_DIV + i).style.display='block';
		}
	}

	showDiv(1);
}
function RelGallInit() {
	showRelDiv(1);
	document.getElementById(NAV_DIV).style.display='block';
}

function SwapFields(t) {
	var tab = document.getElementById('corptable');
	var rows = tab.getElementsByTagName('tr');

	for (i = 0; i < rows.length; i ++) {
		if (rows[i].getAttribute('name') == 'hiderow') {
			if (t.options[t.selectedIndex].value == 1) {
				rows[i].style.display = '';
			} else {
				rows[i].style.display = 'none';
			}
		}
	}
}

var kumulatsize = 0;
function resize(oper) {
	var elem = document.getElementById("ourStoryContent");
	if (oper == '+' && kumulatsize < 5) kumulatsize = kumulatsize + 1;
	if (oper == '-' && kumulatsize > -5) kumulatsize = kumulatsize - 1;
	elem.className = 'fontSize' + kumulatsize;
}

function vbaneri2(section, htmlstart, htmlend) {
	if (!banners[section]) return false;
	if (showban1==1) {
		document.write(htmlstart);
		vbaneriw(section);
		document.write(htmlend);
	}
}

function rldContentBuletin(t) {	
	if (t.value == 'Вашата е-поща') {
		t.value = '';
	}
	t.style.color = '#000';
}

function rldContentBuletin2(t) {
	if (!t.value) {
		t.value = 'Вашата е-поща';
	}	
	t.style.color = '#A4A4A4';
}

function rate(r, t, i, s, hldrId, type) {
	if (!r) return;			// nepodaden rating
	if (t && !i) return;	// type = 1 (msg) i nqma podadeno msgid
	var form;
	var contid;
	if (t == 1) {	// forum msg
		form = document.forms['voteform_' + i];
		contid = 'ratemsg' + i;
	} else {	// story, wine
		form = document.forms['voteform'];
		if(hldrId) {
			contid = hldrId;
		} else {
			if (t == 2 || t == 3) {
				contid = 'recomend' + i;
			}else {
				contid = 'recomend';
			}
		}
	}
		
	if (jQuery('.foto-path').length > 0) {
		var fotoblog = 1;
	}else {
		var fotoblog = 0;
	}
	
	var http_request = getxmlhttp();
	if (!http_request) { 
		form.submit();
		return true;
	}
	
	if (type) {
		var type = '&type=1';
	}
	
	if (t == 2) {
		http_request.open('GET', '/voteform.php?wineid=' + i + '&vote=u' + type, true);
	} else {	
		if (t == 3) {
			http_request.open('GET', '/voteform.php?restid=' + i + '&vote=u' + type, true);
		} else {
			http_request.open('GET', '/voteform.php?storyid=' + s + '&vote=u', true);
		}
	}
	
	http_request.onreadystatechange = function() { voteformload(http_request, contid); };
	http_request.send(null);
}

jQuery(document).ready(function() {
	// Rest of Year vote form
	var otherrest = jQuery('#otherrest');
	if (otherrest.length) {
		otherrest.click(function () {
			if (!jQuery('input[id=restoranta_other]:checked').length) {
				jQuery('#restoranta_other').attr('checked', 'checked');
			}
		});
	}
	
	var restForm = jQuery('.restForm');
	if (restForm.length) {
		restForm.submit(function() {
			if (jQuery('input[id=restoranta_other]:checked').length && (jQuery('#otherrest').val()).replace(/\s+/, '') == '') {
				alert('Моля, въведете име на предложения от вас ресторант.');
				return false;
			}
		});
	}
	
	// Rest of Year reg form
	var numatt = jQuery('#numattendees');
	if (numatt.length) {
		numatt.change(function() {
			var num = numatt.val();
			var max = jQuery('#maxnumattendees').val();
			if (num > 1)
				jQuery('#numattendeesinfo').show();
			else
				jQuery('#numattendeesinfo').hide();
			
			for (var i = 1; i <= max; i++) {
				if (i <= num) {
					jQuery('#attendee' + i + 'data').show();
				} else {
					jQuery('#attendee' + i + 'data').hide();
				}
			}
		});
	}
	var individual = jQuery('#isindividual');
	if (individual.length) {
		idnRegForm();
		individual.change(idnRegForm);
	}
});

function idnRegForm(){
	var tempIndividual = jQuery('#isindividual');
	if (tempIndividual.val() == 1) {
		jQuery('.indv0').hide('slow');
		jQuery('#idnLabel').html('ЕГН *');
		jQuery('#receiverLabel').html('Получател (трите имена)*');
	} else {
		jQuery('.indv0').show('slow');
		jQuery('#idnLabel').html('Идентификационен номер *');
		jQuery('#receiverLabel').html('Получател *');
	}	
}
