var seo_url_templates = new Array('[speciality]-translations-from-[source]-to-[target].html', 
	'traduction-[speciality]-du-[source]-vers-le-[target].html', '', 
	'[speciality]-Uebersetzungen-aus-dem-[source]-ins-[target].html');
var value_inputs_text = new Array();
var ajax_ext = "aspx";

function include(filename)
{
	var body = document.getElementsByTagName('body').item(0);
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	body.appendChild(script)
}

function ShowHide(id)
{
	var l = document.getElementById("l_" + id);
	if (l.style.display != "none")
	{
		l.style.display = "none";
		document.getElementById("i_" + id).innerText = '4';
	}
	else
	{
		l.style.display = "";
		document.getElementById("i_" + id).innerText = '6';
	}
}
//var global_message = new Array();

function location_redirect_select_language(){
	url = url_page+'?lang='+$("#language-selector-id").val();
	//msgBox(url);
	document.location.href = url;

	return 1;
} 

function manage_inputs_text(){
	var id_inputs_text = new Array("edit-name","edit-pass", "request-contact-form-name", "request-contact-form-phone", 
		"request-contact-form-mail", "email-this-quote-to", "email-this-quote-cc", "order-request-name",
		"order-request-phone", "order-request-mail", "request-quote-message");	
	$.each(id_inputs_text, function(key, value) {
		value_inputs_text[value] = $("#"+value).val();
		$("#"+value).focus(function () { if($(this).val()==value_inputs_text[value]) $(this).val('');});	
		$("#"+value).blur(function () { if($(this).val()=="") $(this).val(value_inputs_text[value]);});	
	      
	});
	var word_count = $("#word-count").val();
	$("#word-count").focus(function () { if($(this).val()==$("#word-count").val() || $(this).val()==global_message['unreadable']) $(this).val(''); $("#word-count").css('color', '#000000');});	
	$("#word-count").blur(function () { if($(this).val()=="") $(this).val(word_count);});	

	var request_message = $("textarea#request-contact-form-message").val();
	$("#request-contact-form-message").focus(function () { if($("textarea#request-contact-form-message").val()==request_message) $("textarea#request-contact-form-message").val('');});
	$("#request-contact-form-message").blur(function () { if($("textarea#request-contact-form-message").val()=="") $("textarea#request-contact-form-message").val(request_message);});
}

function panes(pane_name){

	if(pane_name =='instant-pricing'){
		$("#corps-central-form-0").css({visibility:"visible"});
		$("#corps-central-form-1").css({visibility:"hidden"});
		$("a.instant-pricing").find("img").attr("src", "http://www.translatemedia.com/wp-content/themes/translatemedia/img/EN/tab0_on.png");		
		$("a.request-contact").find("img").attr("src", "http://www.translatemedia.com/wp-content/themes/translatemedia/img/EN/tab1_off.png");	

		$("#tab0-text").css("color", "#FFFFFF");
		$("#tab1-text").css("color", "#60A6D9");	
		
	}else{
		$("#corps-central-form-1").css({visibility:"visible"});
		$("#corps-central-form-0").css({visibility:"hidden"});
		$("a.instant-pricing").find("img").attr("src", "http://www.translatemedia.com/wp-content/themes/translatemedia/img/EN/tab0_off.png");		
		$("a.request-contact").find("img").attr("src", "http://www.translatemedia.com/wp-content/themes/translatemedia/img/EN/tab1_on.png");		

		$("#tab0-text").css("color", "#60A6D9");	
		$("#tab1-text").css("color", "#FFFFFF");	
	}
	
}



function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }



// pre-submit callback 
function showRequest(formData, jqForm, options) { 
	
	//reset doc
		$('#order-instant-pricing-doc-id').val(-1);
	// INSTANT PRICING FORM VALIDATION
	  source_lang = $("#instant-pricing-from").val();
		if (source_lang < 0) {
		  msgBox(global_message['warning_source_language']);
		  return false;
	  }

	  target_lang = $("#instant-pricing-to").val();
		if (target_lang < 0) {
		  msgBox(global_message['warning_target_language']);
		  return false;
	  }

	  doc_type = $("#instant-pricing-doc-type").val();
		if (doc_type < 0) {
		  msgBox(global_message['warning_doc_type']);
		  return false;
	  }

	  certification = $("#instant-pricing-certification").val();
		if (certification < 0) {
			$("#instant-pricing-certification").val(0);
		  //msgBox(global_message['warning_certification']);
		  //return false;
	  }

	  word_count = $("#word-count").val();
		if (!IsNumeric(word_count) || word_count <= 0) {
		  file = $("#instant-pricing-file").val();
			if (file.length == 0)
			{
			  msgBox(global_message['warning_word_count']);
		 	 	return false;
			}
	  }
	  else
	  {
	  	getQuote();
	  	return false;
		}
	  // END OF INSTANT PRICING FORM VALIDATION
	  
		$('#ajax-loader').show();

	  HideQuoteDetails();

	  
	  // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
    
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
   // msgBox('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
function getQuote()
{
	  source_lang = $("#instant-pricing-from").val();
	  target_lang = $("#instant-pricing-to").val();
	  doc_type = $("#instant-pricing-doc-type").val();
	  certification = $("#instant-pricing-certification").val();
	  word_count = $("#word-count").val();

	var bManualQuote = false;
	if (isNaN(word_count) || word_count <= 0)
	{
		word_count = 1000;
		$("#word-count").css('color', 'red');
		$("#word-count").val(global_message['unreadable']);
		bManualQuote = true;
	}
	
	document.body.style.cursor = "wait";
	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully 
		{
			document.body.style.cursor = "default";
			//http.responseText contains the response
			if (http.responseText == "ERROR")
			{
				msgBox(global_message['unexpected_error']);
				return;
			}
			
			var aQuote = http.responseText.split('^');
			showQuote(aQuote, bManualQuote);

			bbb= $("#order-instant-pricing-language").val();
			aaa= seo_url_templates[0];
			aaa= seo_url_templates[1];
			var sUrl = seo_url_templates[$("#order-instant-pricing-language").val()];
			sUrl = sUrl.replace('[source]', $("#instant-pricing-from :selected").text()).replace('[target]', $("#instant-pricing-to :selected").text()).replace('[speciality]', $("#instant-pricing-doc-type :selected").text());
			var sUrl = 'http://' + window.location.host + '/' + sUrl;
			//var sUrl = 'http://' + window.location.host + '/' + $("#instant-pricing-doc-type :selected").text() + '-translation-from-' + 
			//$("#instant-pricing-from :selected").text() + '-to-' + $("#instant-pricing-to :selected").text() + '.html';
			//loadHTMLContentArea(sUrl);
		}
	};

		label = 'from ' + $("#instant-pricing-from :selected").text() + ' to ' + 
			$("#instant-pricing-to :selected").text() + ' ' + $("#instant-pricing-doc-type :selected").text() + ' ' +
		 ($("#instant-pricing-certification").val() > 0 ? $("#instant-pricing-certification :selected").text() : '');
	//_gaq.push(['_trackEvent', 'Quote', 'Get', label]);

	sHost = window.location.host;
	var cur = $('#order-instant-pricing-currency').val();
	http.open("GET", "http://" + sHost + "/ajax/QuoteActions." + ajax_ext + "?action=quote&idCur=" + cur + "&idSource=" + 
		source_lang + "&idSpec=" + doc_type + "&idTarget=" + target_lang+ "&idCert=" + certification + "&WordCount="+word_count, true);

	http.send(null);
}

