/* 
* 
*	
*/

jQuery(document).ready(function() {
	  jQuery('.iTE1').cluetip({
		  activation: 'click',
		  local: true, 
	   	  leftOffset: -30,
	   	  topOffset: 15,
		  sticky: true,
		  width: 250,
		  onShow: function(ct, c) {
			jQuery('.bgiframe').remove();
			$('cluetip-title').update( $('cluetip-close') );
		  }	
	 });
	 
	   jQuery('tr.TEbutton').cluetip({
		  activation: 'click',
		  local: true, 
	   	  leftOffset: -150,
	   	  topOffset: 15,
		  sticky: true,
		  width: 280,
		  onShow: function(ct, c) {
			jQuery('.bgiframe').remove();
		  }				
	 });
});

function prepareFormsLayer() {

		// set layer to right size
//		I.E. Bug - what else		
//		$('layer-content').setStyle({
//								margin: 	'12px 0 12px 30px',
//								padding: 	'0 0 20px 12px',
//								width: 		'625px',
//								background: '#ffffff'
//							});
		$('layer-content').style.margin ='12px 0 12px 30px';
		$('layer-content').style.width ='624px';
		$('layer-content').style.background ='#ffffff';
		// this funny right-padding/right-margin stuff 
		// together with display:inline is neede for IE6
		$('layer-content').style.padding ='0 12px 20px 12px';
		$('layer-close').style.marginRight = '-12px';
		$('layer-close').style.display = 'inline';
							
		$('layer-header').update();					
		$('layer-body').update('<div id="layer-body-wait" align="center"><img style="padding:40px; display: block;" src="/siemens/images/doclib/ajax-loader.gif"/></div>');					

		// fix I.E 6 Bug
		jQuery('#layer-zone').bgiframe();		
		
		jQuery('#layer-zone').fadeIn(500);
}		

function showForms( URL, type ) {	
	
		prepareFormsLayer();				
		
		// and now some ajax
		new Ajax.Request( URL, { 
				method:'post',
				onFailure: function(){
				}, 
				onSuccess: function(transport) {
					$('layer-body').removeChild($('layer-body-wait'));
					var _div = document.createElement('div');
					    _div.setAttribute('id', 'layer-body-content');
					    _div.setAttribute('style', 'display: none;');
					    _div.innerHTML = transport.responseText;
	    
					
					//We need to use jQuery append, because 
					//prototype's appendChild does not execute 
					//javascript in the html to append: 
					//$('layer-body').appendChild(_div);
					jQuery('#layer-body').append(_div);
					
					jQuery('#layer-body-content').slideDown(500, function(){
					  	$('layer-form').removeClassName('opaque10');
					 });
					
				},
				onComplete: function() {
					prepareLayerScript ( type );				
				}
		});
}

