$(document).ready(function(){
		$("#user_name").focus();
		
		$("#agreentment").click(function() { 

			if($("#agreentment").attr("checked")==true)
			{
				$("#register").removeAttr("disabled");
				document.getElementById('login_error').innerHTML = '';
				document.getElementById('login_error').style.display = 'none';
				//document.documentElement.scrollTop = 0;
			}
			else
			{
				$("#register").attr({"disabled":"disabled"});
				document.getElementById('login_error').innerHTML = tip_terms_err;
				document.getElementById('login_error').style.display = 'block';
				document.documentElement.scrollTop = 0;
			}

					
		});

		$("#user_pw1").blur(function() { 
			if(($("#user_pw1").val().length > 0 ) && ( $("#user_pw2").val().length > 0) )
			{
				if($("#user_pw1").val() != $("#user_pw2").val())
				{
					document.getElementById('login_error').innerHTML = tip_psw_err;
					document.getElementById('login_error').style.display = 'block';
					document.documentElement.scrollTop = 0;
				}
				else
				{
					document.getElementById('login_error').innerHTML = '';
					document.getElementById('login_error').style.display = 'none';
					document.documentElement.scrollTop = 0;
				}
			}

							
			});
		$("#user_pw2").blur(function() { 
			if(($("#user_pw1").val().length > 0 ) && ( $("#user_pw2").val().length > 0) )
			{
				if($("#user_pw1").val() != $("#user_pw2").val())
				{
					document.getElementById('login_error').innerHTML = tip_psw_err;
					document.getElementById('login_error').style.display = 'block';
					document.documentElement.scrollTop = 0;
				}
				else
				{
					document.getElementById('login_error').innerHTML = '';
					document.getElementById('login_error').style.display = 'none';
					document.documentElement.scrollTop = 0;
				}
			}

							
			});
	}); 

	function setActive(i,id){
		for(var ti=1;ti<8;ti++){
			
			if($("#"+id+ti).hasClass('active-trail'))
				$("#"+id+ti).removeClass('active-trail');
			if(ti == i)
				$("#"+id+ti).addClass('active-trail');
		}

	}

	function ShowMenu(obj,id)
	{
		if($(obj).focus())
			$("#"+id).css('display','block');
	}

	var show = function (e) {   
	  alert(e.currentTarget?"To obtain currentTarget":"To obtain document.activeElement")   
	  alert((e.currentTarget || document.activeElement).tagName);   
	 };   


	function HiddenMenu()
	{
		
		//$("#"+id).css('display','none');
		/*
		 $(obj).bind("mouseleave", function(){ 
			$("#"+id).css('display','none');
		}); 
		*/
		alert(document.activeElement);
	}

	function FlyoutMenu( elemLink, elemPopup )
	{
		var elemLink = $("#"+elemLink);
		var elemPopup = $("#"+elemPopup);
		
		elemPopup.css('display','block');
		
	}

	function HideFlyoutMenu( event, elemLink, elemPopup )
	{
		var elemLink = $("#"+elemLink);
		var elemPopup = $("#"+elemPopup);
		elemPopup.css('display','none');
		//var reltarget = (event.relatedTarget) ? event.relatedTarget : event.toElement;
		//alert(reltarget.tagName);
		//if ( !reltarget || ( $(reltarget).up( '#' + elemLink.id ) || $(reltarget).up( '#' + elemPopup.id )  ) )
			//return;

		// start hiding in a little bit, have to let the fade in animation start before we can cancel it
		//window.setTimeout( HideWithFade.bind( null, elemPopup ), 33 );
		
	}

	function addEmail(obj,id)
	{
		divHTML = $("#"+id).prev().html();
		//cnt		= $("#cnt").val();
		appendHTML = "<tr class='invitetr'>"+divHTML+"</tr>";
        $("#addemail").before(appendHTML);
	}

	function concelThisRow(obj)
	{
		if($(".invitetr").length > 1)
			$(obj).parent().parent().parent().remove();
	}
	
	function sendEmail()
	{
		if($('input[name=user_email]').length > 0)
		{
			var hiddemailtxt;
			cnt = $('input[name=user_email]').length;
			$("#emailtxt").val("");
			for(i=0 ; i<cnt ;i++)
			{
				emailtxt		= $('input[name=user_email]')[i].value;
				hiddemailtxt	= $("#emailtxt").val() + emailtxt+';';
				$("#emailtxt").val(hiddemailtxt);
			}
		}
		$("#inviteform").submit();
	}


	function inviteFacebook()
	{
		var limitLen        = 140;
			
		var strSendTw		= $("#fbCont").val();
		var strSendTwLen	= $("#fbCont").val().length;
		var uid				= $("#uid").val();
		var sid				= $("#sid").val();
		var strid			= "uid="+uid+"&sid="+sid;
//alert(strid);	
	//	if( strSendTwLen > limitLen)
	//		strSendTw		= strSendTw.substring(0,limitLen);

		var exp = new Date();
		exp.setTime(exp.getTime() + 30*60*1000);	//30 minus expires

		if(/.*[\u4e00-\u9fa5]+.*$/.test(strSendTw)) 
			document.cookie = "fbCont=" + escape(strSendTw) +";expires=" + exp.toGMTString();
		else
			document.cookie = "fbCont=" + strSendTw +";expires=" + exp.toGMTString();

		document.cookie = "strid=" + strid +";expires=" + exp.toGMTString();

		var url = 'http://www.raidcall.com/fb/home.php';                                 //redirect url;
		var name = 'popwin';                           //the name of pop windows ,can be null;
		var iWidth = 800;                          //popwin's width;
		var iHeight =600;                        //popwin's height;
		var iTop = (window.screen.availHeight-30-iHeight)/2;       //To obtain popwin's Vertical position;
		var iLeft = (window.screen.availWidth-10-iWidth)/2;           //To obtain popwin's Horizontal position;
		window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');

	}

	function sendTwitter()
	{
		
		
		var limitLen        = 140;
		
		var strSendTw		= $("#twitCont").val();
		var strSendTwLen	= $("#twitCont").val().length;
	
		if( strSendTwLen > limitLen)
			strSendTw		= strSendTw.substring(0,limitLen);

		var exp = new Date();
		exp.setTime(exp.getTime() + 30*60*1000);	//30 minus expires
		
		if(/.*[\u4e00-\u9fa5]+.*$/.test(strSendTw)) 
		{ 
			document.cookie = "twitCont=" + escape(strSendTw) +";expires=" + exp.toGMTString();
		}
		else
		{
			document.cookie = "twitCont=" + strSendTw +";expires=" + exp.toGMTString();
		}
			
		var url = 'http://www.raidcall.com/twip2/redirect.php';                                 
		var name = 'popwin';                           
		var iWidth = 500;                          
		var iHeight =400;                        
		var iTop = (window.screen.availHeight-30-iHeight)/2;       
		var iLeft = (window.screen.availWidth-10-iWidth)/2;           
		window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
		//window.open('http://www.raidcall.com/twip2/index.php?login=true', 800, 600);
	}