/**
 * cross DOM getElementById()
 */ 
function crossDomId(x) {
	if(document.all && !document.getElementById){
		return document.all.x;
	}
	else{
		return document.getElementById(x);
	}
}

function getElementsByClassName(clsName) { 
	var arr = new Array(); 
	var elems = document.getElementsByTagName("*");
	for ( var cls, i = 0; ( elem = elems[i] ); i++ ){
		if ( elem.className == clsName ){
			arr[arr.length] = elem;
		}
	}
	return arr;
}

function hideElement(element){

  element.style.display = 'none';
}

function showElement(element){

  element.style.display = 'block';
}

/**
 * resize thumbnails of Fotogalerie
 */
function resizeFgThumbs(){

  var aThumbs = getElementsByClassName('fgimg');
  var iCf = 1; // verhältnis von Höhe zu Breite
  var counter = 1;
  var faktor = 1;

  if(aThumbs.length > 0){
	
	for(i=0; i < aThumbs.length; i++){

		if(aThumbs[i].height > aThumbs[i].width){
		  
		  iCf = aThumbs[i].height / aThumbs[i].width;
		  aThumbs[i].height = 100;
		  aThumbs[i].width = aThumbs[i].height / iCf;
		}
		else if(aThumbs[i].width > aThumbs[i].height){

		  iCf = aThumbs[i].width / aThumbs[i].height;
		  aThumbs[i].width = 100;
		  aThumbs[i].height = aThumbs[i].width / iCf;
		  
		  var mt = (100 - aThumbs[i].height)/2;

		  aThumbs[i].style.marginTop = mt+'px';
		  
		}
		else if(aThumbs[i].height == aThumbs[i].width){

		  aThumbs[i].height = 100;
		  aThumbs[i].width = 100;
		}
		
		if(counter/(5*faktor) == 1){

			aThumbs[i].parentNode.style.marginRight = '0px';
			faktor ++;
		}
		
		counter++;
	}
  }
}

/**
  * get sms output
  */
$(document).ready(function(){
  
  $.ajax({
    type:"GET",
    url:"fileadmin/template/default/php/sms_steuerung.php",
    success:function(msg){
      
      $("#sms").html(msg);
    }
   });
});


$(document).ready(function(){
  $("div#smsform form").submit(function(){
    $.post("/fileadmin/template/default/php/send_sms.php",
	  { name: $("input#name").val(), telefon: $("input#telefon").val() },
	  function(data) {	  
		if (data.substring(0,2) == "OK") {
		  $("div#smsform").empty();
		  $("div#smsform").append("<p id=\"smsok\">"+data.substring(2)+"</p>");
		} else if (data.substring(0,2) == "ER") {
		  $("div#smsform").empty();
                  $("div#smsform").append("<p id=\"smserror\">"+data.substring(2)+"</p>");		  
		} else {
		  $("div#smsform p:first").remove();		
		  $("div#smsform form").prepend("<p id=\"smserror\">"+data+"</p>");
		}
	  },
      "html");
	return false;
  });
});