function prepareLayerScript( type ) {

	jQuery($('F81')).ready(function(){
			jQuery('a.iF81').cluetip({
				  activation: 'click',
			   	  dropShadow: false,
			   	  local: true,
			   	  topOffset: 20,
			   	  leftOffset: -20,
				  sticky: true,
				  width: 280,
				  onShow: function(ct, c){
				  	jQuery('.bgiframe').remove();
				  	jQuery('#layer-zone').bgiframe();
				  	jQuery('#cluetip').bgiframe({opacity: false, src: '/siemens/images/nav/c.gif'});
				  	showOptionInfo( c );
				  }
			});
	});	
	
	// trim the f81 entries 
	jQuery($('F81')).ready(function(){	
		size_textfield();
	});
	
	jQuery($('E84')).ready(function(){	
			jQuery('a.iE84').cluetip({
				  activation: 'click',
			   	  dropShadow: false,
			   	  local: true,
			   	  cursor: 'help',
				  sticky: true,
				  width: 280,
				  fx: {             
							open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
							openSpeed:  '500'
				  },			      
			      onShow: function(ct, c) {
			      			jQuery('.bgiframe').remove();
				  			jQuery('#layer-zone').bgiframe();
				  			jQuery('#cluetip').bgiframe({opacity: false, src: '/siemens/images/nav/c.gif'});
				  			$('cluetip-title').update( $('cluetip-close') );
				  			var inputsClueTip = $('cluetip-inner').select('input', 'select');
				  			var inputsE84tt = $('e84tt').select('input', 'select');
						for (j = 0; j < inputsClueTip.length; j++) {
							if (inputsClueTip[j].name == 'state')
								inputsClueTip[j].selectedIndex = inputsE84tt[j].selectedIndex;
							else
								inputsClueTip[j].value = inputsE84tt[j].value;
							inputsClueTip[j].enable();
						}
				  }
			});
	});
			
	// disable the form
	// if there are no entries in F81
	jQuery($('#submitFormButton')).ready(function(){
		if ($('f81entries').value == '0') {
			if (type == 'quote')
				$('quote').disable();
			else
				$('try').disable();
			// disable Info Icons
			jQuery('a.iE84').replaceWith('<span class="tooltip_info">&nbsp;</span>');
			jQuery('a.iF82').replaceWith('<span class="tooltip_info">&nbsp;</span>');
			jQuery('span.f82calendar a').remove();
			jQuery('a.iE85').replaceWith('<span class="tooltip_info">&nbsp;</span>');
			jQuery('#e85add_user').remove();
			jQuery('a.link_tac').replaceWith(jQuery('a.link_tac').text());
			jQuery('a.iF87').replaceWith('<span class="tooltip_info">&nbsp;</span>');
			$('submitFormButton').remove();
			return;
		}	
	});
	if( type == 'try') {

		/* F82 */	
		jQuery($('F82')).ready(function(){
			jQuery('#installDate').datepicker({
					changeYear: false,
					dateFormat: setDateFormat(),
					minDate: getNonRemoteMinDate()
			});
			// show minDate in input field
			var minDate = jQuery('#installDate').datepicker('getDate');
			jQuery('#installDate').val(jQuery.datepicker.formatDate(setDateFormat(), minDate));
			jQuery('a.iF82').cluetip({
					activation: 'click',
					dropShadow: false,
					local: true,
					topOffset: -100,
					cursor: 'help',
					sticky: true,
					width: 280,
					fx: {             
						open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
						openSpeed:  '500'
					},
					onActivate: function(e) {
						    jQuery('#_siteId').val($('siteId').value);
							return true;
					},
					onShow: function(ct, c) {
							jQuery('.bgiframe').remove();
				  			jQuery('#layer-zone').bgiframe();
				  			jQuery('#cluetip').bgiframe({opacity: false, src: '/siemens/images/nav/c.gif'});
							$('cluetip-title').update( $('cluetip-close') );
					}
			});
		});

		
		/* E85 */
		jQuery($('E85')).ready(function(){
				jQuery('a.iE85').cluetip({
					  activation: 'click',
				   	  dropShadow: false,
				   	  local: true,
				   	  topOffset: -50,
				   	  cursor: 'help',
					  sticky: true,
					  width: 195,
				      fx: {             
								open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
								openSpeed:  '500'
					  },
				      onShow: function(ct, c){
				      		jQuery('.bgiframe').remove();
				  			jQuery('#layer-zone').bgiframe();
				  			jQuery('#cluetip').bgiframe({opacity: false, src: '/siemens/images/nav/c.gif'});
					  		$('cluetip-title').update( $('cluetip-close') );
					  }
				});
		});
		/* E86 */
		jQuery($('E86')).ready(function(){
			jQuery('#e86Option2').cluetip({
				  activation: 'click',
			   	  dropShadow: false,
			   	  local: true,
			   	  attribute: 'alt',
			   	  cursor: 'help',
				  sticky: true,
				  width: 280,
				  fx: {             
							open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
							openSpeed:  '500'
				  },	      
			      onShow: function(ct, c) {
			       		jQuery('.bgiframe').remove();
				  		jQuery('#layer-zone').bgiframe();
				  		jQuery('#cluetip').bgiframe({opacity: false, src: '/siemens/images/nav/c.gif'});
				  		$('cluetip-title').update( $('cluetip-close') );
				  	
				  	updateE86Input();
				  	var inputsClueTip = $('cluetip-inner').select('input', 'select');
				  	var inputsE86tt = $('e86tt').select('input', 'select');
					for (j = 0; j < inputsClueTip.length; j++) {
						if (inputsClueTip[j].name == 'state')
							inputsClueTip[j].selectedIndex = inputsE86tt[j].selectedIndex;
						else
							inputsClueTip[j].value = inputsE86tt[j].value;
						inputsClueTip[j].enable();
					}
				  }
			});
		});
				
		/* F87 */
		jQuery($('F87')).ready(function(){
				jQuery('a.iF87').cluetip({
						activation: 'hover',
						dropShadow: false,
						local: true,
						cursor: 'help',
						width: 195,
						sticky: true,
						hoverIntent: { 
							sensitivity: 3,   
							interval: 20
						},
						fx: {             
							open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
							openSpeed:  '500'
						},
						onShow: function(ct, c) {
							jQuery('.bgiframe').remove();
				  			jQuery('#layer-zone').bgiframe();
				  			jQuery('#cluetip').bgiframe({opacity: false, src: '/siemens/images/nav/c.gif'});
				  			$('cluetip-title').update( $('cluetip-close') );
						}
				});
		});
	}
}	