function SetDocumentDetails(idDocument, iWordCount)
{
		$('#order-instant-pricing-doc-id').val(idDocument);
		$("#word-count").val(iWordCount);
		getQuote();
}

// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)
{
	//getQuote();
}

// post-submit callback 
function showQuote(aQuote, bManualQuote)//(responseText, statusText, xhr, $form)
{ 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
	$('#instant-pricing-return-manual').hide();

	$("#instant-pricing-return-price").html(aQuote[0] + '*');
	$("#instant-pricing-return-turnout").html(aQuote[1] + '*');
	$('#order-instant-pricing-currency').val(aQuote[2]);
	
	$('#ajax-loader').hide();

	if (!bManualQuote)
	{
	  	$('#instant-pricing-return').slideDown('slow', function() {
			// Animation complete.
		});
	  	$('#turnaround-note').slideDown('slow', function() {
			// Animation complete.
		});
	}
	else
	{
		var sRate = global_message['tanslation_rate'];
		sRate = sRate.replace('[source]', $("#instant-pricing-from :selected").text());
		sRate = sRate.replace('[target]', $("#instant-pricing-to :selected").text());
		sRate = sRate.replace('[speciality]', $("#instant-pricing-doc-type :selected").text());
		$("#request-quote-rate").html(sRate + aQuote[0]);
		$('#instant-pricing-return-manual').slideDown('slow', function() {
			// Animation complete.
		});
	}

  	// populate the uploaded path if any
  	
  	//$("#instant-pricing-uploaded-file-path").val(responseText['uploaded_file_path']);
  	             
  	// populate input hidden fields in the order now form and the email this quote form
	var id_inputs_instant_pricing = new Array("instant-pricing-from", "instant-pricing-to", "instant-pricing-doc-type", "instant-pricing-certification","word-count", "instant-pricing-uploaded-file-path");	
	$.each(id_inputs_instant_pricing, function(key, value) {
		$("#email-"+value).val($("#"+value).val());	
		$("#order-"+value).val($("#"+value).val());	
	});
	var id_html_instant_pricing = new Array("instant-pricing-return-price", "instant-pricing-return-turnout" );	
	$.each(id_html_instant_pricing, function(key, value) {
		$("#email-"+value).val($("#"+value).html());	
		$("#order-"+value).val($("#"+value).html());	
	});
  	
		
/*  msgBox('status: ' + statusText + '\n\nresponseText: \n' + responseText['price'] + 
      '\n\nThe output div should have already been updated with the responseText.');
      */ 


    }
    
