// BOTIKAJAX v 1.0

// Formularioa kargatzeko
function loadForm(zr,gaia,fovi,name,email,fotit,fodes,fitit,fides,noiz,err,file,berri,zrnom,zrdes) {
  var xmlHttp;
  try { // Gehiengoarentzat
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) { // Internet Explorer-entzat
    try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
      try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e) { alert("Your browser does not support AJAX!"); return false; }
    }
  }
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById('idForm').innerHTML=parseScript(xmlHttp.responseText);
			// Akordeoia martxan jartzeko
			$(function(){
				$(".closed")
					.next()
						.hide();
				$(".accTitle").click(function () {
					var $this = $(this);
					if($this.is('.closed')) {
						$(".open").next()
								.slideUp(200);
						$(this).next()
								.slideDown(200);
						$(".accTitle")
							.removeClass('open')
						$(".accTitle")
							.addClass('closed')
						$this
							.removeClass('closed')
						$this
							.addClass('open')
					}
					else if($this.is('.open')) {
						$this.next()
							.slideUp(200);
							$this
								.removeClass('open')
							$this
								.addClass('closed')
					}
				});
				$(".closed").hover(function(){
					$(this).addClass("hover");
					}, function(){
					$(this).removeClass("hover");
				});
			});
			// Input-etan klikatzean testua desagertzeko
			$("form").find("input, textarea").toggleVal();
			// H2 "z" sifr-ak aktibatzeko
			sIFR.replace(chaparral, {
				selector: 'h2.z span.sifr',
				css:[
					'.sIFR-root { color: #409398; font-size: 30px; }',
					'a { text-decoration: none; }',
					'a:link { color: #409398; }',
					'a:hover { color: #6AC7CC; }'
				],
				thickness: -120,
				wmode: 'transparent',
				fixHover: true,
				useStyleCheck: true
			});
			//uploadify karpeta
			var uploadfolder='zr'+zr;
			//uploadify Photo
			$('#photoUpload').fileUpload ({
			'sizeLimit' : 6000000,
			'uploader'  : 'swf/uploadify/uploader.swf',
			'script'    : 'includes/plugins/upload.php',
			'cancelImg' : 'img/plugins/uploadify/cancel.png',
			'buttonText': jsattachsth,
			'onSelect'	: function (event,queueID,fileObj) { var fileMota=fileObj.type.toLowerCase(); if(fileMota!=".jpg" & fileMota!=".png") {  document.getElementById('photoOk').innerHTML='<span class="error">'+jswrongformat+'</span>'; return false; } else { document.getElementById('photoOk').innerHTML=''; document.getElementById('photoIzen').value=fileObj.name; $('#photoUpload').fileUploadStart(queueID); } },
			'onComplete': function (event,queueID,fileObj,response,data) { document.getElementById('photoOk').innerHTML='<span class="fileobj">'+fileObj.name+'</span>'+' &nbsp;('+Math.round((fileObj.size/1024*100))/100+' Kb)<br />'+jsdontforget+'.'; },
			'auto'      : false,
			'folder'    : '/files/'+uploadfolder+'/img'
			});
			//uploadify Archive
			$('#archiveUpload').fileUpload ({
			'sizeLimit' : 6000000,
			'uploader'  : 'swf/uploadify/uploader.swf',
			'script'    : 'includes/plugins/upload.php',
			'cancelImg' : 'img/plugins/uploadify/cancel.png',
			'buttonText': jsattachsth,
			'onSelect'	: function (event,queueID,fileObj) { var fileMota=fileObj.type.toLowerCase(); if(fileMota!=".doc" & fileMota!=".ppt" & fileMota!=".pdf" & fileMota!=".mp3" & fileMota!=".mov" & fileMota!=".mpg" & fileMota!=".avi") { document.getElementById('fileOk').innerHTML='<span class="error">'+jswrongformat+'</span>'; return false; } else {document.getElementById('fileOk').innerHTML='';  document.getElementById('archiveIzen').value=fileObj.name; $('#archiveUpload').fileUploadStart(queueID); } },
			'onComplete': function (event,queueID,fileObj,response,data) { document.getElementById('fileOk').innerHTML='<span class="fileobj">'+fileObj.name+'</span>'+' &nbsp;('+Math.round((fileObj.size/1024*100))/100+' Kb)<br />'+jsdontforget+'.'; },
			'auto'      : false,
			'folder'    : '/files/'+uploadfolder
			});
		}
	}
	xmlHttp.open("GET",jsroot+"botika/forms/memoryForm.php?zr="+zr+"&gaia="+gaia+"&fovi="+fovi+"&name="+name+"&email="+email+"&fotit="+fotit+"&fodes="+fodes+"&fitit="+fitit+"&fides="+fides+"&noiz="+noiz+"&file="+file+"&err="+err+"&berri="+berri+"&zrnom="+zrnom+"&zrdes="+zrdes,true);
	xmlHttp.send(null);
}

