if (navigator.appVersion.toLowerCase().indexOf('msie 6') != -1) {
	document.write("<script type='text/javascript' src='_data/js/jquery.bgiframe.js'></script>");
}

var currentFocus = null;
var to = null;
var to2 = null;
var to3 = null;
var to4 = null;

function checkAccountPass()
{
	var pass = $('input[name=idPassword]').val();
	var rand = Math.random();

	$.ajax({
	   type: "POST",
	   url: "ajax.php?rand="+rand,
	   data: "checkHostIdCardPass="+pass+"&action=checkPassword",
	   success: function(html){
	     	if(html=='1')
			{
				$('#passwordCheckImg').css('background-image', 'url(_data/skin/registerMember/validCheck.gif)');
			}
			else{
				$('#passwordCheckImg').css('background-image', 'url(_data/skin/registerMember/invalidCheck.gif)');
			}
	   }
	});
	
	checkConfPass();
}

function checkConfPass()
{
	var fld = $('#idPassword').val();
	var conf = $('#confirmIDPassword').val();
	if(fld && fld == conf)
	{
		$('#passwordConfImg').css('background-image', 'url(_data/skin/registerMember/validCheck.gif)');
	}
	else{
		$('#passwordConfImg').css('background-image', 'url(_data/skin/registerMember/invalidCheck.gif)');
	}
}

function checkAccountPassTimeouter()
{
	clearTimeout(to);
	to = setTimeout('checkAccountPass()', 500);
}

function show_tooltip(obj, hei)
{
	var offset = 0;
	var browser = navigator.appVersion;
	if (browser.toLowerCase().indexOf('msie 6')!=-1) {
		
		offset = 305;
		$('.info_pic').bgiframe();
	}
	var pos = $(obj).position();
	var objTTtext = $(obj).parent().next().next()
	var txt = objTTtext.text();
	if (objTTtext.attr('class')=='hiddenTTinfo' && txt) {
		$('.ipinner').text(txt);
		$('.info_pic').css({
			'top': parseInt(pos.top + $(obj).parent().parent().position().top + 23) + 'px',
			'left': parseInt(pos.left - offset + $(obj).width() + 30) + 'px'
		});
		
		$(obj).parent().parent().parent().children('.info_pic').children().show(50);//.show('fast');
	}
}
function checkEmail()
{
	var mail = $('#hostEmail').val();
	if(mail.search(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i)!=-1)
	{
		$('#emailCheckImg').css('background-image', 'url(_data/skin/registerMember/validCheck.gif)');
	}
	else{
		$('#emailCheckImg').css('background-image', 'url(_data/skin/registerMember/invalidCheck.gif)');
	}
}
function checkIdCardName()
{
	var card = $('input[name=idCardName]').val();
	var rand = Math.random();

	$.ajax({
	   type: "POST",
	   url: "ajax.php?rand="+rand,
	   data: "checkHostIdCardName="+card+"&action=checkIdCardName",
	   success: function(html){
	     	if(html=='1')
			{
				$('#IdCardNameImg').css('background-image', 'url(_data/skin/registerMember/validCheck.gif)');
			}
			else{
				$('#IdCardNameImg').css('background-image', 'url(_data/skin/registerMember/invalidCheck.gif)');
			}
	   }
	});
}

$(document).ready(function(){

	$('select[name="State"]').change(function(){
		var selected = $('select[name="State"]').val();
		if(selected == -1){ selected = ''; }
		$('input[name="state_province"]').val( selected );
	});
	
	$('.inputWraper > div > input').focus(function(){
		if (currentFocus) {
			if (currentFocus.attr('id') != $(this).parent().parent().attr('id')) {
				var obj = $(this).parent();
				var this_obj = this;
			
				show_tooltip(this_obj, $(this).height());
			}
			else{
				show_tooltip(this, $(this).parent().parent().children('p').height());
			}
		}
		else{
			var obj = $(this).parent();
			var this_obj = this;
			show_tooltip(this_obj, $(this).height());
	
		}
		currentFocus = $(this).parent().parent();
		
	});
	
	
	$('.inputWraper > div > select').focus(function(){
		if (currentFocus) {
			if (currentFocus.attr('id') != $(this).parent().parent().attr('id')) {
				var obj = $(this).parent();
				var this_obj = this;
			
				show_tooltip(this_obj, $(this).height());
			}
			else{
				show_tooltip(this, $(this).parent().parent().children('p').height());
			}
		}
		else{
			var obj = $(this).parent();
			var this_obj = this;
			obj.parent().children('p').slideDown(200, function(){
				show_tooltip(this_obj, $(this).height());
			});		
		}
		currentFocus = $(this).parent().parent();
		
	});

	$('.inputWraper > .szW200').show();
	
	$('.inputWraper > div > input').blur(function(){
		//clearTimeout(to);
		//checkAccountPass();
		$('.info_pic_tooltip').hide();
	});
	$('.inputWraper > div > select').blur(function(){
		//clearTimeout(to);
		//checkAccountPass();
		$('.info_pic_tooltip').hide();
	});
	
	$('input[name=idCardName]').keyup(function(){
		clearTimeout(to);
		to = setTimeout('checkIdCardName()', 500);
	});
	
	$('#idPassword').keyup(function(){
		clearTimeout(to3);
		to3 = setTimeout('checkAccountPass()', 500);
	});
	$('#idPassword').blur(function(){
		clearTimeout(to3);
		checkAccountPass();
		$('#passwordCheckTT').hide();
	});
	
	$('#confirmIDPassword').keyup(function(){
		clearTimeout(to2);
		to2 = setTimeout('checkConfPass()', 300);
	});
	$('#confirmIDPassword').focus(function(){
		checkConfPass();
	});
	$('#hostEmail').keyup(function(){
		clearTimeout(to4);
		to4 = setTimeout('checkEmail()', 200);
	});
});
