// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function toggleideas() {
   var divs = document.getElementsByTagName('p');
   for (var i = 0, ele; ele = divs[i]; i++) {
       if (ele.className == "ideadesc") {
        if ($('expand-collapse').checked)  
			ele.hide();
		else
			ele.show();
		
       }
   }
}

function showsome(url) {

	if ($('include').checked)  
		window.location = url + "?show=all"
	else
		window.location = url
		
}


function check_words() {
	
	error_msg = "There were some problems with submitting your proposal:\n\n";
	flag = false;
	
	if (countwords($F("description")) > 250) {
		error_msg = error_msg + "Elevator Pitch is more than 250 words\n";
		flag = true;
	}
	
	if (countwords($F("needs")) > 250) {
		error_msg = error_msg + "Needs is more than 250 words\n";
		flag = true;
	}

	if (countwords($F("approach")) > 350) {
		error_msg = error_msg + "Approach is more than 350 words\n";
		flag = true;
	}

	if (countwords($F("competition")) > 250) {
		error_msg = error_msg + "Competition is more than 250 words\n";
		flag = true;
	}

	if (countwords($F("sustainability")) > 250) {
		error_msg = error_msg + "Sustainability is more than 250 words\n";
		flag = true;
	}

	if (flag) {
		alert(error_msg);
		return false;
	} 
}


function countwords(value) {
	var a = value.split(/\s+/g); 

	if (value.length == 0) { 
		len = 0;
	} else {
		len = a.length;	
	}

	var text=value + " ";
	var iwhitespace = /^[^A-Za-z0-9]+/gi; // remove initial whitespace
	var left_trimmedStr = text.replace(iwhitespace, "");
	var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric characters
	var cleanedStr = left_trimmedStr.replace(na, " ");
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length - 1;
  	
	return word_count;
}


function updateStatusTextCharCounter(value, e) { 
  	var a = value.split(/\s+/g); 

	if (value.length == 0) { 
		len = 0;
	} else {
		len = a.length;	
	}

	var text=value + " ";
	var iwhitespace = /^[^A-Za-z0-9]+/gi; // remove initial whitespace
	var left_trimmedStr = text.replace(iwhitespace, "");
	var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric characters
	var cleanedStr = left_trimmedStr.replace(na, " ");
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length - 1;
	word_count;

  	
	if (word_count > 250) {
	//	word_count = 250
		$('js_textcount_description').update('<strong>' + (word_count - 250) + ' words over</strong>'); 
		$('js_textcount_approach').update('<strong>' + (word_count - 250) + ' words over</strong>'); 
		$('js_textcount_needs').update('<strong>' + (word_count - 250) + ' words over</strong>'); 
		$('js_textcount_rivals').update('<strong>' + (word_count - 250) + ' words over</strong>'); 
		$('js_textcount_sustainability').update('<strong>' + (word_count - 250) + ' words over</strong>'); 
	} else {	
		$('js_textcount_description').update('' + (250 - word_count) + ' words left'); 
		$('js_textcount_approach').update('' + (250 - word_count) + ' words left'); 
		$('js_textcount_needs').update('' + (250 - word_count) + ' words left'); 
		$('js_textcount_rivals').update('' + (250 - word_count) + ' words left'); 
		$('js_textcount_sustainability').update('' + (250 - word_count) + ' words left'); 
	}
} 

function updatePitchStatusTextCharCounter(value, e) { 
  	var a = value.split(/\s+/g); 

	if (value.length == 0) { 
		len = 0;
	} else {
		len = a.length;	
	}

	var text=value + " ";
	var iwhitespace = /^[^A-Za-z0-9]+/gi; // remove initial whitespace
	var left_trimmedStr = text.replace(iwhitespace, "");
	var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric characters
	var cleanedStr = left_trimmedStr.replace(na, " ");
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length - 1;
	word_count;

  	
	if (word_count > 128) {
	//	word_count = 250
		$('js_textcount_description').update('<strong>' + (word_count - 100) + ' words over</strong>'); 
	} else {	
		$('js_textcount_description').update('' + (100 - word_count) + ' words left'); 
	}
} 

function updateApproachStatusTextCharCounter(value, e) { 
  	var a = value.split(/\s+/g); 

	if (value.length == 0) { 
		len = 0;
	} else {
		len = a.length;	
	}

	var text=value + " ";
	var iwhitespace = /^[^A-Za-z0-9]+/gi; // remove initial whitespace
	var left_trimmedStr = text.replace(iwhitespace, "");
	var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric characters
	var cleanedStr = left_trimmedStr.replace(na, " ");
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length - 1;
	word_count;

  	
	if (word_count > 350) {
	//	word_count = 250
		$('js_textcount_approach').update('<strong>' + (word_count - 350) + ' words over</strong>'); 
	} else {	
		$('js_textcount_approach').update('' + (350 - word_count) + ' words left'); 
	}
} 

function search_go(url, e) {
	if (e.value == "xls") {
		window.location = url;
	} 
}

function goe(url, e) {
	window.location = url + e.value; 
}

function go(url) {
	window.location = url; 
}