// JavaScript Document
//calcInstantQuote()
$(document).ready(function() {
						   
	$('#upload').click(function(event){
		var uploadIframe = $('<iframe id="uploadframe" scrolling="no" frameborder="0" src="instantQuoteUpload.aspx"></iframe>');
		$("#uploadframe").remove();
		$("div#uploadForm").append(uploadIframe);
		$("div#uploadbox").slideDown("slow");
		
	});
	$('#closeUploadForm').click(function(event){
		$("div#uploadbox").hide();
		calcInstantQuote();
		//alert(iframe.height);
	});
						   
	$('#enteredtext').keyup( function(event){calcInstantQuote(-2);} );
	$('#iq_source_language').change(calcInstantQuote);
	$('#iq_target_language').change(calcInstantQuote);
	$("input[name='rbTranslationType_0']").change(calcInstantQuote);
	$("input[name='rblProofReading_0']").change(calcInstantQuote);
	
	function calcInstantQuote(q){
		//var wordCount  = jQuery.trim($('#enteredtext').val()).split(/\b[\s,\.-:;]*/).length;
		var wordCountMethod = 0;//wordCountMethod 0 is DirectText
		if (q == -2)
			wordCountMethod = -2;
		//alert(wordCountMethod);	
		var wordCount  = jQuery.trim($('#enteredtext').val()).split(/[\s\\?]+/).length;
		var sourceLanguage = $('#iq_source_language').val();
		var targetLanguage = $('#iq_target_language').val();
		var translationType = $("input[name='rbTranslationType_0']:checked").val();
		var proofread = $("input[name='rblProofReading_0']:checked").val();

	$.post(
		   'calculateInstantQuote.aspx',
		   {'sourceLanguage':sourceLanguage,
			'targetLanguage':targetLanguage,
		    'proofread':proofread,
			'translationType':translationType,
			'wordCountMethod': wordCountMethod,
			'wordCount':wordCount}, 
		   function(data) {
				var oldHeight = $('#calulated').height();
				$('#calulated').html(data);
				var newHeight = $('#calulated').height();
				var delta = newHeight - oldHeight;
				if (delta>0)
					$('body').height($('body').height()+delta);
				//alert($('body').height());
		   }
	);
		
		//alert(translationType);
	}
	
	
	$('#TranslatorProfile').click(function(event){
		//$('#leftside').remove();
	});
});