PopupPrivacyPolicy = {'idDiv':'id_popupPrivacyPolicy'};

$(document).ready(function() {
	RegistrationDiv.init();
	
	LinkVerificationByFax.init();
	LinkTos.init();
	LinkPrivacyPolicy.init();

	PopupTos.init();
	PopupPrivacyPolicy.init();



	StagesBar.init();

	Captcha.init();

	CustomerPosition.init();

	CheckboxNewsletter.init();

	UploadActions.init();


});



LinkVerificationByFax = {};

LinkVerificationByFax.init = function()
{
	$('#firm_verification_by_fax').bind('click', function() {
		if ( SecteoFormCheckbox.isChecked('firm_verification_by_fax') == false) {
			$('#id_upload_block').slideDown(200);
		} else {
			$('#id_upload_block').slideUp(200);
		}
	});

	$('#firm_verification_by_fax_label').bind('click', function() {
	    SecteoFormCheckbox.click('firm_verification_by_fax');
		if ( SecteoFormCheckbox.isChecked('firm_verification_by_fax') == false) {
			$('#id_upload_block').slideDown(200, function() {
				$('#table_stage_4').attr('class', 'registrationForm firm-confirm-file-down');
			});
		} else {
			$('#id_upload_block').slideUp(200, function() {
				$('#table_stage_4').attr('class', 'registrationForm firm-confirm-file-up');
			});
		}
	}).css({'cursor':'pointer'});

	if ( $('#id_hidden_firm_verification_by_fax').attr('value') == "1" ) {
		$('#id_upload_block').hide();
		$('#table_stage_4').attr('class', 'registrationForm firm-confirm-file-up');
	} else {
		$('#id_upload_block').show();
		$('#table_stage_4').attr('class', 'registrationForm firm-confirm-file-down');
	}
}


LinkTos = {};

LinkTos.init = function()
{
	$('#id_showPopupTos').bind('click', function() {
		PopupTos.open();
	})

	SecteoFormCheckbox.setDisabled('customer_tos_ok');

	$('#customer_tos_ok').bind('click', function() {
		if ( SecteoFormCheckbox.isChecked('customer_tos_ok') == false ) {
			PopupTos.open();
		} else {
			SecteoFormCheckbox.setChecked('customer_tos_ok', false)
		}
	});
}

LinkPrivacyPolicy = {};

LinkPrivacyPolicy.init = function()
{
	$('#id_showPopupPrivacePolicy').bind('click', function() {
		PopupPrivacyPolicy.open();
	});

	SecteoFormCheckbox.setDisabled('customer_privacy_policy_ok');

	$('#customer_privacy_policy_ok').bind('click', function() {
		if ( SecteoFormCheckbox.isChecked('customer_privacy_policy_ok') == false ) {
			PopupPrivacyPolicy.open();
		} else {
			SecteoFormCheckbox.setChecked('customer_privacy_policy_ok', false)
		}
	});
}

PopupTos = {'idDiv':'id_popupTos'};

PopupTos.init = function()
{
	this.div = $('#' + this.idDiv);

	$('#id_img_popupTos_window_close').click(function() {
		PopupTos.cancel();
	});

	$('#id_buttonPopupTosClose_top').click(function() {
		PopupTos.ok();
	});

	$('#id_buttonPopupTosClose').click(function() {
		PopupTos.ok();
	});
}

PopupTos.open = function()
{
	/*
    OverlayModal.setShowCallback('PopupTos._show()');
	OverlayModal.setHideCallback('PopupTos._close()');
	OverlayModal.show();
	*/
	PopupTos._show();
}


PopupTos._show = function()
{
	var pageSize = jQuery.iUtil.getScroll();

	var width = 570;
	var height = 'auto'; //500;

	var maxW = Math.max(pageSize.iw,pageSize.w); //1210;
	var maxH = Math.max(pageSize.ih,pageSize.h);

	var left = ( maxW - width )/2; // 2;
	var top =  (Browser.isMsie())?32:window.pageYOffset + 32;

	this.div.css({
		 'border':'0px solid #ff0000',
		 'z-index': 1864,
		 'background-color':'#ffffff',
		 'position':'absolute',
		 'top': top + 'px',
		 'left': left + 'px',
		 'width': width,
		 'height': height
	});

	$('body').append(this.div);

	var infoText = 'width:' + width + ' height:' + height + ' <br/>'
		         + ' maxW:' + maxW + ' maxH:' + maxH + ' <br/>'
				 + ' left:' + left + ' top:' + top;

 	this.div.show();
	OverlayModal.show();
	RegistrationDiv.goInShadow();
}


