


function toggleField() {
 if(document.getElementById("sms-more").style.display=="block") { document.getElementById("sms-more").style.display="none"; }
 else { document.getElementById("sms-more").style.display="block"; }
}



function checkSMS() {
 var noerror=true;

	 if(document.getElementById("sms_1").value=="") {
		noerror=false;
		document.getElementById("sms_1_error").innerHTML="Por favor introduzca un SMS."
	 }	
	 else {
		document.getElementById("sms_1_error").innerHTML=""
	 }

	 if(document.getElementById("sms_1_time").value=="") {
		noerror=false;
		document.getElementById("sms_1_time_error").innerHTML="Por favor introduzca un tiempo."
	 }	
	 else {
		document.getElementById("sms_1_time_error").innerHTML=""
	 }


	

	if(document.getElementById("sms-more").style.display=="block") {	//falls weitere sms eingegeben werden
		 if(document.getElementById("sms_2").value=="") {
			noerror=false;
			document.getElementById("sms_2_error").innerHTML="Por favor introduzca un SMS."
		 }	
		 else {
			document.getElementById("sms_2_error").innerHTML=""
		 }

		 if(document.getElementById("sms_2_time").value=="") {
			noerror=false;
			document.getElementById("sms_2_time_error").innerHTML="Por favor introduzca un tiempo."
		 }	
		 else {
			document.getElementById("sms_2_time_error").innerHTML=""
		 }

		/*
		 if(document.getElementById("sms_3").value=="") {
			noerror=false;
			document.getElementById("sms_3_error").innerHTML="Por favor introduzca un SMS."
		 }	
		 else {
			document.getElementById("sms_3_error").innerHTML=""
		 }

		 if(document.getElementById("sms_3_time").value=="") {
			noerror=false;
			document.getElementById("sms_3_time_error").innerHTML="Por favor introduzca un tiempo."
		 }	
		 else {
			document.getElementById("sms_3_time_error").innerHTML=""
		 }
		*/
		 
	}


	 if(document.getElementById("country").value==0 && document.getElementById("country_free").value=="") {
		noerror=false;
		document.getElementById("country_error").innerHTML="Por favor selccione un paÃ­s."
	 }	
	 else {
		document.getElementById("country_error").innerHTML=""
	 }

	 if(document.getElementById("terms").checked=="") {
		noerror=false;
		document.getElementById("terms_error").innerHTML="Aceptar las condiciones generales del contrato!"
	 }	
	 else {
		document.getElementById("terms_error").innerHTML=""
	 }
	 
 return noerror;
}







function checkComment() {
 var noerror=true;

	 if(document.getElementById("comment").value=="") {
		noerror=false;
		document.getElementById("comment_error").innerHTML="Por favor introduzca un SMS."
	 }	
	 else {
		document.getElementById("comment_error").innerHTML=""
	 }

	 if(document.getElementById("country").value==0 && document.getElementById("country_free").value=="") {
		noerror=false;
		document.getElementById("country_error").innerHTML="Por favor selccione un país."
	 }	
	 else {
		document.getElementById("country_error").innerHTML=""
	 }

 return noerror;
}



function checkEmail() {

 var noerror=true;

	 if(document.getElementById("email").value=="") {
		noerror=false;
		document.getElementById("email_error").innerHTML="Por favor, introduzca la dirección de correo electrónico."
	 }	
	 else {
		document.getElementById("email_error").innerHTML=""
	 }

 return noerror;
}


function checkSearch() {
 if(document.getElementById("search-field").value=="") { return false; }	
}


function checkCountry() {
var noerror;
 if(document.getElementById("country").value=="") { 
 	noerror=false;
 	document.getElementById("country_error").innerHTML="Por favor selccione un país."
 }	
 else {
 	document.getElementById("country_error").innerHTML=""
 }
return noerror;
}



function updateClock ( )
{
  var currentTime = new Date ( );

  var currentDay = currentTime.getDay ( );
  
  //Convert the day component to day abbreviation
  currentDay = ( currentDay == 0 ) ? "Sun" : currentDay;
  currentDay = ( currentDay == 1 ) ? "Mon" : currentDay;
  currentDay = ( currentDay == 2 ) ? "Tue" : currentDay;
  currentDay = ( currentDay == 3 ) ? "Wed" : currentDay;
  currentDay = ( currentDay == 4 ) ? "Thu" : currentDay;
  currentDay = ( currentDay == 5 ) ? "Fri" : currentDay;
  currentDay = ( currentDay == 6 ) ? "Sat" : currentDay;
  
  var currentMonth = currentTime.getMonth( ); 
  
  //Convert the month component to text month
  currentMonth = ( currentMonth == 0 ) ? "January" : currentMonth;
  currentMonth = ( currentMonth == 1 ) ? "February" : currentMonth;
  currentMonth = ( currentMonth == 2 ) ? "March" : currentMonth;
  currentMonth = ( currentMonth == 3 ) ? "April" : currentMonth;
  currentMonth = ( currentMonth == 4 ) ? "May" : currentMonth;
  currentMonth = ( currentMonth == 5 ) ? "June" : currentMonth;
  currentMonth = ( currentMonth == 6 ) ? "July" : currentMonth;
  currentMonth = ( currentMonth == 7 ) ? "August" : currentMonth;
  currentMonth = ( currentMonth == 8 ) ? "September" : currentMonth;
  currentMonth = ( currentMonth == 9 ) ? "October" : currentMonth;
  currentMonth = ( currentMonth == 10) ? "November" : currentMonth;
  currentMonth = ( currentMonth == 11) ? "December" : currentMonth;
  
  var currentDate = currentTime.getDate( );
  
  // Add suffix to the date
  currentDate = ( currentDate == 1 || currentDate == 21 || currentDate == 31 ) ? currentDate + "st" : currentDate;
  currentDate = ( currentDate == 2 || currentDate == 22 ) ? currentDate + "nd" : currentDate;
  currentDate = ( currentDate == 3 ) || currentDate == 23 ? currentDate + "rd" : currentDate;
  currentDate = ( currentDate > 3 || currentDate < 21 || currentDate > 23 || currentDate < 31 ) ? currentDate + "th" : currentDate;
  
  
  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + " " + timeOfDay;

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
  
}


function textCounter(field, max, i) {
 var count = max - 1 - field.length;
 if (field.length+1 > max) {
	document.getElementById("sms_"+i).value = field.substring(0, max);
	document.getElementById("max_char_"+i).innerHTML = "0";
 }
 else {
 	document.getElementById("max_char_"+i).innerHTML = count;
 	
 	}
}	




function rateSMS(rating, id) {

  if(rating!="" && id!="") {
	http.open("GET", "ajax/rate.php?rating="+escape(rating)+"&id="+escape(id), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
  }

}





function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
    location.reload();
  }
}



function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

 var http = getHTTPObject();





function showRater(type,id) {
 if(type==1) {
	document.getElementById("rating-bar-rate_"+id).style.display="block";
	document.getElementById("rating-bar-show_"+id).style.display="none";
 }
 if(type==2) {
	document.getElementById("rating-bar-show_"+id).style.display="block";
	document.getElementById("rating-bar-rate_"+id).style.display="none";
 } 
}