// Formularioa bidaltzeko
function sendForm(zr,fovi,berri) {

	var name = document.getElementById('name').value;
	if(name==jsname) { name=''; }
	var email = document.getElementById('email').value;
	if(email==jsemail) { email=''; }
	var fotit = document.getElementById('photoName').value;
	if(fotit==jsfotit) { fotit=''; }
	var fodes = document.getElementById('photoDescription').value;
	if(fodes==jsfodes) { fodes=''; }
	var fitit = document.getElementById('archiveName').value;
	if(fitit==jsfitit) { fitit=''; }
	var fides = document.getElementById('archiveDescription').value;
	if(fides==jsfides) { fides=''; }
	var onartua = document.getElementById('acceptTerms').checked;
	if(onartua) { onartua=1; } else { onartua=0; }
	
	if(berri==1) {
		var zrnom = document.getElementById('newZarauztarName').value;
		if(zrnom==jszrnom) { zrnom=''; }
		var zrdes = document.getElementById('newZarauztarDescription').value;
		if(zrdes==jszrdes) { zrdes=''; }
	} else {
		zrnom=1;
		zrdes=1;
	}
		
	if(document.getElementById('photoIzen').value!='') { fovi=1; }
	if(document.getElementById('archiveIzen').value!='') { fovi=2; }
	
	if(fovi==1) {
		file=document.getElementById('photoIzen').value;
		if(zr!=3) {
			gaia=document.getElementById('photoTheme').value;
		} else {
			if(berri==1) {
				gaia=0;
			} else {
				gaia=document.getElementById('zarauztarName').value;
			}
		}
		var noizarray=new Array();
		noiz=document.getElementById('photoDate').value.toString();
		for(i=1;i<=15;i++) {
			noizarray[i]=0;
			noiz=noiz+','+noizarray[i];
		}
	} else if(fovi==2) {
		file=document.getElementById('archiveIzen').value;
		if(zr!=3) {
			gaia=document.getElementById('archiveTheme').value;
		} else {
			if(berri==1) {
				gaia=0;
			} else {
				gaia=document.getElementById('zarauztarName').value;
			}
		}
		var noizarray=new Array();
		noiz='0';
		for(i=1;i<=15;i++) {
			noizarray[i]=document.getElementById('dat'+i).checked.value;
			if(document.getElementById('dat'+i).checked) { noizarray[i]=1; } else { noizarray[i]=0; }
			noiz=noiz+','+noizarray[i];
		}
	} else {
		file=0;
		gaia=1;
		noiz='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
	}

  var xmlHttp;
  try { // Gehiengoarentzat
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) { // Internet Explorer-entzat
    try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
      try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e) { alert("Your browser does not support AJAX!"); return false; }
    }
  }
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			//alert(noiz);
			document.getElementById('idForm').innerHTML=parseScript(xmlHttp.responseText);
			$(function(){
				$(".closed")
					.next()
						.hide();
				$(".accTitle").click(function () {
					var $this = $(this);
					if($this.is('.closed')) {
						$(".open").next()
								.slideUp(200);
						$(this).next()
								.slideDown(200);
						$(".accTitle")
							.removeClass('open')
						$(".accTitle")
							.addClass('closed')
						$this
							.removeClass('closed')
						$this
							.addClass('open')
					}
					else if($this.is('.open')) {
						$this.next()
							.slideUp(200);
							$this
								.removeClass('open')
							$this
								.addClass('closed')
					}
				});
				$(".closed").hover(function(){
					$(this).addClass("hover");
					}, function(){
					$(this).removeClass("hover");
				});
			});
		}
	}
	xmlHttp.open("GET",jsroot+"botika/forms/memoryFormSend.php?zr="+zr+"&gaia="+gaia+"&fovi="+fovi+"&name="+name+"&email="+email+"&fotit="+fotit+"&fodes="+fodes+"&fitit="+fitit+"&fides="+fides+"&file="+file+"&noiz="+noiz+"&onartua="+onartua+"&berri="+berri+"&zrnom="+zrnom+"&zrdes="+zrdes,true);
	xmlHttp.send(null);
}