PopupTos.ok = function()
{
	SecteoFormCheckbox.setChecked('customer_tos_ok', 1);
	/* OverlayModal.hide(); */
	PopupTos._close();	
	window.scrollTo(0,0);
}

PopupTos.cancel = function()
{  
	SecteoFormCheckbox.setChecked('customer_tos_ok', 0);
	/* OverlayModal.hide(); */
	PopupTos._close();
}

PopupTos._close = function()
{
	this.div.hide();
	RegistrationDiv.goFromShadow();
}

PopupPrivacyPolicy.init = function()
{
	this.div = $('#' + this.idDiv); //alert('PopupPrivacyPolicy.init');

	$('#id_img_popupPrivacyPolicy_window_close').click(function() {
		PopupPrivacyPolicy.cancel();
	});

	$('#id_buttonPopupPrivacyPolicyClose_top').click(function() {
		PopupPrivacyPolicy.ok();
	});

	$('#id_buttonPopupPrivacyPolicyClose').click(function() {
		PopupPrivacyPolicy.ok();
	});
}

PopupPrivacyPolicy.open = function()
{
	/*
	OverlayModal.setShowCallback('PopupPrivacyPolicy._show()');
	OverlayModal.setHideCallback('PopupPrivacyPolicy._close()');
	OverlayModal.show();
	*/
	OverlayModal.show();
	PopupPrivacyPolicy._show();
}

PopupPrivacyPolicy._show = function()
{
	var pageSize = jQuery.iUtil.getScroll();

	var width = 570;
	var height = 'auto'; //500;

	var maxW = Math.max(pageSize.iw,pageSize.w); //1210;
	var maxH = Math.max(pageSize.ih,pageSize.h);

	var left = ( maxW - width ) / 2 ;
	var top =  (Browser.isMsie())?32:window.pageYOffset + 32;

	this.div.css({
		 'border':'0px solid #ff0000',
		 'z-index': 1864,
		 'background-color':'#ffffff',
		 'position':'absolute',
		 'top': top + 'px',
		 'left': left + 'px',
		 'width': width,
		 'height': height
	});

	$('body').append(this.div);

	var infoText = 'width:' + width + ' height:' + height + ' <br/>'
		         + ' maxW:' + maxW + ' maxH:' + maxH + ' <br/>'
				 + ' left:' + left + ' top:' + top;

 	this.div.show();
	RegistrationDiv.goInShadow();
}


PopupPrivacyPolicy.ok = function()
{
	SecteoFormCheckbox.setChecked('customer_privacy_policy_ok', 1);
	/* OverlayModal.hide(); */
	PopupPrivacyPolicy._close();
	window.scrollTo(0,0);
}

PopupPrivacyPolicy.cancel = function()
{
	SecteoFormCheckbox.setChecked('customer_privacy_policy_ok', 0);
	/* OverlayModal.hide(); */
	PopupPrivacyPolicy._close()
}

PopupPrivacyPolicy._close = function()
{
	this.div.hide();
	RegistrationDiv.goFromShadow();
}

RegistrationDiv = {};

