$(document).ready(function() {
	
	// Story submissions - mimic maxlength attribute on a textarea (since said attribute doesn't exist)
	// also, dynamically count characters as they're typed
	
	var max = 500;
	if ($("#question").length > 0)
	{
		var len = $('#question').val().length;
	}
	else
	{
		var len = 0;
	}
		
	$('#characters').html(max - len);
	
	$('#question').keyup(function() {
		var charLength = $(this).val().length;
		var newLength = max - charLength;		
		if (newLength > 999)
		{			
			newLength = addCommas(newLength);
		}
	  	$('#characters').html(newLength);	
	  	if ($(this).val().length > max)
	  	{
	    	$(this).val($(this).val().substr(0, max));
	  	}
	});
	
});


/************************************************************************************************		
							MindTree Changes for Removal of admin_characters count
*************************************************************************************************/
/*	
$(document).ready(function() {
	
	// Story submissions - mimic maxlength attribute on a textarea (since said attribute doesn't exist)
	// also, dynamically count characters as they're typed
	
	var max = 500;
	if ($("#admin_response").length > 0)
	{
		var len = $('#admin_response').val().length;
	}
	else
	{
		var len = 0;
	}
		
	$('#admin_characters').html(max - len);
	
	$('#admin_response').keyup(function() {
		var charLength = $(this).val().length;
		var newLength = max - charLength;		
		if (newLength > 999)
		{			
			newLength = addCommas(newLength);
		}
	  	$('#admin_characters').html(newLength);	
	  	if ($(this).val().length > max)
	  	{
	    	$(this).val($(this).val().substr(0, max));
	  	}
	});
	
});

*/

function countChars(max, id)
{
	var len = $('#'+id).val().length;
	$('#characters').html(max - len);
	
	var charLength = $('#'+id).val().length;
	var newLength = max - charLength;
			
	if (newLength > 999)
	{			
		newLength = addCommas(newLength);
	}
	
  	$('#characters').html(newLength);	

  	if ($('#'+id).val().length > max)
  	{
    	$('#'+id).val($('#'+id).val().substr(0, max));
  	}
}

function addCommas(the_int)
{
	var str = new String(the_int);
	var arr = new Array();
	arr = str.split("");
	var new_str = new String();	
	var new_arr = new Array();
	
	new_arr[0] = arr[0];
	new_arr[1] = ",";
	new_arr[2] = arr[1];
	new_arr[3] = arr[2];
	new_arr[4] = arr[3];
	
	new_str = new_arr.join("");
	
	return new_str;
}

function bwwNewWindow(strMyPage, strMyName, intWidth, intheight, scroll) {
	var intWidth;   // width and height of the popup window, these values are in the anchor link
	var intheight;  //
	var intWinLeft = 25; // location of the popup window, this is set at the center of screen
	var intWinTop = 25;
	var strWinprops = 'height='+intheight+',width='+intWidth+',top='+intWinTop+',left='+intWinLeft+',scrollbars='+scroll+',resizable=no'; 
	var strwin = window.open(strMyPage, strMyName, strWinprops);
	if (parseInt(navigator.appVersion) >= 4) { strwin.window.focus(); }
}

function change_country(country){
	if(country != ""){
		switch (country) {
   			case 'en' :
			window.location.replace('http://www.fixodent.ca/en/');
			break;
			case 'ca' :
			window.location.replace('http://www.fixodent.ca/en/');
			break;
			case 'cr' :
			window.location.replace('http://www.pg.com.hr/products/mouthcare/blendadent.shtml');
			break;
			case 'de' :
			window.location.replace('http://www.blend-a-dent.de');
			break;
  			case 'hu' :
			window.location.replace('http://www.pg.hu/products/mouthcare/blendadent.shtml');
			break;
			case 'uk' :
			window.location.replace('http://fixodent.co.uk');
			break;
		}
	}
}