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

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

function openw(url, title, options) {
	var newwin = window.open(url, title, options);
	newwin.focus();
}



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') == 'hidesmall') {
			if (t.options[t.selectedIndex].value == 1) {
				rows[i].style.display = '';
			} else {
				rows[i].style.display = 'none';
			}
		}
		if (rows[i].getAttribute('name') == 'hidebig') {
			if (t.options[t.selectedIndex].value == 2) {
				rows[i].style.display = '';
			} else {
				rows[i].style.display = 'none';
			}
		}
		if (rows[i].getAttribute('name') == 'hideburzo') {
			if (t.options[t.selectedIndex].value == 3) {
				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);
		vbaneri(section);
		document.write(htmlend);
	}
}

function rldContentBuletin(t) {	
	if (t.value == 'Вашият email адрес') {
		t.value = '';
	}
	t.style.color = '#003663';
}

function rldContentBuletin2(t) {
	if (!t.value) {
		t.value = 'Вашият email адрес';
	}	
	t.style.color = '#4C7291';
}

function vbaneritxtindex(section,prefixhtml,suffixhtml,prefixelem,suffixelem) {
	var ret = '';
	for(i in section) {
		if (showban1==1 && banners[section[i]]) {
			ret += prefixelem + singleBanner(banners[section[i]][0], banners[section[i]][8], banners[section[i]][2], banners[section[i]][3], banners[section[i]][1], banners[section[i]][4], banners[section[i]][5], banners[section[i]][6], banners[section[i]][7], banners[section[i]][9], banners[section[i]][10]) + suffixelem;
		}
		
	}
	
	if(ret) {
		document.write(prefixhtml);
		document.write(ret);
		document.write(suffixhtml);
	}
}

function limitText(limitField, limitCount, limitNum) {
		if (limitField.value.length > limitNum) {
			limitField.value = limitField.value.substring(0, limitNum);
		} else {
			limitCount.value = limitNum - limitField.value.length;
		}
}

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

			for (i = 0; i < rows.length; i ++) {
				if (rows[i].getAttribute('name') == 'proizvoditelid') {
					if (t.options[t.selectedIndex].value == 2079) {
						rows[i].style.display = '';
					} else {
						rows[i].style.display = 'none';
					}
				}
				if (rows[i].getAttribute('name') == 'tdrebnoid') {
					if (t.options[t.selectedIndex].value == 2080) {
						rows[i].style.display = '';
					} else {
						rows[i].style.display = 'none';
					}
				}
				if (rows[i].getAttribute('name') == 'tedroid') {
					if (t.options[t.selectedIndex].value == 2081) {
						rows[i].style.display = '';
					} else {
						rows[i].style.display = 'none';
					}
				}
				if (rows[i].getAttribute('name') == 'oborudvaneid') {
					if (t.options[t.selectedIndex].value == 2082) {
						rows[i].style.display = '';
					} else {
						rows[i].style.display = 'none';
					}
				}
				if (rows[i].getAttribute('name') == 'konsultid') {
					if (t.options[t.selectedIndex].value == 2083) {
						rows[i].style.display = '';
					} else {
						rows[i].style.display = 'none';
					}
				}
			}
		}
function replyTo(postNum, postAuthor) {
	var curVal = jQuery('#msg').val();
	var repStr;
	if(curVal.length > 0) {
		repStr = curVal + '\nДо коментар [#' + postNum + '] от "' + postAuthor + '":\n\n';
	} else {
		repStr = 'До коментар [#' + postNum + '] от "' + postAuthor + '":\n\n';
	}
	jQuery('#msg').val(repStr).focus();
	jQuery('html,body').animate({scrollTop: jQuery('#addcomment').offset().top},500);
	return false;
}