function validate_promotion_add() {
  var aErrors = new Array();

  if(document.promotion_add.main_url.value=='') {
    aErrors.push("You did not input Main site url");
  } else if(document.promotion_add.sim_url.value=='') {
    aErrors.push("You did not input Your site url");
  }
  
   var captcha = document.promotion_add.secret.value;

  jQuery.get('/checkCaptcha.php',
	    {'input_captcha': captcha},
	    function(data) {
	      if(data == "false") {
		aErrors.push("<p>You did not input correct captcha</p>");
	      }

	      if(aErrors.length == 0) {
		jQuery('#standard_error').empty();
		document.promotion_add.submit();
	      } else {
		jQuery('#standard_error').html(aErrors.join(""));
	      }
	    });
}

function validate_add_similar() {
  var aErrors = new Array();

  if(document.add_site.url.value=='') {
    aErrors.push("You did not input any site url");
  } else if(document.add_site.url.value) {
    if(document.add_site.url.value.match(new RegExp(/^http:\/\//)) || document.add_site.url.value.match(new RegExp(/^https:\/\//))) {
      aErrors.push("<p>The URL must not start with http:// or https:// Just omit the prefix in 'url' field and select proper option given below 'url' field</p>");
    }
  }

/*  if(document.add_site.tags.value=='') {
    aErrors.push("You did not input any site tags");
  } */
  if(document.add_site.tags.value=='') {
    aErrors.push("You did not input any tags, you must type in at least one tag!"); }
	
  else if(document.add_site.tags.value) {
    var aTags = document.add_site.tags.value.split(",");
    if(aTags.length > 10) {
      aErrors.push("<p>You are allowed to add max. 10 tags separated with commas</p>");
    }

    for(var i = 0; i < aTags.length; i++) {
      if(aTags[i].length > 20) {
	aErrors.push("<p>Tags longer than 20 characters are not allowed</p>");
	break;
      }
    }
  }

  var captcha = document.add_site.secret.value;

  jQuery.get('/checkCaptcha.php',
	    {'input_captcha': captcha},
	    function(data) {
	      if(data == "false") {
		aErrors.push("<p>You did not input correct captcha</p>");
	      }

	      if(aErrors.length == 0) {
		jQuery('#standard_error').empty();
		document.add_site.submit();
	      } else {
		jQuery('#standard_error').html(aErrors.join(""));
	      }
	    });
}

function validate_add_similar1() {
  var aErrors = new Array();

  if(document.add_site.url.value=='') {
    aErrors.push("You did not input any site url");
  } else if(document.add_site.url.value) {
    if(document.add_site.url.value.match(new RegExp(/^http:\/\//)) || document.add_site.url.value.match(new RegExp(/^https:\/\//))) {
      aErrors.push("<p>The URL must not start with http:// or https:// Just omit the prefix in 'url' field and select proper option given below 'url' field</p>");
    }
  }

/*  if(document.add_site.tags.value=='') {
    aErrors.push("You did not input any site tags");
  } */
	
  else if(document.add_site.tags.value) {
    var aTags = document.add_site.tags.value.split(",");
    if(aTags.length > 10) {
      aErrors.push("<p>You are allowed to add max. 10 tags separated with commas</p>");
    }

    for(var i = 0; i < aTags.length; i++) {
      if(aTags[i].length > 20) {
	aErrors.push("<p>Tags longer than 20 characters are not allowed</p>");
	break;
      }
    }
  }

  var captcha = document.add_site.secret.value;

  jQuery.get('/checkCaptcha.php',
	    {'input_captcha': captcha},
	    function(data) {
	      if(data == "false") {
		aErrors.push("<p>You did not input correct captcha</p>");
	      }

	      if(aErrors.length == 0) {
		jQuery('#standard_error').empty();
		document.add_site.submit();
	      } else {
		jQuery('#standard_error').html(aErrors.join(""));
	      }
	    });
}


function reportDissimilar(site_id, similar_id, similarity_id) {
  $.facebox({ ajax: '/facebox/report.php?site_id=' + site_id + '&similar_id=' + similar_id + '&similarity_id=' + similarity_id });
}

function suggestTags(site_id) {
  $.facebox({ ajax: '/facebox/suggestTags.php?site_id=' + site_id });
}

function refreshCaptcha(image_id) {
    var currentTime = new Date()
    var suffix = currentTime.getTime();
    var id_of_image = '#' + image_id;
    jQuery(id_of_image).attr("src", '/captcha.php?' + suffix);
}

function validate_suggest_tags(site_id) {
  var aErrors = new Array();

  if(document.suggestTagsForm.tags.value=='') {
    aErrors.push("<p>Tags input field must not be left empty</p>");
  }

  if(document.suggestTagsForm.tags.value) {
    var aTags = document.suggestTagsForm.tags.value.split(",");
    if(aTags.length > 10) {
      aErrors.push("<p>You are allowed to add max. 10 tags separated with commas</p>");
    }

    for(var i = 0; i < aTags.length; i++) {
      if(aTags[i].length > 20) {
	aErrors.push("<p>Tags longer than 20 characters are not allowed</p>");
	break;
      }
    }
  }

  var captcha = document.suggestTagsForm.secret.value;

  jQuery.get('/checkCaptcha.php',
	    {'input_captcha': captcha},
	    function(data) {
	      if(data == "false") {
		aErrors.push("<p>You did not input correct captcha</p>");
	      }

	      if(aErrors.length == 0) {
		jQuery('#facebox_error').empty();
		$.facebox({ ajax: '/facebox/suggestTags.php?action=saveTags&site_id=' + site_id + '&tags=' + document.suggestTagsForm.tags.value });
	      } else {
		jQuery('#facebox_error').html(aErrors.join(""));
	      }
	    });
}

function validate_report_dissimilar(similarity_id) {
  var reason;
  if(document.reportDissimilarForm.reportDissimilar[0].checked) {reason = 0;}
  else if(document.reportDissimilarForm.reportDissimilar[1].checked) {reason = 1;}
  else if(document.reportDissimilarForm.reportDissimilar[2].checked) {reason = 2;}
  else if(document.reportDissimilarForm.reportDissimilar[3].checked) {reason = 3;}
  else if(document.reportDissimilarForm.reportDissimilar[4].checked) {reason = 4;}

  var aErrors = new Array();

  if(reason == null) {
    aErrors.push("<p>You did not indicate any reason for reporting</p>");
  }

  var captcha = document.reportDissimilarForm.secret.value;

  jQuery.get('/checkCaptcha.php',
	    {'input_captcha': captcha},
	    function(data) {
	      if(data == "false") {
		aErrors.push("<p>You did not input correct captcha</p>");
	      }

	      if(aErrors.length == 0) {
		jQuery('#facebox_error').empty();
		$.facebox({ ajax: '/facebox/report.php?similarity_id=' + similarity_id + '&reason=' + reason });
	      } else {
		jQuery('#facebox_error').html(aErrors.join(""));
	      }
	    });
}
function switch_news(layer_id)
{
	document.getElementById('votes').style.display = "none";
	document.getElementById('similarity').style.display = "none";
	document.getElementById('added').style.display = "none";

	document.getElementById(layer_id).style.display = "block";
}
function switch_similar(layer_id)
{
	document.getElementById('site0').style.display = "none";
	document.getElementById('site1').style.display = "none";

	document.getElementById(layer_id).style.display = "block";
}