$(document).ready(function()
{
	try
	{
		if ($("#order-instant-pricing-language").val() == 3 || $("#order-instant-pricing-language").val() == 0)
			ajax_ext = "php";
			
		SetPhoneNumber(); //sets the phone number

		getUserdetails();
	  fillSourceLangList();
	  
	  //check if it is the feedback page. //fix me! not the best solution
	  if(document.location.href.indexOf("translationfeedback.html", 0) >= 0)
	  	loadFeedback();

	  $('selectbox_instant-pricing-from').bind('change', function(){ msgBox('Selected value: '+this.value) } )
	
		$("#language-selector-id").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		$("#instant-pricing-from").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		$("#instant-pricing-to").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		$("#instant-pricing-doc-type").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		$("#instant-pricing-certification").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		
		  /*$("#language-selector-id").change(function () {
			  if (location_redirect_select_language()) return;
	      });	*/
		  manage_inputs_text();
		  
		  // the file input styling
	  $("#instant-pricing-file").filestyle({ 
		     image: "http://www.translatemedia.com/wp-content/themes/translatemedia/img/instant-pricing-upload.png",
		     imageheight : 29,
		     imagewidth : 47,
		     width : 106,
		     paddingtop : 7,
		     sentence : $('#instant-pricing-file').attr('text')
		 });	  
	
		$("#instant-pricing-form").css({visibility:"visible"});
		
		$('#language-selector-id').change(function() {
			  var lng = $("#language-selector-id").val();
			  if (lng == 'de')
			  	window.location = 'http://www.translatemedia.de';
			  else if (lng == 'fr')
			  	window.location = 'http://www.translatemedia.fr';
			  else
			  	window.location = 'http://www.translatemedia.co.uk';
			});
		
			$('#instant-pricing-file').change(function() {
			  $("#word-count").val('');
			});
	
		  // the panes, central form
			$('a.instant-pricing').removeAttr("href");
			$('a.request-contact').removeAttr("href");
		  
		  //show contact request pane
		  panes('request-contact');

			$('a.instant-pricing').click(function() {			panes('instant-pricing');		});
			$('a.request-contact').click(function() {			panes('request-contact');		});
	
			$('#tab0-text').click(function() {			panes('instant-pricing');		});
			$('#tab1-text').click(function() {			panes('request-contact');		});
			
			$('#instant-pricing-return').hide();
			$('#instant-pricing-return-manual').hide();
			$('#turnaround-note').hide();
			$('#email-this-quote').hide();
			$('#ajax-loader').hide();
						
		//warranty
		$('#warranty-top').click(function() {
			if ($('#warranty-bottom').is(':visible'))
				$('#warranty-bottom').slideUp('slow', function() { /*Animation complete. */});
			else
				$('#warranty-bottom').slideDown('slow', function() { /*Animation complete.*/});				
			});

			$('#open-email-this-quote').click(function() {
				$('#email-this-quote').slideDown('slow', function() {
					// Animation complete.
				});
				return false;
			});		
			
			$('#request-quote-submit').click(function(){getManualQuote();});
			$('#cancel-email').click(function() {
				$('#email-this-quote').slideUp('slow', function() {
					// Animation complete.
				});
				return false;
			});		
			
			
	        var options = { 
	                target:        '#output1',   // target element(s) to be updated with server response 
	                beforeSubmit:  showRequest,  // pre-submit callback 
	                success:       showResponse,  // post-submit callback 
	         
	                // other available options: 
	                url:       'http://www.tm-stream.com/ajax/QuoteActions.aspx'         // override for form's 'action' attribute 
	                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
	                //dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
	                //clearForm: true        // clear all form fields after successful submit 
	                //resetForm: true        // reset the form after successful submit 
	         
	                // $.ajax options can be used here too, for example: 
	                //timeout:   10000 
	            }; 
	            // bind form using 'ajaxForm' 
		        $('#instant-pricing-form').ajaxForm(options); 		
	
	        options = { 
	                target:        '#output1',   // target element(s) to be updated with server response 
	                beforeSubmit:  login,  // pre-submit callback 
	                success:       function() { alert('success'); return true; },  // post-submit callback 
	         
	                // other available options: 
	                url:       'utilities/ajax.php',         // override for form's 'action' attribute 
	                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
	                dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
	                //clearForm: true        // clear all form fields after successful submit 
	                //resetForm: true        // reset the form after successful submit 
	         
	                // $.ajax options can be used here too, for example: 
	                //timeout:   10000 
	            }; 
	            // bind form using 'ajaxForm' 
		        $('#user-login').ajaxForm(options);
	
	        options = { 
	                target:        '#output1',   // target element(s) to be updated with server response 
	                beforeSubmit:  getSearchResults,  // pre-submit callback 
	//                success:       function() { alert('success'); return true; },  // post-submit callback 
	         
	                // other available options: 
	                url:       'utilities/ajax.php',         // override for form's 'action' attribute 
	                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
	                dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
	                //clearForm: true        // clear all form fields after successful submit 
	                //resetForm: true        // reset the form after successful submit 
	         
	                // $.ajax options can be used here too, for example: 
	                //timeout:   10000 
	            }; 
	            // bind form using 'ajaxForm'
		        $('#search-form').ajaxForm(options);
	
	        options = { 
	                target:        '#output1',   // target element(s) to be updated with server response 
	                beforeSubmit:  sendEmailQuote  // pre-submit callback 
	//                success:       function() { alert('success'); return true; },  // post-submit callback 
	         
	                // other available options: 
	                //url:       'utilities/ajax.php',         // override for form's 'action' attribute 
	                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
	                //dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
	                //clearForm: true        // clear all form fields after successful submit 
	                //resetForm: true        // reset the form after successful submit 
	         
	                // $.ajax options can be used here too, for example: 
	                //timeout:   10000 
	            }; 
	            // bind form using 'ajaxForm' 
		        $('#email-this-quote').ajaxForm(options);
	
	        options = { 
	                target:        '_self',   // target element(s) to be updated with server response 
	                beforeSubmit:  onOrder,  // pre-submit callback 
	//                success:       function() { alert('success'); return true; },  // post-submit callback 
	         
	                // other available options: 
	                url:       'http://www.tm-stream.com/registration-and-place-order2.aspx'         // override for form's 'action' attribute 
	                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
	                //dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
	                //clearForm: true        // clear all form fields after successful submit 
	                //resetForm: true        // reset the form after successful submit 
	         
	                // $.ajax options can be used here too, for example: 
	                //timeout:   10000 
	            }; 
	            // bind form using 'ajaxForm' 
		        $('#order-now-form').ajaxForm(options);
	        options = { 
	                target:        '#output1',   // target element(s) to be updated with server response 
	                beforeSubmit:  function(){return false;},  // pre-submit callback 
	//                success:       function() { alert('success'); return true; },  // post-submit callback 
	         
	                // other available options: 
	                url:       'http://www.tm-stream.com/registration-and-place-order2.aspx'         // override for form's 'action' attribute 
	                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
	                //dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
	                //clearForm: true        // clear all form fields after successful submit 
	                //resetForm: true        // reset the form after successful submit 
	         
	                // $.ajax options can be used here too, for example: 
	                //timeout:   10000 
	            }; 
	            // bind form using 'ajaxForm' 
	        options = { 
	                target:        '#output1',   // target element(s) to be updated with server response 
	                beforeSubmit:  function(){onContactRequest (); return false;},  // pre-submit callback 
	//                success:       function() { alert('success'); return true; },  // post-submit callback 
	         
	                // other available options: 
	                url:       'http://www.tm-stream.com/registration-and-place-order2.aspx'         // override for form's 'action' attribute 
	                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
	                //dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
	                //clearForm: true        // clear all form fields after successful submit 
	                //resetForm: true        // reset the form after successful submit 
	         
	                // $.ajax options can be used here too, for example: 
	                //timeout:   10000 
	            }; 
		        $('#request-contact-form').ajaxForm(options);
		  }
		  catch(err)
		  {
		  	alert(err);
		  }
		}
	);

function getSearchResult(lnk)
{
	try
	{
		document.body.style.cursor = "wait";
		http = getHttpAjaxObject();
		http.onreadystatechange = function()	//handler function executated when the ready state is changed
		{
			if (http.readyState == 4)//HTTP request ended successfully 
			{
				document.body.style.cursor = "default";
				document.getElementById('contentarea').innerHTML = http.responseText;
			}
		}

		sHost = window.location.host;
		sParams = lnk.href.substring(lnk.href.indexOf('search.pl?')+10);
		http.open("GET", "http://" + sHost + "/ajax/SearchResults." + ajax_ext + "?url=" + sParams, true);
		http.send(null);
	}
	catch(err)
	{
		alert(err);
		return false;
	}
	
	return false;
}

function getSearchResults()
{
	try
	{
		sSearchText = document.getElementById('edit-search-theme-form-1').value;
		if (sSearchText.length == 0)
			return false;
		document.body.style.cursor = "wait";
		http = getHttpAjaxObject();
		http.onreadystatechange = function()	//handler function executated when the ready state is changed
		{
			if (http.readyState == 4)//HTTP request ended successfully 
			{
				document.body.style.cursor = "default";
				document.getElementById('contentarea').innerHTML = http.responseText;
			}
		}

		sHost = window.location.host;
		http.open("GET", "http://" + sHost + "/ajax/SearchResults." + ajax_ext + "?Terms=" + sSearchText, true);
		http.send(null);
	}
	catch(err)
	{
		alert(err);
	}

	return false;
}

// get AJAX object		//fix me! we should use JQuery	
function getHttpAjaxObject()
{
	var http = null; 
	if(window.XMLHttpRequest)
		http = new XMLHttpRequest(); 
	else if (window.ActiveXObject)
		http  = new ActiveXObject("Microsoft.XMLHTTP"); 
	return http;
}

//fix me!
String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

