function change_country(country_id,state_list,province)
{
	var state_obj=$('#state_'+$('#'+country_id).val());
	if(state_obj[0])
	{
		$('#'+state_list).html(state_obj.html());
		$('#'+province).hide();
		$('#'+state_list).show();
	}
	else
	{
		$('#'+state_list).hide();
		$('#'+state_list).html('<option value="1"></option>');
		//$('#'+province).val('');
		$('#'+province).show();
	}
}

function notice(root_url)
{
    $.post(root_url+'/index.php',{mod:'ajax',act:'notice'},function(notice){if(notice!='')alert(notice);});
}

function show_info(msg) {
   var info='';
   if(msg!='')
   {
        info=msg.split('/');
        if(info.length==4)
        {
            $('#quantity').html(info[0]);
            $('#sub_total').html(info[1]);
            $('#discount').html(info[2]);
            $('#total').html(info[3]);
        }
   }
}

function shop_cart(root_url)
{
    $.post(root_url+'/index.php',{mod:'ajax',act:'shop_cart'},function(msg){show_info(msg);});
}

/*
function cart_add(id) {
    $.post('<!--/root_url-->/index.php',{mod:'ajax',act:'cart_add',id:id},function(msg){if(msg=='success'){shop_cart();alert('Product add to shopping cart success!');}});
}
*/

function login(root_url,skins_url,logout)
{
    var email=$('#ajax_email').val();
    var password=$('#ajax_pwd').val();

    if( (email!='') && (password!=''))
    {
       $.post(
        root_url+'/index.php',
        {act:'ajax_login',email:email,password:password},
        function(msg)
        {
            var data='';
            if(msg!='')
            {
                data=msg.split('/');
                if(data[0]=='success')
                {
                    alert('Login success !');
                    refresh_user_info(root_url,skins_url,logout);
                    shop_cart(root_url);
                }
                else
                {
                    alert('Login fail please check email & password !');
                }
            }
        }
        );
     }
     else
     {
        if(email=='')alert('Email can not be empty !');
        if(password=='')alert('Password can not be empty !');
     }
}

function refresh_user_info(root_url,skins_url,logout)
{
    $.post(root_url+'/index.php',
            {mod:'ajax',act:'ajax_is_login'},
            function(msg)
            {
                var data='';
                if(msg!=''){
                    data=msg.split('/');
                    if(data[0]=='success')
                    {
                        logout=logout.replace(/fullname/g,data[1]);
                        $("#top_login_left").html(logout);
                    }
                    else
                    {
                        //$("#login_info").html(input_td);
                    }
                 }
            }
           );
}


//===================================
//register

function check_change(province_id,province2_id,country_id)
{
 	var select_obj=$('#'+province_id)[0];

   if($('#'+country_id).val()=='US')
    {
		 if(select_obj.selectedIndex<12)
		{
			 select_obj.selectedIndex=12;
		}
        hide_obj(province2_id);
    }
   else if($('#'+country_id).val()=='CA')
    {
		 if(select_obj.selectedIndex<2 || select_obj.selectedIndex>10 )
		{
			 select_obj.selectedIndex=2;
		}
        hide_obj(province2_id);
    }
	else
	{
 		 if(select_obj.selectedIndex!=0)
		{
			 select_obj.selectedIndex=0;
		}
       show_obj(province2_id);
	}

}

function country_check_change(country_id,province_id,province2_id)
{
	var select_obj=$('#'+province_id)[0];

   if($('#'+country_id).val()=='US')
    {
		 if(select_obj.selectedIndex<12)
		{
			 select_obj.selectedIndex=12;
		}
        hide_obj(province2_id);
    }
   else if($('#'+country_id).val()=='CA')
    {
		 if(select_obj.selectedIndex<2 || select_obj.selectedIndex>10 )
		{
			 select_obj.selectedIndex=2;
		}
        hide_obj(province2_id);
    }
	else
	{
 		 if(select_obj.selectedIndex!=0)
		{
			 select_obj.selectedIndex=0;
		}
       show_obj(province2_id);
	}
}

function show_obj(obj_id)
{
  $('#'+obj_id).show();
}

function hide_obj(obj_id)
{
  $('#'+obj_id).hide();
}

function image_src(image_id,image_src)
{
     $('#'+image_id).attr('src',image_src);
}
