function replaceAllString(strText,matchVal,replaceVal)
{
	var strReplaceAll = strText;
	var intIndexOfMatch = strText.indexOf(matchVal);
 	// Loop over the string value replacing out each matching
	// substring.
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strReplaceAll = strReplaceAll.replace( matchVal, replaceVal )
		// Get the index of any next matching substring.
		intIndexOfMatch = strReplaceAll.indexOf( matchVal );
	}
	return strReplaceAll;
}

function hideClass(className)
{
	var items = $$('.'+className);

	items.each(function (item) {
		item.hide();
	});
}

function showClass(className)
{

	var items = $$('.'+className);

	items.each(function (item) {
		item.show();
	});
}


function clearComments()
{
	if ($('comments').value == 'Enter Comments Here...')
		$('comments').value = '';
}


function showTerms(){
		
	var dims = $('terms_explain').getDimensions();
	var top_offset = (window.pageYOffset) ? window.pageYOffset :  document.body.scrollTop;
	
	var w = 0;	var h = 0;		
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
		
	x_pos = Math.round((w * 0.5 - dims.width / 2 ));
	y_pos = top_offset + Math.round((h - dims.height) * .2);
	
	new Effect.Move('terms_explain',{ x: x_pos, y: y_pos, mode: 'absolute', duration: 0.0 });
	new Effect.Appear('terms_explain', {duration: 0.2});		
}



function showCVV2(){
		
	var dims = $('cvv2').getDimensions();
	var top_offset = (window.pageYOffset) ? window.pageYOffset :  document.body.scrollTop;
	
	var w = 0;	var h = 0;		
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
		
	x_pos = Math.round((w * 0.5 - dims.width / 2 ));
	y_pos = top_offset + Math.round((h - dims.height) * 0.5);
	
	new Effect.Move('cvv2',{ x: x_pos, y: y_pos, mode: 'absolute', duration: 0.0 });
	new Effect.Appear('cvv2', {duration: 0.2});		
}

function kudos(t){
	if(t.length > 0){
		$('generosity').innerHTML = "You are very generous " + t + ", thank you.";
	}else{
		$('generosity').innerHTML = '';
	}
}

function checkInternational(checked){
	if(checked){
		$('int_fields').show();
		$('us_fields').hide();
		$('us_city').disabled = true;
		$('int_city').disabled = false;
		$('int_city').value = $('us_city').value;
		$('us_zip').disabled = true;
		$('int_zip').disabled = false;
		$('int_zip').value = $('us_zip').value;
	}else{
		$('int_fields').hide();
		$('us_fields').show();
		$('us_city').disabled = false;
		$('int_city').disabled = true;
		$('us_city').value = $('int_city').value;
		$('us_zip').disabled = false;
		$('int_zip').disabled = true;
		$('us_zip').value = $('int_zip').value;
	}
}