function fillCertificationsList()
{
	document.body.style.cursor = "wait";
	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully 
		{
			document.body.style.cursor = "default";
			
			var ddCerts = document.getElementById('instant-pricing-certification');
			ddCerts.options.length = 1;

			var aSpecs = http.responseText.split('|');
			
			for (i = 0; i < aSpecs.length; i++)
			{
				p = aSpecs[i].split(',');
				$('#instant-pricing-certification').append($("<option></option>").attr("value", p[1]).text(p[0])); 
			}
			
			$("#instant-pricing-certification").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		}
	}
	sHost = window.location.host;
	var sUrl = "http://" + sHost + "/ajax/LanguagePairProvider." + ajax_ext + "?Cert=0&SiteLng=" + 
		$("#order-instant-pricing-language").val();
	http.open("GET", sUrl, true);
	http.send(null);
}

//fix me! We should use JSON
function fillSourceLangList()
{
	document.body.style.cursor = "wait";
	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully 
		{
			document.body.style.cursor = "default";

			var aLanguages = http.responseText.split('|');

			var topLangs = new Array()
			for (i = 0; i < aLanguages.length; i++)
			{
				p = aLanguages[i].split(','); //fix me! It should go to server side
				if (p[1] == 35 || p[1] == 37 || p[1] == 38 || p[1] == 40 || p[1] == 45 || p[1] == 82 || p[1] == 34 || p[1] == 44)
					topLangs[topLangs.length] = p;
			}
			
			if (topLangs.length > 0)
			{
				$('#instant-pricing-from').append($("<option></option>").attr("value",-1).text('----------------------')); 
				
				for (i = 0; i < topLangs.length; i++)
					$('#instant-pricing-from').append($("<option></option>").attr("value",topLangs[i][1]).text(topLangs[i][0])); 
				
				$('#instant-pricing-from').append($("<option></option>").attr("value",-1).text('----------------------')); 
			}
			
			for (i = 0; i < aLanguages.length; i++)
			{
				p = aLanguages[i].split(',');
				if(!p[0].startsWith("##"))
					$('#instant-pricing-from').append($("<option></option>").attr("value",p[1]).text(p[0])); 
			}
			
			$("#instant-pricing-from").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		}
	}
	sHost = window.location.host;
	var sUrl = "http://" + sHost + "/ajax/LanguagePairProvider." + ajax_ext + "?SiteLng=" + $("#order-instant-pricing-language").val();
	http.open("GET", sUrl, true);
	http.send(null);
}

function onSourceChanged()
{
	document.body.style.cursor = "wait";
	var ddSource = document.getElementById('instant-pricing-from');
	idSource = ddSource.options[ddSource.selectedIndex].value;
	if (idSource == '-1') return;

	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully 
		{
			document.body.style.cursor = "default";

			var ddTarget = document.getElementById('instant-pricing-to');
			var aLanguages = http.responseText.split('|');

			ddTarget.options.length = 1;
			
			if (aLanguages.length > 15)
			{
				var topLangs = new Array()
				for (i = 0; i < aLanguages.length; i++)
				{
					p = aLanguages[i].split(',');
					if (p[1] == 35 || p[1] == 37 || p[1] == 38 || p[1] == 40 || p[1] == 45 || p[1] == 82 || p[1] == 34 || p[1] == 44) 
						topLangs[topLangs.length] = new Option(p[0], p[1], true, false);
				}
				
				if (topLangs.length > 0)
				{
						var separator = new Option('----------------------', -1, false, false);
						separator.disabled = true;
						ddTarget.options[ddTarget.options.length] = separator;
						
						for (i = 0; i < topLangs.length; i++)
							ddTarget.options[ddTarget.options.length] = topLangs[i];
						
						separator = new Option('----------------------', -1, false, false);
						separator.disabled = true;
						ddTarget.options[ddTarget.options.length] = separator;
				}
			}

			for (i = 0; i < aLanguages.length; i++)
			{
				p = aLanguages[i].split(',');
				if(!p[0].startsWith("##"))
					ddTarget.options[ddTarget.options.length] = new Option(p[0], p[1], true, false);
			}
			$("#instant-pricing-to").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		}
	}
	sHost = window.location.host;
	http.open("GET", "http://" + sHost + "/ajax/LanguagePairProvider." + ajax_ext + "?FromLng=" + idSource + 
		"&SiteLng=" + $("#order-instant-pricing-language").val(), true);
	http.send(null);

	HideQuoteDetails();
}

function onTargetChanged()
{
	var ddSource = document.getElementById('instant-pricing-from');
	idSource = ddSource.options[ddSource.selectedIndex].value;
	if (idSource == '-1') return;

	var ddTarget = document.getElementById('instant-pricing-to');
	idTarget = ddTarget.options[ddTarget.selectedIndex].value;
	if (idTarget == '-1') return;
	
	document.body.style.cursor = "wait";
	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully 
		{
			document.body.style.cursor = "default";
			//http.responseText contains the response
			var aSpecialities = http.responseText.split('|');

			var ddSpeciality = document.getElementById('instant-pricing-doc-type');

			ddSpeciality.options.length = 1;

			for (i = 0; i < aSpecialities.length; i++)
			{
				p = aSpecialities[i].split(',');
				ddSpeciality.options[ddSpeciality.options.length] = new Option(p[0], p[1], true, false);
			}
			$("#instant-pricing-doc-type").styleSelect({styleClass: "selectLanguage",optionsWidth: 1,speed: 'fast'});
		}
	};

	sHost = window.location.host;
	http.open("GET", "http://" + sHost + "/ajax/LanguagePairProvider." + ajax_ext + "?FromLng=" + idSource + "&IntoLng=" + 
		idTarget + "&SiteLng=" + $("#order-instant-pricing-language").val(), true);
	http.send(null);

	HideQuoteDetails();
}

function onSpecChanged()
{
		var ddSpeciality = document.getElementById('instant-pricing-doc-type');
		fillCertificationsList();
		HideQuoteDetails();
		return;
}

function HideQuoteDetails()
{
	  	$('#instant-pricing-return').slideUp('fast', function() {
			// Animation complete.
		});
	  	$('#instant-pricing-return-manual').slideUp('fast', function() {
			// Animation complete.
		});
	  	$('#turnaround-note').slideUp('fast', function() {
			// Animation complete.
		});
		$('#email-this-quote').slideUp('fast', function() {
			// Animation complete.
		});
}

var bShow = false;
function onRegisterClick()
{
//	var secRegister = document.getElementById('register');		
	if (bShow)
		$("#register").slideUp('fast');
//		secRegister.style.display = 'none';
	else
		$("#register").slideDown('slow');
//		secRegister.style.display = 'block';
	
	bShow = !bShow;	
	return false;
}

