// 2006.12.06 Ilmars M.
// Atrod HTML tagu kas seko nākamais
function getPreviosTag(Me){
	var oNode = false;
	oNode = Me.previousSibling;
	while(1){
		if(oNode == false) break;
		if(oNode.nodeType == 1) break;
		oNode = oNode.previousSibling;
	}
	return oNode;
}

// 2006.12.06 Ilmars M.
// Atrod iepriekšējo HTML tagu
function getNextTag(Me){
	var oNode = false;
	oNode = Me.nextSibling;
	while(1){
		if(oNode == false) break;
		if(oNode.nodeType == 1) break;
		oNode = oNode.nextSibling;
	}
	return oNode;
}

// 2006.12.06 Ilmars M.
// Bīda HTML elementus uz augšu vai leju (maina tos vietām)
function moveElement(elementID, up){
	var oMyOrder = document.getElementById('element_sort_order_'+elementID);
	var oMyRow = document.getElementById('element_entry_'+elementID);
	var totalCount = document.getElementById('element_total_count').value;
	if((up == 1)&&((oMyOrder.value*1) > 1)){
		var oMyBrother = getPreviosTag(oMyRow);
		var brotherID = oMyBrother.getAttribute('element_id');
		oMyRow.parentNode.insertBefore(oMyRow, oMyBrother);
		oMyOrder.value = (oMyOrder.value*1) - 1;
		document.getElementById('element_sort_order_'+brotherID).value = (document.getElementById('element_sort_order_'+brotherID).value*1) + 1;
		document.getElementById('element_changed_'+elementID).value = 1;
		document.getElementById('element_changed_'+brotherID).value = 1;
	}
	if((up != 1) && ((oMyOrder.value*1) < (totalCount*1))){
		var oMyBrother = getNextTag(oMyRow);
		var brotherID = oMyBrother.getAttribute('element_id');
		oMyRow.parentNode.insertBefore(oMyBrother, oMyRow);
		oMyOrder.value = (oMyOrder.value*1) + 1;
		document.getElementById('element_sort_order_'+brotherID).value = (document.getElementById('element_sort_order_'+brotherID).value*1) - 1;
		document.getElementById('element_changed_'+elementID).value = 1;
		document.getElementById('element_changed_'+brotherID).value = 1;
	}
}
function needSave(elementID){
	document.getElementById('element_changed_'+elementID).value = 1;
}