/* F81 */		
function showOptionInfo( c ) {	
		var url = c.get(0).firstChild.innerHTML;


   		url = url.replace(/&amp;/g, "&");
	  	url = url.replace(/<[^>]+>/g, "");
	  	
	  	var l = $('cluetip').getStyle('left');
	  	var t = $('cluetip').getStyle('top');
  		
  		$('cluetip').toggle();
  		$('cluetip-title').update( $('cluetip-close') );
  		$('cluetip-waitimage').setStyle({
				  left: l,
				  top: t
		});
		
		if(url.length != 0) {
	  		$('cluetip-waitimage').show();
			  		
			new Ajax.Request( url, { 
	                    	method:'get',
	                    	onFailure: function(){
	                     	}, 
							onSuccess: function( request ) {
						  		$('cluetip').toggle();
								$('cluetip-inner').update( request.responseText );
							},
							onComplete: function() {
								$('cluetip-waitimage').hide();
							}	
	  		});
		}
}		

function size_textfield() {

		// well, this is hardcoded ...
		var e = $$('label.f81Options_label');
			e.each(function(index, item ) {
	 		if (item.offsetWidth > 140) {
				var name = item.innerHTML;

				while (item.offsetWidth > 130) {
					var name_length = name.length;
					name = name.substring(0, (name_length-2));
					item.innerHTML = name;
				}
				item.innerHTML = name + '...';
			}	
	 	});
}

/* F81 trial */
function f81_countSelectedItems( checkbox ) {
		if ($('f81type').value == 'TRY') {
		 	var c = 0;
		 	var e = $$('input.f81checkbox');
		 	e.each(function(index, item )  {
		 		if (item.checked == true) {
					c++;
				}
		 	});
		 	
			if (c > $('f81max').value ) {
	
				jQuery.popup.show( $('f81maxSelectedMsg').value );
				checkbox.checked = false;
				checkbox.focus();
			}
		}			
}

/* F81 error */
function f81highlightError() {
		var labels = $$('label.f81Options_label');
		// fiction ...
//	 	l.each(function(index, item )  {
//				item.addClassName('errorText');
//	 	});
		// ... and (i.e.) reality
	 	for (i = 0; i < labels.length; i++) {
				var item = labels[i];
				var c = item.className;
				item.className = c + ' errorText';
		}
		var inputs = $$('inputs.f81checkbox');
	 	for (i = 0; i < inputs.length; i++) {
				var item = inputs[i];
				var c = item.className;
				item.className = c + ' errorHighlight';
		}
}	