function onReminderClick()
{
	//window.open('http://www.tm-stream.com/common/passwordReminder2.aspx','reminder','width=400,height=330'); 	
//	include('/js/contact.js');
//	include('/js/jquery.simplemodal.js');
	
	showReminderDialog();
	
	return false;
}
	
function sendEmailQuote()
{
	  source_lang = $("#instant-pricing-from").val();
	  source_text = $("#instant-pricing-from :selected").text();
		if (source_lang < 0) {
		  msgBox(global_message['warning_source_language']);
		  return false;
	  }

	  target_lang = $("#instant-pricing-to").val();
	  target_text = $("#instant-pricing-to :selected").text();
		if (target_lang < 0) {
		  msgBox(global_message['warning_target_language']);
		  return false;
	  }

	  doc_type = $("#instant-pricing-doc-type").val();
	  doc_text = $("#instant-pricing-doc-type :selected").text();
		if (doc_type < 0) {
		  msgBox(global_message['warning_doc_type']);
		  return false;
	  }

	  cert_type = $("#instant-pricing-certification").val();
	  cert_text = $("#instant-pricing-certification :selected").text();
		if (cert_type < 0) {
			cert_type = 0;
		  //msgBox(global_message['warning_certification']);
		  //return false;
	  }

	  word_count = $("#word-count").val();
		if (!IsNumeric(word_count) || word_count <= 0) {
			word_count = 1000;
		  word_count = $("#word-count").val(word_count);
	  }

	sTo = $('#email-this-quote-to').val();
	sCC = $('#email-this-quote-cc').val();
	if (sTo == "Send email to") sTo = "";
	if (sTo.length == 0)
	{
		msgBox(global_message['warning_email_address']);
		return;
	}
	if (sCC == "Send CC to") sCC = "";
	
	var doc_id = $('#order-instant-pricing-doc-id').val();
	
	document.body.style.cursor = "wait";
	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully 
		{
			document.body.style.cursor = "default";
			//http.responseText contains the response
			if (http.responseText == "ERROR")
			{
				msgBox(global_message['unexpected_error']);
				return;
			}
			else
			{
				msgBox(global_message['message_email_sent']);
				$('#email-this-quote').slideUp('fast', function() {
					// Animation complete.
				});
			}
		}

	};

	sHost = window.location.host;
	var cur = $('#order-instant-pricing-currency').val();
	http.open("GET", "http://" + sHost + "/ajax/QuoteActions." + ajax_ext + "?action=email&idCur=" + cur + "&idDoc=" + doc_id + 
		"&idSource=" + source_lang + "&idSpec=" + doc_type + "&idTarget=" + target_lang + "&idCert=" + cert_type + 
		"&WordCount=" + word_count + "&SiteLng=" + $("#order-instant-pricing-language").val() + "&Source=" + source_text + 
		"&Target=" + target_text + "&Spec=" + doc_text + "&Cert=" + cert_text + "&CC=" + sCC + "&To=" + sTo, true);
	http.send(null);
}

function onOrder()
{
	if ($("#order-instant-pricing-doc-id").val() <= 0)
	{
		msgBox(global_message['warning_source_file']);
		return;
	}
	
	var order_form = document.getElementById("order-now-form");
	//order_form.action = "http://localhost:2130/registration-and-place-order2.aspx";
	order_form.action = "http://www.tm-stream.com/registration-and-place-order2.aspx";
	order_form.target = "_self";
	order_form.submit();
}

function onCertChanged()
{
}

function msgBox(msg)
{
	$.prompt(msg);
	//alert(msg);
}

function login()
{
	try
	{
		var user_name = $('#edit-name').val();
		var password = $('#edit-pass').val();
		
		var userdetails = {id: -1, usertype: '', firstName: '', lastName: '', lastLogin: ''};
		
		$('body').css('cursor','wait');
		http = getHttpAjaxObject();
		http.onreadystatechange = function()	//handler function executated when the ready state is changed
		{
			if (http.readyState == 4)//HTTP request ended successfully 
			{
				document.body.style.cursor = "default";
				//http.responseText contains the response
				var aUserdetails = http.responseText.split('|');
				if (aUserdetails.length == 5)
				{
					userdetails.id = parseInt(aUserdetails[0]);
					userdetails.usertype = aUserdetails[1];
					/*if (userdetails.usertype == "administrator")
					{
						//window.location = "http://www.tm-stream.com/admin/admin.aspx";
					}*/
					if (userdetails.usertype == "translator")
					{
						var login_form = document.getElementById("user-login");
						login_form.action = "http://www.tm-stream.com/common/login.aspx?origin=2";
						login_form.target = "_self";
						login_form.submit();
                    	label = 'name: ' + aUserdetails[2] + '' + aUserdetails[3];
                    	//_gaq.push(['_trackEvent', 'Translator login', 'Get', label]);
					}
					else if (userdetails.usertype == "corporateClient")
					{
						var login_form = document.getElementById("user-login");
						login_form.action = "http://www.tm-stream.com/corporates/corporateLogon.aspx";
						login_form.target = "_self";
						login_form.submit();
                    	label = 'name: ' + aUserdetails[2] + '' + aUserdetails[3];
                    	//_gaq.push(['_trackEvent', 'Corporate client login', 'Get', label]);
					}
					else
					{
                    	label = 'name: ' + aUserdetails[2] + '' + aUserdetails[3];
                    	//_gaq.push(['_trackEvent', 'Client login', 'Get', label]);
					}

					userdetails.firstName = aUserdetails[2];
					userdetails.lastName = aUserdetails[3];
					userdetails.lastLogin = aUserdetails[4];
					
					$('#order-instant-pricing-user-id').val(aUserdetails[0]);
					showLoginDetails(userdetails);
					
					//save login detals
					var data = userdetails.id + '|' + userdetails.usertype + '|' + userdetails.firstName + '|' + userdetails.lastName + '|' + userdetails.lastLogin; 
					setCookie("userdetails", data);
				}
				else
				{
					msgBox(global_message['warning_incorrect_login']);
					$('#edit-name').val(global_message['username']);
					$('#edit-pass').val(global_message['password']);
				}
			}
		};
		sHost = window.location.host;
		http.open("POST", "http://" + sHost + "/ajax/QuoteActions." + ajax_ext + "?action=LoginUser", true);
		var sParam = "UserName=" + user_name.replace("=", "#`'#") + "&Password=" + escape(password.replace("=", "#`'#"));
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", sParam.length);
		http.setRequestHeader("Connection", "close");
		http.send(sParam);

	}
	catch(err)
	{
		alert(err);
	}
}

