function init(){
	document.siteSearchForm.searchString.value = searchValue;
	document.siteLoginForm.username.value = usernameValue;
	document.siteLoginForm.password.value = passwdValue;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){ x.src=x.oSrc; x.oSrc=x.src; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
   
   document.oldImg = new Object;
   document.oldImg.src = a[2];
   document.oldImg.name = a[0];
}

function openTellFriend(pageUri){
	window.open('/kerro_kaverille.php?pageUri='+pageUri,'tellFriendWin','scrollbars=no,width=430,height=500,location=no,resizable=no');
}

function openGallupComment(gallupId){
    window.open('/data/comment.php?gallupid='+gallupId,'commentWin','scrollbars=no,width=400,height=300,location=no,resizable=no');   
}

function openTerms(){
	window.open('/data/terms.php','terms','scrollbars=no,width=400,height=500,location=no,resizable=no');
}

function removeProfile(){
	if(confirm("Haluatko varmasti poistaa profiilin?\nKaikki profiilin tiedot poistetaan.")){
		document.removeForm.submit();
	}
	else{

	}
		
}

function removeTestimony(){
	if(confirm("Haluatko varmasti poistaa todistuksen?")){
		document.testimonyForm.action.value = "Poista todistus";
		//alert(document.testimonyForm.action.value);
		document.testimonyForm.submit();
	}
	else{
		//alert("Ei poistettu");
	}
}

function saveTestimony(){
	document.testimonyForm.action.value = "Tallenna todistus";
	document.testimonyForm.submit();
}

function removeBlogWriting(){
	if(confirm("Haluatko varmasti poistaa kirjoituksen?")){
		document.blogWritingForm.action.value = "remove";
		//alert(document.testimonyForm.action.value);
		document.blogWritingForm.submit();
	}
	else{
		//alert("Ei poistettu");
	}
}

function saveBlogWriting(){
	document.blogWritingForm.action.value = "save";
	document.blogWritingForm.submit();
}

function showFolder(curFolder, maxFolders){
	//document.galleryFolders.folder_+curFolder.style= "display:block;";
	for(var i=0;i<maxFolders.length;i++){
		if(maxFolders[i] == curFolder) document.getElementById('folder_'+maxFolders[i]).style.display = "block";
		else document.getElementById('folder_'+maxFolders[i]).style.display = "none";
	}
	//alert(document.getElementById('folder_'+0).style.value);
	//alert(curFolder);
}

function addFolder(){
	if(document.getElementById('folderName').value == "") alert("Kansion nimi ei voi olla tyhjä");
	else{
		document.galleryFolderForm.action.value = "new";
		document.galleryFolderForm.submit();
	}
}

function publishFolder(folder){
//	if(document.getElementById('folderName').value == "") alert("Kansion nimi ei voi olla tyhjä");
//	else{
		document.galleryFolderForm.action.value = "publish";
		document.galleryFolderForm.folder.value = folder;
		document.galleryFolderForm.submit();
//	}
}

function removeFolder(folder){
	if(confirm("Haluatko varmasti poistaa kansion?\nMyös kansioissa olevat kuvat poistetaan.")){
		document.galleryFolderForm.action.value = "remove";
		document.galleryFolderForm.folder.value = folder;
		//alert(document.testimonyForm.action.value);
		document.galleryFolderForm.submit();
	}
	else{
		//alert("Ei poistettu");
	}
}

function renameFolder(folder){
	window.open('/data/actions/renameFolder.php?id='+folder,'renamefolder','width=200, height=100, scrollbars=no, resizable=no, location=no');
	
}

function saveFolder(id, name){
	//d_op = window.opener.document.galleryFolderForm;

	//alert(id+" "+name);
	if(name != ""){
		opener.document.galleryFolderForm.action.value = "rename";
		opener.document.galleryFolderForm.folder.value = id;
		opener.document.galleryFolderForm.folder_name.value = name;
		opener.document.galleryFolderForm.submit();
		this.close();
	}
	else alert("Kansiolle pitää antaa nimi.");
	//	alert(window.opener.document.galleryFolderForm.action.value);
	
}

function removeImage(image){
	if(confirm("Haluatko varmasti poistaa kuvan?")){
		document.galleryImageForm.action.value = "remove";
		document.galleryImageForm.image.value = image;
		//alert(document.testimonyForm.action.value);
		document.galleryImageForm.submit();
	}
	else{
		//alert("Ei poistettu");
	}
}

function modifyImage(image, gallery, profile){
	window.open('/data/actions/modifyImage.php?id='+image+'&gallery='+gallery+'&profile='+profile,'modifyimage','width=200, height=200, scrollbars=no, resizable=no, location=no');
	
}

function initForm(){
	if(opener.document.galleryImageForm.profileId.value > 0){}
	else window.close();
	
}

function saveImage(img_id, title, alt, folder){
	opener.document.galleryImageForm.action.value = "modifypicture";
	opener.document.galleryImageForm.image.value = img_id;
	opener.document.galleryImageForm.title.value = title;
	opener.document.galleryImageForm.alt.value = alt;
	opener.document.galleryImageForm.folderId.value = folder;
	opener.document.galleryImageForm.submit();
	window.close();
	
}

function removeComments(image, gallery, profile){
	window.open('/data/actions/removeComments.php?id='+image+'&gallery='+gallery+'&profile='+profile,'removecomments','width=640, height=200, scrollbars=yes, resizable=no, location=no');
	
}

function removeComment(img_id, comment_id){
	opener.document.galleryImageForm.action.value = "removeComment";
	opener.document.galleryImageForm.image.value = img_id;
	opener.document.galleryImageForm.commentId.value = comment_id;
	opener.document.galleryImageForm.submit();
	window.close();
	
}

function showImg(img,alt,title){
	document.getElementById('imageArea').style.left = (document.body.clientWidth / 2) - 400;
	document.getElementById('imageArea').style.display = 'block';
	document.getElementById('imgSrc').src = "http://www.netmission.fi/filebank/gallery/"+img+".jpg";
	document.getElementById('imgSrc').alt = alt;
	document.getElementById('titleSrc').innerHTML = title;
	//return ((document.body.clientWidth / 2) - 400);
	//alert(document.body.clientWidth);
}

function hideMe(){
	document.getElementById('imageArea').style.display = 'none';
}

function showCommentForm(){
	document.getElementById('comment').style.display = 'block';
}

function addComment(){
	if(document.getElementById('commentArea').value == ""){}
	else document.blogWritingCommentForm.submit();
	
}

function removeMsg(msg_row_id, msg_id){
	document.msg_form.action.value = "remove";
	document.msg_form.msg_row_id.value = msg_row_id;
	document.msg_form.msg_id.value = msg_id;
	document.msg_form.submit();
	
}

function validate(object, type){
	var value = object.value;

	if(type == 'd'){
		if(object.value >31) object.value = 31;
	}
	else if(type == 'm'){
		if(object.value >12) object.value = 12;
	}
	else if(type == 'y'){//alert(value.length);
		/*if(value.length < 3) object.value = "20"+object.value;
		else if(value.length < 4) object.value = "2"+object.value;
		if(object.value >2100) object.value = 2100;*/
	}
	else if(type == 'h'){
		if(object.value >23) object.value = 23;
	}
	else if(type == 'min'){
		if(object.value >59) object.value = 59;
	}
	else{
	}
	
}