$(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.com');			
			//window.location.href = "http://www.fixodent.com";
			window.open ("http://www.fixodent.com");
			break;
			case 'ca' :
			//window.location.replace('http://www.fixodent.ca');
			//window.location.replace('http://www.fixodent.ca/en/');			
			//window.location.href = "http://www.fixodent.ca/en/";			
			window.open ("http://www.fixodent.ca/en/");
			break;
			case 'cr' :
			//window.location.replace('http://www.pg.com.hr/products/mouthcare/blendadent.shtml');
			//window.location.href = "http://www.pg.com.hr/products/mouthcare/blendadent.shtml";
			window.open ("http://www.pg.com.hr/products/mouthcare/blendadent.shtml");
			break;
			case 'de' :
			//window.location.replace('http://www.blend-a-dent.de');
			//window.location.href = "http://www.blend-a-dent.de";
			window.open ("http://www.blend-a-dent.de");
			break;
  			case 'hu' :
			//window.location.replace('http://www.pg.hu/products/mouthcare/blendadent.shtml');
			//window.location.href = "http://www.pg.hu/products/mouthcare/blendadent.shtml";
			window.open ("http://www.pg.hu/products/mouthcare/blendadent.shtml");
			break;
			case 'uk' :
			//window.location.replace('http://www.fixodent.co.uk');
			//window.location.href = "http://www.fixodent.co.uk";
			window.open ("http://www.fixodent.co.uk");
			break;			
			case 'fr' :
			//window.location.replace('http://www.fixodent.fr');
			//window.location.href = "http://www.fixodent.fr";
			window.open ("http://www.fixodent.fr");
			break;
			case 'it' :
			window.open ("http://www.kukident.it");
			break;
		}
	}
}


function change_product(product){
	if(product != "") {
		switch (product) {
   			case '1' :			
			window.location.href = "/fixodent-denture-products/buy-fixodent-comfort";
			break;
   			case '2' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-food-seal-plus-scope-flavor";
			break;
   			case '3' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-complete";
			break;
   			case '4' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-free";
			break;
   			case '5' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-food-seal";
			break;
   			case '6' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-fresh";
			break;
   			case '7' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-original";
			break;
   			case '8' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-food-seal-to-go";
			break;
   			case '9' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-extra-hold-powder";
			break;
   			case '10' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-denture-cleanser-plus-scope-ingredients";
			break;
   			case '11' :
			window.location.href = "/fixodent-denture-products/buy-fixodent-denture-cleanser-advanced-whitening";
			break;
		}
	}
}
