function createPublicMarker(lat, lng, htmldata)
{
	var point = new GLatLng(lat, lng);
  				  				
	var marker = new GMarker(point);
	
	GEvent.addListener( marker
				  , "click"
				  , function() 
  				    {
    					marker.openInfoWindowHtml(unescape(htmldata));
  					}
  				  );
  
	return marker;
  				 	
}

function varmistapoisto(newLocation) 
{ 
	if(confirm("Haluatko varmasti poistaa valitun kohteen?"))
	{ 
		window.location.href=newLocation;
	}
	else
	{
		//do nothing
	}
	
}


function palautakuva(valittukuva,valittuinfo,parentElement,parentInfo, imgpath, imgid) 
{ 
	var opnrTest = (window.opener)? true : false;
  	if (opnrTest) 
	{
		window.opener.document.getElementById(parentInfo).value=valittuinfo;
		window.opener.document.getElementById(parentElement).value=valittukuva;
		window.opener.document.getElementById(imgid).src=imgpath;
		
	}		
	window.close();
}

function palautadoc(valittuid,valittuinfo,parentElement,parentInfo) 
{ 
	var opnrTest = (window.opener)? true : false;
  	if (opnrTest) 
	{
		window.opener.document.getElementById(parentInfo).value=valittuinfo;
		window.opener.document.getElementById(parentElement).value=valittuid;
	}		
	window.close();
}

function palautadoclink( docPath, docName ,parentElement )
{
    var opnrTest = (window.opener)? true : false;
  	if (opnrTest) 
	{
		var origvalue = window.opener.document.getElementById(parentElement).value;
		var newvalue = "";
		newvalue = origvalue + "[LINK][URL]" + docPath + "[/URL]" + docName + "[/LINK]";
		window.opener.document.getElementById(parentElement).value=newvalue;
		
	}		
	window.close();   
}

function lisaakuvatekstiin(valittukuva,valittuinfo,parentElement, imgt) 
{ 
	var opnrTest = (window.opener)? true : false;
  	if (opnrTest) 
	{
		var origvalue = window.opener.document.getElementById(parentElement).value;
		var newvalue = "";
		if( !imgt )
			newvalue = origvalue + "[IMG]" + valittuinfo + "[/IMG]";
		else
			newvalue = origvalue + "[IMGT]" + valittuinfo + "[/IMGT]";
		
		window.opener.document.getElementById(parentElement).value=newvalue;
	}		
	window.close();
}

function lisaaEfekti( formName, elementName, addstr )
{
	var elementTest = document.forms[formName].elements[elementName] ? true : false;
	if( elementTest )
	{		
		var newvalue = document.forms[formName].elements[elementName].value + addstr;
		document.forms[formName].elements[elementName].value = newvalue;
	}	
}

function tyhjennaPvm(formName, elementName) 
{ 
	var elementTest = document.forms[formName].elements[elementName] ? true : false;
	if( elementTest )
		document.forms[formName].elements[elementName].value="";
}

function tyhjennaKuvaId(formName, elementName) 
{ 
	var elementTest = document.forms[formName].elements[elementName] ? true : false;
	if( elementTest )
		document.forms[formName].elements[elementName].value="0";
}


function setParentElementValueToCookie(formName, sourceElement) 
{ 
	var retVal="";
	var opnrTest = (window.opener)? true : false;
  	if (opnrTest) 
	{
		//retVal = window.opener.document.getElementById(sourceElement).value;
		retVal = window.opener.document.forms[formName].elements[sourceElement].value;
		retVal = retVal.replace(/\r\n\r\n|\n\n|\r\r/g, '<P>');
		retVal = retVal.replace(/\r\n|\n|\r/g, ' ');
		document.cookie = sourceElement + "=" + retVal;
		
	}		
}

function ShowPreview()
{
 	var hWndPreviewWindow =
	window.open("","Preview","width=400,height=250,scrollbars=yes,resizable=yes,status=0");
    hWndPreviewWindow.document.open();
	hWndPreviewWindow.document.writeln('<HTML><HEAD><TITLE>Ylläpito - tekstin esikatselu</TITLE></HEAD>');
    hWndPreviewWindow.document.writeln('<BODY leftmargin="30" topmargin="20" marginwidth="0" marginheight="0" link="666666" vlink="666666">');
    hWndPreviewWindow.document.writeln('<A HREF="javascript:window.close()">Close Preview</A><BR>');
	
    /*
    var otsikko = window.opener.document.forms[formName].elements[otsikko].value;
	var ingressi = window.opener.document.forms[formName].elements[ingressi].value;
	var uutinen = window.opener.document.forms[formName].elements[uutinen].value;
	*/
	
	hWndPreviewWindow.document.writeln('<?php echo ' + otsikko + ';?>');
    hWndPreviewWindow.document.writeln('</BODY></HTML>');
    hWndPreviewWindow.document.close();
}

function previewArticle() { //artikkelin esikatselu etusivulleliitettynä
    var originalaction = document.getElementById('mainform').action;
    document.getElementById('mainform').action = "../index.php?pid=70&aid=preview";
    document.getElementById('mainform').target = "_blank";
    document.getElementById('mainform').submit();
    // palautetaan alkuperäinen takaisin
    document.getElementById('mainform').action = originalaction;
    document.getElementById('mainform').target = "";
}

function menupreview() { //linkin esikatselua varten
}
    

/*
createlink
{
	myString = new String("Go to DevGuru today!")
	rExp = /devguru/gi;
	newString = new String ("http://www.devguru.com")
	results = myString.replace(rExp, newString.link("http://www.devguru.com"))
	document.write(results)
}
*/


function poistakuva(index) {
    var kuva = "elem_kuva"+index;
    var id = "imageid"+index;
    document.getElementById(kuva).src="";
    document.getElementById(id).value="";
}