/* F81 confirm */
function f81_queryForVideo( URL, productId ) {
			
	URL += 'productId=' + productId;
	URL += '&video=' + 1;

	new Ajax.Request( URL , {
					onSuccess: function(transport){
						var response = transport.responseText;
						if (response.search(/true/) != -1) {
							showVideoLink( productId );
						}	
					}
	});						
}

function f81_showVideoLink( productId ) {
	jQuery('#f81_video_' + productId).fadeIn(100);
}
		
/* F82 */
function setDateFormat() {
	var cDateFormat = $('installDate').value;
	if (cDateFormat.search(/YYYY/) != -1) {
		var cDateFormat = cDateFormat.replace(/YYYY/, "YY");			
	}
	return cDateFormat.toLowerCase();
	
}		
function getNonRemoteMinDate() {
	var minDate = parseInt($('f82_webservice_nonremote_mindate').value);
	if (minDate < 1)
		minDate = 10;

	var w = 0;
	
	var d = new Date()
	var c = d.getDay();

	if (minDate > 4) {
		w = parseInt(minDate/5);
		minDate = w*2+minDate;
		if (c == 0)
			minDate = 1+minDate;
		if (c == 6)
			minDate = 2+minDate;	
	} 
	else {
		if (c == 0)
			minDate = 1+minDate;
		if (c+minDate > 5)	
			minDate = 2+minDate;
	}
	return "+" + minDate;	
}

function setNonRemoteMinDate() {
	var minDate = getNonRemoteMinDate();
	jQuery('#installDate').datepicker('option', 'minDate', minDate );	

}	

function setRemoteMinDate() {
	var minDate = parseInt($('f82_webservice_remote_mindate').value);
	if (minDate < 1)
		minDate = 3;
		
	var w = 0;
	
	var d = new Date()
	var c = d.getDay();

	if (minDate > 5) {
		w = parseInt(minDate/5);
		minDate = w*2+minDate;
	} else {
		if (c == 0)
			minDate = 1+minDate;
		if (c+minDate > 5)	
			minDate = 2+minDate;
	}
	
	jQuery('#installDate').datepicker('option', 'minDate', "+" + minDate );

}

function showDatepicker() {
	jQuery('#installDate').datepicker('show');
}

function querySiteId(){
	// prepare query string
	var skip = 0;
	var inputs = $('cluetip-inner').getElementsByTagName("input");
	for (j = 0; j < inputs.length; j++) {
	 	if (! inputs[j].value ) {
	 		jQuery.popup.show( $('f82_webservice_error_empty_id').value );
	 		skip++;
	 	}	
	} 	
	var queryString = getQueryString();
	if (jQuery('#_siteIdPrefix').length > 0){
	    	queryString += "&location=" + jQuery('#cluetip-inner input:first').val()  + "-" + jQuery('#cluetip-inner input:last').val();
	} else {
	    	queryString += "&serialNumber=" + jQuery('#cluetip-inner input:last').val() + "&systemId=" + jQuery('input:hidden[name="systemId"]').val();
	}
	if (!skip) {
	    var f82SiteId = jQuery('#cluetip-inner input:last').val();
		new Ajax.Request( 'SMCMDBRemoteServiceCheckView?' + queryString, {
				method:'get',
				onLoading: function(){
				},
				onSuccess: function(transport){
					var response = jQuery(transport.responseText);
					var result = response.attr('id');
					
					if (result == 'true') {
						$('cluetip-inner').update( response.html() );
						$('hasRemoteInstall').value = 'yes';
						setRemoteMinDate();
						// update siteId in E84 module
						$('siteId').value = f82SiteId;
					}	
					if (result == 'false') {
						$('cluetip-inner').update( response.html() );
						$('hasRemoteInstall').value = 'no';
						setNonRemoteMinDate();
						// update siteId in E84 module
						$('siteId').value = f82SiteId;
					}
					if (result == 'failure' || result == 'error') {
						jQuery.popup.show(response.html());
					}
				},
				onFailure: function(){ 	
						jQuery.popup.show( $('f82_webservice_response_error').value );
				}
			});
	}	
}	