function openImgPopUp(imgUrl, imgName){
	MyWindow = window.open(imgUrl,"Picture","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=400,height=400");
	MyWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	MyWindow.document.write('<html>');
	MyWindow.document.write('<head>');
	MyWindow.document.write('	<script type="text/javascript">');
	MyWindow.document.write('		function resizePopUp() {');
	MyWindow.document.write('			iWidth = document.documentElement.clientWidth;');
	MyWindow.document.write('			iHeight = window.innerHeight;');
	MyWindow.document.write('			if(iHeight == undefined) { iHeight = document.documentElement.clientHeight; }');
	MyWindow.document.write('			iWidth = document.images[0].width - iWidth;');
	MyWindow.document.write('			iHeight = document.images[0].height - iHeight;');
	MyWindow.document.write('			window.resizeBy(iWidth, iHeight);');
	MyWindow.document.write('		};');
	MyWindow.document.write('	</script>');
	MyWindow.document.write('	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
	MyWindow.document.write('	<title>'+imgName+'</title>');
	MyWindow.document.write('</head>');
	MyWindow.document.write('<body style="margin:0; padding:0;" onLoad="resizePopUp();">');
	MyWindow.document.write('	<img src="'+imgUrl+'" alt="'+imgName+'" />');
	MyWindow.document.write('</body>');
	MyWindow.document.write('</html>');
	MyWindow.document.close();
	return(false);
}

function moveDisplayThumb(sectionId, direction){
	var thumbs_total = parseInt(document.getElementById('thumb_section_total_count_'+sectionId).value);
	var thumbs_start = parseInt(document.getElementById('thumb_section_first_'+sectionId).value);
	if(direction == 1){ // forward
		if((thumbs_start+5) < thumbs_total){
			var old_th = document.getElementById('thumb_'+sectionId+'_'+thumbs_start);
			old_th.style.display = 'none';
			var new_th = document.getElementById('thumb_'+sectionId+'_'+(thumbs_start+5));
			new_th.style.display = 'block';
			thumbs_start++;
		}
	}
	else { // backward
		if(thumbs_start > 0){
			var old_th = document.getElementById('thumb_'+sectionId+'_'+(thumbs_start+4));
			old_th.style.display = 'none';
			var new_th = document.getElementById('thumb_'+sectionId+'_'+(thumbs_start-1));
			new_th.style.display = 'block';
			thumbs_start--;
		}
	}
	document.getElementById('thumb_section_total_count_'+sectionId).value = thumbs_total;
	document.getElementById('thumb_section_first_'+sectionId).value = thumbs_start;
}

// Prieksh klientu skata, ja pievienots MP3 fails
function writePlayer(parent_id, mp3path){
	//alert('writePlayer('+parent_id+', '+mp3path+')');
	// esosho flash mp3 pleijeri novācu un tā vietā lieku gifu
	var snd_player = document.getElementById('snd_player');
	if(snd_player != null){
		var snd_parent = snd_player.parentNode;
		var old_parent_id = snd_parent.getAttribute('id');
		var old_mp3path = snd_parent.getAttribute('mp3path');
		while(snd_parent.childNodes.length > 0){
			snd_parent.removeChild(snd_parent.childNodes[0]);
		}
		var oA = document.createElement('a');
		oA.setAttribute('href', 'javascript:writePlayer(\''+old_parent_id+'\' ,\''+old_mp3path+'\');');
		oImg = document.createElement('img');
		oImg.setAttribute('src', '/images/icons/player.gif');
		oA.appendChild(oImg);
		snd_parent.appendChild(oA);
	}

  var snd_parent = document.getElementById(parent_id);
	while(snd_parent.childNodes.length > 0){
		snd_parent.removeChild(snd_parent.childNodes[0]);
	}
	var sFlash = '';
	sFlash += '<object id="snd_player" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" height="15" width="70">';
	sFlash += '	<param value="sameDomain" name="allowScriptAccess" />';
	sFlash += '	<param value="/images/swf/snd_player.swf?pth='+mp3path+'" name="movie" />';
	sFlash += '	<param value="#ffffff" name="bgcolor" />';
	sFlash += '	<embed ';
	sFlash += '		pluginspage="http://www.macromedia.com/go/getflashplayer" ';
	sFlash += '		type="application/x-shockwave-flash" ';
	sFlash += '		allowscriptaccess="sameDomain" ';
	sFlash += '		name="snd_player" ';
	sFlash += '		bgcolor="#ffffff" ';
	sFlash += '		quality="high" ';
	sFlash += '		src="/images/swf/snd_player.swf?pth='+mp3path+'" ';
	sFlash += '		align="middle" ';
	sFlash += '		height="15" ';
	sFlash += '		width="70" />';
	sFlash += '</object>';

	snd_parent.innerHTML = sFlash;
	/*
	var oObject = document.createElement('object');
	oObject.setAttribute('classid', 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');
	oObject.setAttribute('codebase', 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0');
  oObject.setAttribute('width', '70');
  oObject.setAttribute('height', '15');
  oObject.setAttribute('id', 'snd_player');
  var oParam = document.createElement('param');
  oParam.setAttribute('value', 'sameDomain');
  oParam.setAttribute('name', 'allowScriptAccess');
  oObject.appendChild(oParam);
  oParam = document.createElement('param');
  oParam.setAttribute('value', '/images/swf/snd_player.swf?pth='+mp3path);
  oParam.setAttribute('name', 'movie');
  oObject.appendChild(oParam);
  oParam = document.createElement('param');
  oParam.setAttribute('value', '#ffffff');
  oParam.setAttribute('name', 'bgcolor');
  oObject.appendChild(oParam);
  var oEmbed = document.createElement('embed');
  oEmbed.setAttribute('src', '/images/swf/snd_player.swf?pth='+mp3path);
  oEmbed.setAttribute('quality', 'high');
  oEmbed.setAttribute('bgcolor', '#ffffff');
  oEmbed.setAttribute('width', '70');
  oEmbed.setAttribute('height', '15');
  oEmbed.setAttribute('name', 'snd_player');
  oEmbed.setAttribute('align', 'middle');
  oEmbed.setAttribute('allowScriptAccess', 'sameDomain');
  oEmbed.setAttribute('type', 'application/x-shockwave-flash');
  oEmbed.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
	oObject.appendChild(oEmbed);
	snd_parent.appendChild(oObject);
	*/
}

function addNote(noteParam){
	window.open('/note_add.php?'+noteParam, 'Add Note', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=300,height=230');
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


// Ilmārs Mārciņš 2007.02.02
// Pārslēdzas starp eventiem (firstpage wedding tools)
function switchEventTools(eventId){
	var oA;
	var linkUrl;
	var newLinkUrl;
	for(var i=0; i < 6; i++){
		if(!document.getElementById('event_tool_link_'+(i))) continue;
		oA = document.getElementById('event_tool_link_'+(i));
		linkUrl = oA.getAttribute('href');
		newLinkUrl = linkUrl.substring(0, linkUrl.lastIndexOf('=')) + '=' + eventId;
		oA.setAttribute('href', newLinkUrl);
	}
	// uzsetoju cookie, ar usera izvēlēto eventu
	createCookie('tools_event', eventId, 0);
}

function textarea_limiter(text_area, maxlimit) {
	var myarea = document.getElementById(text_area);
	if(myarea.value.length > maxlimit){
		myarea.value = myarea.value.substring(0, maxlimit);
	}
	var myupdate = document.getElementById(text_area+'_counter');
	myupdate.firstChild.nodeValue = myarea.value.length;
}