RegistrationDiv.init = function()
{

	//return;

	var div = $('#id_registration_div');
	div.css(
				{
					'z-index'   : '1860',
					//'background': '#ffffff',
					'opacity':1,
					'position': 'absolute',
					'left': '50%',
					'top': Platform.getValue('175px','161px','167px','169px'),
					'margin-left': '-365px',
					'border-top':'4px solid #359ac9'
					//'top':'-1000px;'
				}
			);
	//div.fadeIn();

		var tabs = $('#id_registration_tab').css({
				//'margin-top':'-59px'
				'opacity':1,
				'-moz-opacity': 1,
				'z-index'   : '1862',
				'position':'absolute',
				'top':'-48px',
				'left': '0px'
				});


			$('#footer_nav').css({
				'margin-top':'500px'
			});

			$('#layout_message_in_content').hide();
			//div.hide();
			
	
	//alert($('#customer_title').css('margin'));
	
	$('div.SecteoFormSelectContainer').css({
		'opacity':1
	});
	
	$('#upload_frame').css({
		'opacity':1
	});	

			
	$('body').append(div);
	if ( true ) {
		tabs = $('#id_registration_tab').css({
				'top':Platform.getValue('134px','120px','126px','128px'),
				'left': '50%',
				'margin-left': '-365px'
		});
		$('body').append(tabs);
	}
	
	//OverlayModal.setHideCallback('PopupTos.cancel();PopupPrivacyPolicy.cancel();Browser.gotoHref("");');
	OverlayModal.setHideCallback('PopupTos.cancel();PopupPrivacyPolicy.cancel();');
	OverlayModal.show(false, true); //OFF - RASTER ALIGNING

	$('#id_form_registration').bind('submit', function() {
		//OverlayModal.hide();
	});

	if (jQuery.browser.msie) {
		//alert('ie');
	}

	var messageBox = $("#id_message_box").dialog({
		      "autoOpen":false,
		      "dialogClass":"secteo",
		      "modal":true,
		      "overlay":{"opacity":"0.5", "background-color":"#000000"}
		   });

	

	//alert($('#customer_title').css('filter'));
	//RegistrationDiv.goInShadow();
	//$("#id_message_box").dialog("open");
}

RegistrationDiv.goInShadow = function()
{
	$('#id_registration_div').css({
		'z-index':700
	});
	$('#id_registration_tab').css({
		'z-index':700
	});
}

RegistrationDiv.goFromShadow = function()
{
	$('#id_registration_div').css({
		'z-index':1860
	});
	$('#id_registration_tab').css({
		'z-index':1862
	});
}

StagesBar = {};

StagesBar.init = function()
{
/*
		$('#id_img_registrationStage_2').bind('mouseover', function(){
			$('#caption_of_stage_2').attr({
				'class': 'enabled'
			});
		}).bind('mouseout', function(){
			$('#caption_of_stage_2').attr({
				'class': 'disabled'
			});
		});
*/

		$('#id_img_registrationStage_1').bind('click', function(){
			$('#nextStageNo').attr('value','1');
		})
		.bind('mouseover', function() {
			$('#caption_of_stage_1').mouseover();
		})
		.bind('mouseout', function() {
			$('#caption_of_stage_1').mouseout();
		});

		$('#id_img_registrationStage_2').bind('click', function(){
			$('#nextStageNo').attr('value','2');
		})
		.bind('mouseover', function() {
			$('#caption_of_stage_2').mouseover();
		})
		.bind('mouseout', function() {
			$('#caption_of_stage_2').mouseout();
		});

		$('#id_img_registrationStage_3').bind('click', function(){
			$('#nextStageNo').attr('value','3');
		})
		.bind('mouseover', function() {
			$('#caption_of_stage_3').mouseover();
		})
		.bind('mouseout', function() {
			$('#caption_of_stage_3').mouseout();
		});

		$('#id_img_registrationStage_4').bind('click', function(){
			$('#nextStageNo').attr('value','4');
		}).bind('mouseover', function() {
			$('#caption_of_stage_4').mouseover();
		})
		.bind('mouseout', function() {
			$('#caption_of_stage_4').mouseout();
		});

		$('#id_img_registrationStage_5').bind('click', function(){
			$('#nextStageNo').attr('value','5');
		}).bind('mouseover', function() {
			$('#caption_of_stage_5').mouseover();
		})
		.bind('mouseout', function() {
			$('#caption_of_stage_5').mouseout();
		});


		$('#hover_caption_of_stage_1')
		.bind('mouseover', function() {
			$('#id_img_registrationStage_1').mouseover();
		})
		.bind('mouseout', function() {
			$('#id_img_registrationStage_1').mouseout();
		});

		$('#hover_caption_of_stage_2')
		.bind('mouseover', function() {
			$('#id_img_registrationStage_2').mouseover();
		})
		.bind('mouseout', function() {
			$('#id_img_registrationStage_2').mouseout();
		});

		$('#hover_caption_of_stage_3')
		.bind('mouseover', function() {
			$('#id_img_registrationStage_3').mouseover();
		})
		.bind('mouseout', function() {
			$('#id_img_registrationStage_3').mouseout();
		});

		$('#hover_caption_of_stage_4')
		.bind('mouseover', function() {
			$('#id_img_registrationStage_4').mouseover();
		})
		.bind('mouseout', function() {
			$('#id_img_registrationStage_4').mouseout();
		});

		$('#hover_caption_of_stage_5')
		.bind('mouseover', function() {
			$('#id_img_registrationStage_5').mouseover();
		})
		.bind('mouseout', function() {
			$('#id_img_registrationStage_5').mouseout();
		});
}

