// JavaScript Document

function tider(vad) {
	
	//alert(vad);
	
	if (vad) {
		
		document.getElementById("tider_box").style.display = 'table-row';
		
	} else {
		
		document.getElementById("tider_box").style.display = 'none';
		
	}
	
	//alert(document.getElementById("tider_box").style.display);
}


sure = function(me) {
	//alert(me);

	conf = confirm("Vill du verkligen ta bort " + me + " ?");
	
	//alert(conf);
	
	
	if (conf) {
		return true;
	} else {
		return false;
	}
	

}

function clearSearch(vad) {
	
	if (vad == "Hitta") {
		
		document.getElementById("findField").value = "";
			
	}
	
}

showKom = function(me) {
	//alert("vem e jag? " + me);
	
	for(i=1;i<21;i++) {
	
		h = document.getElementById("kom" + i);
		h.style.display = "none";
		
		
		//c = document.getElementById("c" + i);
		//c.style.display = "block";
			
	}
	
	
	s = document.getElementById("kom" + me);
	s.style.display = "block";
	
	//c = document.getElementById("c" + me);
	//c.style.display = "block";
	
}


function showKomTable(me) {
	
	var IE = /*@cc_on!@*/false;
	
	for(i=1;i<21;i++) {
	
		h = document.getElementById("kom" + i);
		h.style.display = "none";
			
	}
	
	
	s = document.getElementById("kom" + me);
	
	if (IE) {
		s.style.display = "block";
	} else {
		s.style.display = "table-row";
	}
	
}


///////////////////////////////////////////////////////////////////////

var tb=new Array();
var nr = 0;
function flipPic(vart) {
	//alert("ey");
	
	
	if(vart == 'plus'){
		if (nr < (tb.length -1 )) {
			nr++
		} else {
			nr = 0;
		}
	} else if (vart == 'minus') {
		if (nr > 0) {
			nr--
		} else {
			nr = (tb.length -1);
		}
	}
	
	//alert(nr + " " + (tb.length -1));
	ab = document.getElementById('annonsBild');
	
	ab.src = '../../img/thumb/' + tb[nr] + '.jpg';
	
}

////////////////////////////////////////////////////////////////////////

var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            //document.getElementById('myspan').innerHTML = result;
			//alert(result);
			//alert(run);
			
			if (run == "1") {
				if (result == "1") {
					alert("Din epost är redan registrerad.");
					//alert("Din kampanjkod är inte korrekt.");
				}	
			}
			
			if (run == "2") {
				if (result == "1") {
					//alert("Din epost är redan registrerad.");
					alert("Din kampanjkod är inte korrekt.");
				} else {
					document.getElementById('regForm').submit();
					//alert("Din kampanjkod är korrekt.");
					//return true;
				}
			}
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
	  
	  run = "1";
	  
	  if (document.getElementById("epost").value < 2) {
		  
		  alert('Du måste fylla i en epostadress/användarnamn');
		  
	  } else {
		  
      	var poststr = "minEpost=" + escape(encodeURI(document.getElementById("epost").value));
      	makePOSTRequest('include/kollaEpost.php', poststr);
		
	  }
   }

////////////////////////////////////////////////////////////////

var bn = 1;
function bytBild(b1,b2,b3) {
	
	im = document.getElementById('annonsBild');
	
	if (bn == 0) {
		im.src = '../../img/thumb/' + b1 + '.jpg';
	} else if (bn == 1) {
		if (b2 != "tom") {
			im.src = '../../img/thumb/' + b2 + '.jpg';
		} else {
			bn = 0;
		}
	} else if (bn == 2) {
		if (b3 != "tom") {
			im.src = '../../img/thumb/' + b3 + '.jpg';
		} else {
			bn = 0;
			im.src = '../../img/thumb/' + b1 + '.jpg';
		}
	}
	
	if (bn < 2) {
		bn++;
	} else {
		bn = 0;
	}
}

function bytBildL(b1,b2,b3) {
	
	im = document.getElementById('annonsBild');
	
	if (bn == 0) {
		im.src = '../../img/thumb/' + b1 + '.jpg';
	} else if (bn == 1) {
		if (b2 != "tom") {
			im.src = '../../img/thumb/' + b2 + '.jpg';
		} else {
			bn = 0;
		}
	} else if (bn == 2) {
		if (b3 != "tom") {
			im.src = '../../img/thumb/' + b3 + '.jpg';
		} else {
			bn = 0;
			im.src = '../../img/thumb/' + b1 + '.jpg';
		}
	}
	
	if (bn < 2) {
		bn++;
	} else {
		bn = 0;
	}
}

function kollaAntalTecken() {
	
	//alert("hej");
	
	var tt = document.getElementById("ii");	
	
	if (tt.value.length > 180) {
		
		//Kommentera för att avaktivera extra text
		
		document.getElementById("extraText").value = tt.value.substring(180);
		tt.value = tt.value.substring(0, 180);
		document.getElementById("extraText").focus();
		showExtra();
	}
	
	var rek = document.getElementById("rekna");
	
	rek.innerHTML = 180 - tt.value.length;
	
	putInfo('ingressen');
	
}