/* E84 */
function closeE84tt() {
	var inputsClueTip = $('cluetip-inner').select('input', 'select');
	var inputsE84tt = $('e84tt').select('input', 'select');
	//alert($('zipFormat').innerHTML);
	var zipFormat = new RegExp($('zipFormat').innerHTML, 'g');
	var isOK = true;
	
	$w($('validationRule').innerHTML).each(function validateInputField(fieldName){
			//alert("fieldName: " + fieldName);
			var field = $('cluetip-inner').select('[name=' + fieldName + ']');
			var label = $('cluetip-inner').select('[for=' + fieldName + ']');
			if (field[0].value.length === 0){
				field[0].addClassName('errorHighlight');
				label[0].addClassName('errorText');
				isOK = false;
			} else {
				field[0].removeClassName('errorHighlight');
				label[0].removeClassName('errorText');
			}
			// validate zip code
			if (field[0].name == 'zipCode' && zipFormat.test(field[0].value)){
				//alert(field[0].value);
				field[0].addClassName('errorHighlight');
				label[0].addClassName('errorText');
				isOK = false;
			}
			
	});

	
	if (isOK){
		var showAdditional = false;
		for (j = 0; j < inputsClueTip.length; j++) {
			if ( inputsClueTip[j].value  && inputsClueTip[j].name == inputsE84tt[j].name) {
				inputsE84tt[j].value = inputsClueTip[j].value;
				inputsE84tt[j].enable();
				inputsClueTip[j].disable();
				showAdditional = true;
			}
		}
		if (showAdditional) {
		$('e84additional').show();
		} else {
			$('e84additional').hide();		
		}
		$('F80error').hide();
		$('cluetip').toggle();
	} else {
		$('F80error').show();
	}
}
function clearE84tt() {
	var inputsClueTip = $('cluetip-inner').select('input', 'select');
	var inputsE84tt = $('e84tt').select('input', 'select');
	inputsClueTip.each(function(field){
		if (field.name == 'state'){
			field.selectedIndex = -1;
		} else {
			field.value = '';
		}
		field.removeClassName('errorHighlight');
	});
	inputsE84tt.each(function(field){
		if (field.name == 'state')
			field.selectedIndex = -1;
		else
			field.value = '';
		field.disable();
	});
	var labels = $('cluetip-inner').select('label');
	labels.each(function(field){
		field.removeClassName('errorText');	
	});
	
	$('e84additional').hide();	
	$('F80error').hide();
	
}
/* E85 */	

function e85add_user() {
	// add only up to 3 user
	var c_max = $('f85_user_max').value;
	var c = $('f85_user_count').value;

	// add elements
	if (c < c_max) {

			var _tr1 = document.createElement('tr');
			_tr1.appendChild( add_label( $('name_0_label').innerHTML ));
			_tr1.appendChild( add_input( 'name_' + c ));
			jQuery('#e85add_user').before( _tr1 );
		
			var _tr2 = document.createElement('tr');
			_tr2.appendChild( add_label( $('email_0_label').innerHTML ));
			_tr2.appendChild( add_input( 'email_' + c ));
			jQuery('#e85add_user').before( _tr2 );

    		c++;
    }
   	if (c == c_max) {
 			// hide the add button
    		$('e85add_user').hide();
   	}
   	jQuery('#f85_user_count').val( c );
    	
}

function add_label( text ) {
	var _label = document.createElement('label');
	_label.innerHTML = text;
	var _td = document.createElement('td');
	_td.appendChild( _label );
	return _td;
}