function showLoginDetails(userdetails)
{
	$('.login').hide();
	$('.tools').hide();
	$('#login').css('background-image', 'url("")');
	$('#logout').show();
	$('#form-up').css('background-image', 'url("http://www.translatemedia.com/wp-content/themes/translatemedia/img/form-up-right-fond.png")');
	$('#userdetails').html('Welcome back ' + userdetails.firstName + ' ' + userdetails.lastName + ' Last login ' + 
		'<b>' + userdetails.lastLogin + '</b>');
}

function logout()
{
	$('#login').show();
	$('#logout').hide();
	$('#login').css('background-image', 'url("http://www.translatemedia.com/wp-content/themes/translatemedia/img/login-background.png")');
	$('.login').show();
	$('.tools').show();
	$('#userdetails').html('');
	$('#order-instant-pricing-user-id').val(-1);
	deleteCookie('userdetails');
}

function getCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
/* ####################### end get cookie value ####################### */
}

function setCookie(name, value, expires, path, domain, secure) {


  var thisCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = thisCookie;
}

function deleteCookie(name, path, domain)
{
	document.cookie = name + "=" +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function getUserdetails()
{
	try
	{
		var userdetailsCookie = getCookie('userdetails');
		var userdetails = {id: "", usertype: "", firstName: "", lastname: "", lastLogin: ""};
		var aUserDetails = userdetailsCookie.split('|');
		
		userdetails.id = aUserDetails[0];
		userdetails.usertype = aUserDetails[1];
		userdetails.firstName = aUserDetails[2];
		userdetails.lastName = aUserDetails[3];
		userdetails.lastLogin = aUserDetails[4];
		$('#order-instant-pricing-user-id').val(aUserDetails[0]);

		if (userdetails.id > 0)
			showLoginDetails(userdetails);
	}
	catch(err)
	{
		return null;
	}
}

function onContactRequest()
{
	sName = $('#request-contact-form-name').val();
	if (sName.length == 0 || sName==global_message['name'])
	{
		msgBox(global_message['enter_your_name']);
		$('#request-contact-form-name').focus();
		return;
	}
	sPhone = $('#request-contact-form-phone').val();
	if (sName.length == 0 || sPhone==global_message['phone'])
	{
		msgBox(global_message[enter_your_phone_number]);
		document.getElementById('#request-contact-form-phone').focus();
		return;
	}
	sEmail = $('#request-contact-form-mail').val();
	if (sEmail.length == 0 || sEmail==global_message['email'])
	{
		msgBox(global_message[enter_your_email_address]);
		document.getElementById('#request-contact-form-mail').focus();
		return;
	}
	sMessage = $('#request-contact-form-message').val();
	if (sMessage.length == 0 || sMessage == global_message['message'])
	{
		msgBox(global_message['enter_your_message']);
		document.getElementById('#request-contact-form-message').focus();
		return;
	}
	
	document.body.style.cursor = "wait";
	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully
		{
			document.body.style.cursor = "default";

			var aResult = http.responseText.split('^');

			if (aResult[0] == "OK")
			{
				$('#corps-central-form-1').css('background-image', 'url("http://www.translatemedia.com/wp-content/themes/translatemedia/img/form-central-request-contact-empty.png")');
				$('#corps-central-form-1').html('<div class=\'request-response\'>' + global_message['getting_touch'] + 
					'</div> <div class=\'request-response\'>' + global_message['expert_reply'] + '</div><div class=\'request-response\'>' +
					global_message['faster_response'] + '<span id="lblTel"></div>');
				$('#lblTel').html(aResult[1]);
				return;
			}
			else
				msgBox(global_message['contact_request_failure']);
			return;
		}
	};

	label = 'name: ' + sName + ' email: ' + sEmail;
	//_gaq.push(['_trackEvent', 'Request contact', 'Get', label]);

	sHost = window.location.host;
	http.open("POST", "http://" + sHost + "/ajax/QuoteActions." + ajax_ext + "?action=ContactRequest", true);
	var sParam = "name=" + sName.replace("=", "#`'#") + "&email=" + sEmail.replace("=", "#`'#");
	sParam += "&phone=" + sPhone.replace("=", "#`'#") + "&message=" + sMessage.replace("=", "#`'#");
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", sParam.length);
	http.setRequestHeader("Connection", "close");
	http.send(sParam);
}

function viewCertification(siteLang)
{
	win = window.open("http://www.tm-stream.com/public/certification2.aspx?lng="+siteLang,
		'Certification','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=650, height=600');
	win.focus();
}

function loadHTMLContentArea(url)
{
	try
	{
		http=getHttpAjaxObject();
		http.onreadystatechange=function()
		{ 
			if(http.readyState == 4)
			{
				var content = http.responseText;
				if (content.indexOf("<title>Error</title>") < 0)
				{
					var start = content.indexOf("<div id=\"contentarea\"") + 40;
					var end = content.indexOf("<!-- End of contentarea -->") - 8;
					document.getElementById('contentarea').innerHTML = content.substring(start, end); 
				}
			} 
		}; 
	
		http.open("GET", url , true);
		http.send(null);
	}
	catch(err)
	{
		alert(err);
	}
}

function getManualQuote()
{
	sName = $('#order-request-name').val();
	if (sName.length == 0 || sName==global_message['name'])
	{
		msgBox(global_message['enter_your_name']);
		$('#order-request-name').focus();
		return;
	}
	sPhone = $('#order-request-phone').val();
	if (sName.length == 0 || sPhone==global_message['phone'])
	{
		msgBox(global_message['enter_your_phone']);
		document.getElementById('#order-request-phone').focus();
		return;
	}
	sEmail = $('#order-request-mail').val();
	if (sEmail.length == 0 || sEmail==global_message['email'])
	{
		msgBox(global_message['enter_your_email']);
		document.getElementById('#order-request-mail').focus();
		return;
	}
	sMessage = $('#request-quote-message').val();
	if (sMessage.length == 0 || sMessage==global_message['message'])
	{
		msgBox(global_message['enter_your_message']);
		document.getElementById('#request-quote-message').focus();
		return;
	}
	
	document.body.style.cursor = "wait";
	http = getHttpAjaxObject();
	http.onreadystatechange = function()	//handler function executated when the ready state is changed
	{
		if (http.readyState == 4)//HTTP request ended successfully
		{
			document.body.style.cursor = "default";

			var aResult = http.responseText.split('^');

			if (aResult[0] == "OK")
			{
				msgBox(global_message['getting_touch'] + ' ' + global_message['expert_reply'] + ' ' + global_message['faster_response'] + ' ' +
					global_message['office_phone']);
				return;
			}
			else
				msgBox(global_message['quote_request_failure']);
			return;
		}
	};

	label = 'name: ' + sName + ' email: ' + sEmail;
	//_gaq.push(['_trackEvent', 'Request manual quote', 'Get', label]);

	source_lang = $("#instant-pricing-from").val();
  target_lang = $("#instant-pricing-to").val();
  doc_type = $("#instant-pricing-doc-type").val();
  certification = $("#instant-pricing-certification").val();
	doc_id = $('#order-instant-pricing-doc-id').val();

	sHost = window.location.host;
	http.open("POST", "http://" + sHost + "/ajax/QuoteActions." + ajax_ext + "?action=QuoteRequest", true);
	var sParam = "name=" + sName.replace("=", "#`'#") + "&email=" + sEmail.replace("=", "#`'#");
	sParam += "&phone=" + sPhone.replace("=", "#`'#") + "&message=" + sMessage.replace("=", "#`'#");
	sParam += "&idSource=" + source_lang + "&idSpec=" + doc_type + "&idTarget=" + target_lang+ "&idCert=" + certification;
	sParam += "&idDoc=" + doc_id;

	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", sParam.length);
	http.setRequestHeader("Connection", "close");
	http.send(sParam);
}