Captcha = {};

Captcha.init = function()
{
	//alert('captcha.init');
	$('div.captcha img').bind('click', function() {
		//alert(this.src);
		var url = "getnewcaptcha";
		//alert(url);
		//$.get(url ,  function(json) {  alert(json);
	    $.getJSON(url ,  function(json) {
		    if (json.isSuccess == true) {
				$('#customer_captcha-input').attr('value', '');
				$('#customer_captcha-id').attr('value', json.newId);
				$('div.captcha img').attr('src', json.newImageSrc);
			}
		})
		$('#customer_captcha-input').focus();
	})
	.css({
			'cursor':'pointer'
		});
		/*
	$('#id_captcha div.image')
	.tooltip({'bodyHandler':function() {
			return $('<img/>').attr({'src':'default/index/tooltip/localeId/' + Locales.localeId + '/moduleTmx/registration/captionKey/_key_captcha_Click'});
	 }});
	 */

	 $('#id_captcha div.image').tooltip({
		'showURL':false,
		'id': 'SecteoInputHelp'
	});
}

CustomerPosition = {};

CustomerPosition.init = function()
{
	//alert('CustomerPosition.init');
	$('#group_id').bind('change', function() {
		CustomerPosition.xable(true);
	});
	CustomerPosition.xable(false);
}

CustomerPosition.xable = function(isSlide)
{
	//alert($('#group_id').val());
	if ($('#group_id').attr('value') == "-1") {
		if (isSlide) {
			$('#div_customer_group_other').slideDown(function(){
				$('#customer_group_other').focus();
				$('#message_customer_group_other').css({'padding-top':'30px'});
			});
		} else {
			$('#div_customer_group_other').show();
			$('#customer_group_other').focus();
			$('#message_customer_group_other').css({'padding-top':'30px'});
		}
	}
	else {
		$('#div_customer_group_other').hide();
		$('#customer_group_other').attr('value', '');
		/*
		if (isSlide) {
			$('#div_customer_group_other').hide(function(){
				$('#customer_group_other').attr('value', '');
			});
		} else {
			$('#div_customer_group_other').hide();


		}*/
		$('#message_customer_group_other').css({'padding-top':'2px'});
	}
}

CheckboxNewsletter = {};
CheckboxNewsletter.init = function()
{
	//alert('CheckboxNewsletter.init');

	$('#id_customer_newsletter_label').bind('click', function() {
	    SecteoFormCheckbox.click('customer_newsletter');
	}).css({'cursor':'pointer'});
}

UploadActions = {};
UploadActions.init = function()
{
	//alert('UploadActions.init()');

}

UploadActions.initJsAction = function()
{
	//alert('--UploadActions.initJsAction()');
	$('#id_registration_IndustryVerificationText').show();
	$('#id_registration_firm_verification_file_Help').show();
	$('#table_stage_4').show();
	$('#id_registration_InputFileUploadLabel').show();

}

UploadActions.preJsAction = function()
{
	//alert('--UploadActions.preJsAction()');
	UploadActions.postJsAction();
}

UploadActions.postJsAction = function()
{
	//alert('--UploadActions.postJsAction()');
	$('#id_registration_IndustryVerificationText').hide();
	$('#id_registration_firm_verification_file_Help').hide();
	$('#table_stage_4').hide();
	$('#id_registration_InputFileUploadLabel').hide();
	$('#message_upload_firm_verification_file_alias').empty();
}