function add_input( id ) {
	var _input = document.createElement('input');
	_input.setAttribute('type', 'text');
        _input.setAttribute('id', id );
        _input.setAttribute('name', id );
	var _td = document.createElement('td');
	_td.setAttribute('align', 'right' );
	_td.appendChild( _input );
	return _td;
}		
	
/* E86 */
function updateE86Input(){
	/*
	 * update with values from E83 and E84
	 * if no values were entered so far
	 */ 
	 var doUpdate = $('e86_update').innerHTML;
	 if (doUpdate){
		 var inputsE68tt = $('e86tt').select('input', 'select');
		 inputsE68tt.each(function(field){
		 	var field2 = $(field.name.substring(4));
		 	if (field.name == 'e86_state')
		 		field.selectedIndex = field2.selectedIndex
		 	else
		 		field.value = field2.value;
		 });
	 }
}


function closeE86tt() {
	var inputsClueTip = $('cluetip-inner').select('input', 'select');
	var inputsE86tt = $('e86tt').select('input', 'select');
	var zipFormat = new RegExp($('e86_zipFormat').innerHTML, 'g');
	var isOK = true;
	$w($('e86_validationRule').innerHTML).each(function validateInputField(fieldName){
			var field = $('cluetip-inner').select('[name=' + fieldName + ']');
			var label = $('cluetip-inner').select('[for=' + fieldName + ']');
			if (field[0].value.length === 0){
				field[0].addClassName('errorHighlight');
				label[0].addClassName('errorText');
				isOK = false;
			} else {
				field[0].removeClassName('errorHighlight');
				label[0].removeClassName('errorText');
			}
			// validate zip code
			if (field[0].name == 'zipCode' && zipFormat.test(field[0].value)){
				field[0].addClassName('errorHighlight');
				label[0].addClassName('errorText');
				isOK = false;
			}
			
	});

	
	if (isOK){
		for (j = 0; j < inputsClueTip.length; j++) {
			if ( inputsClueTip[j].value  && inputsClueTip[j].name == inputsE86tt[j].name) {
				inputsE86tt[j].value = inputsClueTip[j].value;
				inputsE86tt[j].enable();
				inputsClueTip[j].disable();
			}
		}
		$('e86Option2').checked = 'checked';
		// remove update flag, because we now have user-entered values
		$('e86_update').innerHTML = '';
		$('F80error').hide();
		$('cluetip').toggle();
	} else {
		$('F80error').show();
	}
}
function clearE86tt() {
	var inputsClueTip = $('cluetip-inner').select('input', 'select');
	var inputsE86tt = $('e86tt').select('input', 'select');
	inputsClueTip.each(function(field){
		if (field.name == 'state'){
			field.selectedIndex = -1;
		} else {
			field.value = '';
		}
		field.removeClassName('errorHighlight');
	});
	inputsE86tt.each(function(field){
		if (field.name == 'state')
			field.selectedIndex = -1;
		else
			field.value = '';
		field.disable();
	});
	var labels = $('cluetip-inner').select('label');
	labels.each(function(field){
		field.removeClassName('errorText');	
	});
	$('e86Option2').checked = '';
	// remove update flag, because we now have user-entered values
	$('e86_update').innerHTML = '';
	$('F80error').hide();
	
}

/* F87 */
function termsAndCond(catalogId, langId, storeId) {

		var url = "/webapp/wcs/stores/servlet/PSOptionTermsAndConditionsView?" + "catalogId=" + catalogId + "&langId=" + langId + "&storeId=" + storeId;
		window.open( url, '', 'location=no,menubar=no,toolbar=no,scrollbars=yes,dependent=yes,width=512,height=500,left=100,top=200');
}
	
/* F88 */
function f88highlightError() {
		var labels = $$('label.f88Option_label');
//		i.e. bug
//	 	l.each(function(index, item )  {
//				item.addClassName('errorText');
//	 	});
		for (i = 0; i < labels.length; i++) {
				var item = labels[i];
				var c = item.className;
				item.className = c + ' errorText';
		}	
}	
	