/*
 * jQuery Impromptu
 * By: Trent Richardson [http://trentrichardson.com]
 * Version 3.1
 * Last Modified: 3/30/2010
 * 
 * Copyright 2010 Trent Richardson
 * Dual licensed under the MIT and GPL licenses.
 * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
 * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
 * 
 */
(function($){$.prompt=function(message,options){options=$.extend({},$.prompt.defaults,options);$.prompt.currentPrefix=options.prefix;var ie6=($.browser.msie&&$.browser.version<7);var $body=$(document.body);var $window=$(window);options.classes=$.trim(options.classes);if(options.classes!='')options.classes=' '+options.classes;var msgbox='<div class="'+options.prefix+'box'+options.classes+'" id="'+options.prefix+'box">';if(options.useiframe&&(($('object, applet').length>0)||ie6)){msgbox+='<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+options.prefix+'fade" id="'+options.prefix+'fade"></iframe>';}else{if(ie6){$('select').css('visibility','hidden');}msgbox+='<div class="'+options.prefix+'fade" id="'+options.prefix+'fade"></div>';}msgbox+='<div class="'+options.prefix+'" id="'+options.prefix+'"><div class="'+options.prefix+'container"><div class="';msgbox+=options.prefix+'close">X</div><div id="'+options.prefix+'states"></div>';msgbox+='</div></div></div>';var $jqib=$(msgbox).appendTo($body);var $jqi=$jqib.children('#'+options.prefix);var $jqif=$jqib.children('#'+options.prefix+'fade');if(message.constructor==String){message={state0:{html:message,buttons:options.buttons,focus:options.focus,submit:options.submit}};}var states="";$.each(message,function(statename,stateobj){stateobj=$.extend({},$.prompt.defaults.state,stateobj);message[statename]=stateobj;states+='<div id="'+options.prefix+'_state_'+statename+'" class="'+options.prefix+'_state" style="display:none;"><div class="'+options.prefix+'message">'+stateobj.html+'</div><div class="'+options.prefix+'buttons">';$.each(stateobj.buttons,function(k,v){if(typeof v=='object')states+='<button name="'+options.prefix+'_'+statename+'_button'+v.title.replace(/[^a-z0-9]+/gi,'')+'" id="'+options.prefix+'_'+statename+'_button'+v.title.replace(/[^a-z0-9]+/gi,'')+'" value="'+v.value+'">'+v.title+'</button>';else states+='<button name="'+options.prefix+'_'+statename+'_button'+k+'" id="'+options.prefix+'_'+statename+'_button'+k+'" value="'+v+'">'+k+'</button>';});states+='</div></div>';});$jqi.find('#'+options.prefix+'states').html(states).children('.'+options.prefix+'_state:first').css('display','block');$jqi.find('.'+options.prefix+'buttons:empty').css('display','none');$.each(message,function(statename,stateobj){var $state=$jqi.find('#'+options.prefix+'_state_'+statename);$state.children('.'+options.prefix+'buttons').children('button').click(function(){var msg=$state.children('.'+options.prefix+'message');var clicked=stateobj.buttons[$(this).text()];if(clicked==undefined){for(var i in stateobj.buttons)if(stateobj.buttons[i].title==$(this).text())clicked=stateobj.buttons[i].value;}if(typeof clicked=='object')clicked=clicked.value;var forminputs={};$.each($jqi.find('#'+options.prefix+'states :input').serializeArray(),function(i,obj){if(forminputs[obj.name]===undefined){forminputs[obj.name]=obj.value;}else if(typeof forminputs[obj.name]==Array||typeof forminputs[obj.name]=='object'){forminputs[obj.name].push(obj.value);}else{forminputs[obj.name]=[forminputs[obj.name],obj.value];}});var close=stateobj.submit(clicked,msg,forminputs);if(close===undefined||close){removePrompt(true,clicked,msg,forminputs);}});$state.find('.'+options.prefix+'buttons button:eq('+stateobj.focus+')').addClass(options.prefix+'defaultbutton');});var ie6scroll=function(){$jqib.css({top:$window.scrollTop()});};var fadeClicked=function(){if(options.persistent){var i=0;$jqib.addClass(options.prefix+'warning');var intervalid=setInterval(function(){$jqib.toggleClass(options.prefix+'warning');if(i++>1){clearInterval(intervalid);$jqib.removeClass(options.prefix+'warning');}},100);}else{removePrompt();}};var keyPressEventHandler=function(e){var key=(window.event)?event.keyCode:e.keyCode;if(key==27){fadeClicked();}if(key==9){var $inputels=$(':input:enabled:visible',$jqib);var fwd=!e.shiftKey&&e.target==$inputels[$inputels.length-1];var back=e.shiftKey&&e.target==$inputels[0];if(fwd||back){setTimeout(function(){if(!$inputels)return;var el=$inputels[back===true?$inputels.length-1:0];if(el)el.focus();},10);return false;}}};var positionPrompt=function(){$jqib.css({position:(ie6)?"absolute":"fixed",height:$window.height(),width:"100%",top:(ie6)?$window.scrollTop():0,left:0,right:0,bottom:0});$jqif.css({position:"absolute",height:$window.height(),width:"100%",top:0,left:0,right:0,bottom:0});$jqi.css({position:"absolute",top:options.top,left:"50%",marginLeft:(($jqi.outerWidth()/2)*-1)});};var stylePrompt=function(){$jqif.css({zIndex:options.zIndex,display:"none",opacity:options.opacity});$jqi.css({zIndex:options.zIndex+1,display:"none"});$jqib.css({zIndex:options.zIndex});};var removePrompt=function(callCallback,clicked,msg,formvals){$jqi.remove();if(ie6){$body.unbind('scroll',ie6scroll);}$window.unbind('resize',positionPrompt);$jqif.fadeOut(options.overlayspeed,function(){$jqif.unbind('click',fadeClicked);$jqif.remove();if(callCallback){options.callback(clicked,msg,formvals);}$jqib.unbind('keypress',keyPressEventHandler);$jqib.remove();if(ie6&&!options.useiframe){$('select').css('visibility','visible');}});};positionPrompt();stylePrompt();if(ie6){$window.scroll(ie6scroll);}$jqif.click(fadeClicked);$window.resize(positionPrompt);$jqib.bind("keydown keypress",keyPressEventHandler);$jqi.find('.'+options.prefix+'close').click(removePrompt);$jqif.fadeIn(options.overlayspeed);$jqi[options.show](options.promptspeed,options.loaded);$jqi.find('#'+options.prefix+'states .'+options.prefix+'_state:first .'+options.prefix+'defaultbutton').focus();if(options.timeout>0)setTimeout($.prompt.close,options.timeout);return $jqib;};$.prompt.defaults={prefix:'jqi',classes:'',buttons:{Ok:true},loaded:function(){},submit:function(){return true;},callback:function(){},opacity:0.6,zIndex:999,overlayspeed:'slow',promptspeed:'fast',show:'fadeIn',focus:0,useiframe:false,top:"15%",persistent:true,timeout:0,state:{html:'',buttons:{Ok:true},focus:0,submit:function(){return true;}}};$.prompt.currentPrefix=$.prompt.defaults.prefix;$.prompt.setDefaults=function(o){$.prompt.defaults=$.extend({},$.prompt.defaults,o);};$.prompt.setStateDefaults=function(o){$.prompt.defaults.state=$.extend({},$.prompt.defaults.state,o);};$.prompt.getStateContent=function(state){return $('#'+$.prompt.currentPrefix+'_state_'+state);};$.prompt.getCurrentState=function(){return $('.'+$.prompt.currentPrefix+'_state:visible');};$.prompt.getCurrentStateName=function(){var stateid=$.prompt.getCurrentState().attr('id');return stateid.replace($.prompt.currentPrefix+'_state_','');};$.prompt.goToState=function(state,callback){$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$('#'+$.prompt.currentPrefix+'_state_'+state).slideDown('slow',function(){$(this).find('.'+$.prompt.currentPrefix+'defaultbutton').focus();if(typeof callback=='function')callback();});};$.prompt.nextState=function(callback){var $next=$('.'+$.prompt.currentPrefix+'_state:visible').next();$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$next.slideDown('slow',function(){$next.find('.'+$.prompt.currentPrefix+'defaultbutton').focus();if(typeof callback=='function')callback();});};$.prompt.prevState=function(callback){var $next=$('.'+$.prompt.currentPrefix+'_state:visible').prev();$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$next.slideDown('slow',function(){$next.find('.'+$.prompt.currentPrefix+'defaultbutton').focus();if(typeof callback=='function')callback();});};$.prompt.close=function(){$('#'+$.prompt.currentPrefix+'box').fadeOut('fast',function(){$(this).remove();});};$.fn.prompt=function(options){if(options==undefined)options={};if(options.withDataAndEvents==undefined)options.withDataAndEvents=false;$.prompt($(this).clone(options.withDataAndEvents).html(),options);}})(jQuery);


function SetPhoneNumber()
{
	try
	{
		httpFN = getHttpAjaxObject();
		httpFN.onreadystatechange = function()	//handler function executated when the ready state is changed
		{
			if (httpFN.readyState == 4)//HTTP request ended successfully 
			{
				$(".tel").text(httpFN.responseText);
			}
		}

		sHost = window.location.host;
		httpFN.open("GET", "http://" + sHost + "/ajax/QuoteActions." + ajax_ext + "?action=tel", true);
		httpFN.send(null);
	}
	catch(err)
	{
		alert("ERROR "+err);
		return false;
	}
	
	return false;
}

function loadFeedback() {
    $("body").css("cursor", "wait");
    var sParam = window.location.search.substring(1);
    $.ajax({
        type: "POST",
        url: "/ajax/WebsiteActions.php?" + sParam,
        async: true,
        data: "action=GetFeedbackInfo",
        success: function(responseText, statusText, xhr, $form) {
        	var oFeedback = eval(responseText);
        	$("#tdJobref").text(oFeedback.sReference);
        	$("#tdDesc").text(oFeedback.sDescription);
        	$("#tdSubmitDate").text(oFeedback.sSubmit);
        	$("#tdOrigFilename").text(oFeedback.sOriginalFileName);
        	$("#tdProjManager").html(oFeedback.sPMName + "<br/>" + oFeedback.sPMEmail);
        	if (oFeedback.byThumb >= 0 && oFeedback.byThumb <=4 )
						$('input[@name="rating"]')[oFeedback.byThumb].checked;
					$('#txtComment').text(oFeedback.sComment);
					$("#wholeOrder").checked(true);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert(textStatus);
        },
        complete: function(jqXHR, textStatus) {

        		$("#formFeedback").show();
        		$("#lblMessage").hide();
            $("body").css("cursor", "auto");
        }
    });
}

function submitFeedback() {
    $("body").css("cursor", "wait");
    var rate = $('input:radio[name=rating]:checked').val();
    var comment = $('#comment').val();
    var wholeOrder = $('#wholeOrder').is(':checked');
    var sParam = window.location.search.substring(1);
    var sPMEmail = "email";
    var sRef =$("#tdJobref").text();
    $.ajax({
        type: "POST",
        //url: "/ajax/WebsiteActions.php?" + sParam,
        url: "http://localhost:3369/ajax/NewSiteActions.aspx?" + sParam,
        async: true,
        data:  "&action=SetFeedbackInfo&thumb=" + rate + "&comment=" + comment + "&PMEmail=" + sPMEmail + "&wholeOrder=" + wholeOrder + "&reference" + sRef,
        success: function(responseText, statusText, xhr, $form) {
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert(textStatus);
        },
        complete: function(jqXHR, textStatus) {
        		$("#formFeedback").hide();
        		$("#lblMessage").show();
            $("body").css("cursor", "auto");
        }
    });
}

function showRequestContact()
{
	$('#light').show();
	$('#fade').show();
	$('#form-central-layer2').append($('#form-central'));
	$(".tabs-central").css({visibility:"hidden"});
	//document.getElementById('light').style.display='block';
	//document.getElementById('fade').style.display='block';
}

function closeRequestContact()
{
	document.getElementById('light').style.display='none';
	document.getElementById('fade').style.display='none';
	//send the contact request section back
	$('#form-central-layer1').append($('#form-central'));
	$(".tabs-central").css({visibility:"visible"});
}

