// JavaScript Document


// **************************** TO RESTRICT UPC FIELD TO NUMBERS ONLY

// copyright 1999 Idocs, Inc. http://www.idocs.com
function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;	  
	   
	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   	myfield.form.elements[dec].focus();
	   	return false;
	   }
	else
	   return false;
}


// **************************** TO KEEP CHECKED LIMIT ON CHECKBOXES 1

function limitmaxansw_1(me)
{
	max=3
	count=0;
	if (max == 0) { return count; }
	if (document.getElementById('fav1').checked) { count += 1; }
	if (document.getElementById('fav2').checked) { count += 1; }
	if (document.getElementById('fav3').checked) { count += 1; }
	if (document.getElementById('fav4').checked) { count += 1; }
	if (document.getElementById('fav5').checked) { count += 1; }
	if (document.getElementById('fav6').checked) { count += 1; }
	if (document.getElementById('fav7').checked) { count += 1; }
	if (document.getElementById('fav8').checked) { count += 1; }
	if (count > max)
	{
		alert('Please choose at most ' + max + ' answers.');
		if (me.type == 'checkbox') {me.checked = false;}
		return max;
	}
}

// **************************** TO KEEP CHECKED LIMIT ON CHECKBOXES 2

function limitmaxansw_2(me)
{
	max=3
	count=0;
	if (max == 0) { return count; }
	if (document.getElementById('buy1').checked) { count += 1; }
	if (document.getElementById('buy2').checked) { count += 1; }
	if (document.getElementById('buy3').checked) { count += 1; }
	if (document.getElementById('buy4').checked) { count += 1; }
	if (document.getElementById('buy5').checked) { count += 1; }
	if (document.getElementById('buy6').checked) { count += 1; }
	if (document.getElementById('buy7').checked) { count += 1; }
	if (document.getElementById('buy8').checked) { count += 1; }
	if (document.getElementById('buy9').checked) { count += 1; }
	if (document.getElementById('buy10').checked) { count += 1; }
	if (document.getElementById('buy11').checked) { count += 1; }
	if (document.getElementById('buy13').value != '' || document.getElementById('buy12').checked ) { count += 1; }
	if (count > max)
	{
		alert('Please choose at most ' + max + ' answer(s) for that question.');
		if (me.type == 'checkbox') {me.checked = false;}
		if (me.type == 'text') 
		{
			me.value = '';
			if (document.getElementById('buy12'))
			{
				document.getElementById('buy12').checked = false;
			}
		}	return max;
	}
}

// **************************** TO SWAP IMAGE ON MOUSEOVER

function btn_swap(button_id, img)
{
	var btn = document.getElementById(button_id);
	btn.src = img;
}

// **************************** Rollover Script using jQuery

var jq_rollOver_cache = new Object();

$("img.swap").each(
	function(i)
	{
		var imgsrc = this.src;
		var dotpos = imgsrc.lastIndexOf('.');
		var imgsrc_over = imgsrc.substr(0,dotpos) + '-over.' + imgsrc.substr(dotpos+1);

		jq_rollOver_cache[this.src] = new Image();
		jq_rollOver_cache[this.src].src = imgsrc_over;

		$(this).hover(
			function(){ this.src = imgsrc_over; },
			function(){ this.src = imgsrc; }
		)
	}
);

// **************************** LIMIT LENGTH OF TEXT BOX

function check_length(input_form)
{
	maxLen = 500; // max number of characters allowed
	if (input_form.comments.value.length > maxLen) 
	{
		// Alert message if maximum limit is reached.
		var txt_msg = "Oops that was a bit too long. Please limit you comments to " + maxLen + " characters. Thanks!";
		alert(txt_msg);
		// Reached the Maximum length so trim the textarea
		input_form.comments.value = input_form.comments.value.substring(0, maxLen);
	}
	else
	{ 
		// Maximum length not reached so update the value of comments counter
		input_form.text_num.value = maxLen - input_form.comments.value.length;
	}
}

// **************************** POP-UP WINDOW
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=715,height=800,scrollbars=yes');
return false;
}

// **************************** POP-UP WINDOW - Close Button
function targetopener(mylink, closeme, closeonly)
{
if (! (window.focus && window.opener))return true;
window.opener.focus();
if (! closeonly)window.opener.location.href=mylink.href;
if (closeme)window.close();
return false;
}