function sendQuoteRequest() {

	hideError();
	deactivateButton('submitFormButton');
		
	var req = new Ajax.Request( 'PSOptionQuote', {
		method:'post',
		parameters:  $('quote').serialize(true) ,
		requestHeaders: ['Connection', 'close'],

		onSuccess: function(transport){
			var response = transport.responseText;
			if (response.search(/form/) != -1) {
				
				$('layer-confirm').update( response );
							
			    jQuery('#layer-form').fadeOut(500,function(){
  					 $('layer-form').hide();
  					 jQuery('#layer-confirm').show();

					var div = $('layer-confirm').getElementsByTagName("div");
					for (i = 0; i < div.length; i++) {
							var item = div[i];
							var c = item.className;
							if(c.search(/opaque10/) != -1)
									item.className = c.replace(/opaque10/g, "");
					}
 				});					
			} else {
				eval( response );
				// move window
				goto_top();
				activateButton('submitFormButton', 'javascript:sendQuoteRequest();');
			}	
		},
		onFailure: function(transport){
			jQuery.popup.show( $('f80sendRequestError').value );
		}
	});
}

function sendTrialRequest() {

	hideError();
	deactivateButton('submitFormButton');
			
	new Ajax.Request( 'PSOptionTrial', {
		parameters:  $('try').serialize(true) ,
		requestHeaders: ['Connection', 'close'],
		
		onSuccess: function(transport){
			var response = transport.responseText;
			if (response.search(/form/) != -1) {
				$('layer-confirm').update( response );
							
			    jQuery('#layer-form').fadeOut(500,function(){
  					 $('layer-form').hide();
  					 jQuery('#layer-confirm').show();

					var div = $('layer-confirm').getElementsByTagName("div");
					for (i = 0; i < div.length; i++) {
							var item = div[i];
							var c = item.className;
							if(c.search(/opaque10/) != -1)
									item.className = c.replace(/opaque10/g, "");
					}
				});	
			} else {
				eval( response );
				// move window
				goto_top();
				activateButton('submitFormButton', 'javascript:sendTrialRequest();');
			}	
		},
		onComplete: function() {
			f81confirm();				
		},
		onFailure: function(){ 
			jQuery.popup.show( $('f80sendRequestError').value );
		}
		
	});
}

function f81confirm() {
			var inputs = $('layer-confirm').getElementsByTagName("input");
			for (i = 0; i < inputs.length; i++) {
							var item = inputs[i];
							eval( item.value );			
			}
}

function hideError() {
	
			var inputs = $$('input.errorHighlight');
			for (i = 0; i < inputs.length; i++) {
				inputs[i].removeClassName('errorHighlight');
			}
			var selects = $$('select.errorHighlight');
			for (i = 0; i < selects.length; i++) {
				selects[i].removeClassName('errorHighlight');
			}
			var labels = $$('label.errorText');
			for (i = 0; i < labels.length; i++) {
			
				// it could be so easy:
				//labels[i].removeClassName('errorText');
			
				// IE:
				var item = labels[i];
				var c = item.className;
				if(c.search(/errorText/) != -1)
					item.className = c.replace(/errorText/g, "");
			}
}


// avoid multiple requests
function deactivateButton(button) {
		$(button).href = 'javascript:pleaseWait();';
		jQuery('#' + button).css('cursor', 'wait');
		
		if($(button).className.search(/imgButton/) != -1)
			$(button).className = $(button).className.replace(/imgButton/g, "imgButton2");
}

// activat the button again
function activateButton(button, href) {
		$(button).href = href;
		jQuery('#' + button).css('cursor', 'pointer');

		if($(button).className.search(/imgButton2/) != -1)
			$(button).className = $(button).className.replace(/imgButton2/g, "imgButton");
}

function pleaseWait() {
		//alert('Welcome to Windows 95');
}

