/* Ajax script */
function voteClick(id)
{
    vote = confirm('ยีนยันการ Vote ของคุณ');
    if(vote) {
        dojo.xhrPost ({
            url: '/webboard/vote/'+id,
            handle: function(data) {
                //alert(data)
                if(parseInt(data) >0) {
                    dojo.byId('post-'+id).innerHTML = data;
                } else {
                    msg = 'ไม่สามารถ Vote ได้ในขณะนี้';
                    alert(msg);
                }
            }
        }); 
    }    
}

function gotoStep(from, to)
{ 
	//alert('step 2: from: '+from+' '+'to: '+to);
	
    //$('#step-'+from).removeClass('current');
    //$('#step-'+to).addClass('current'); 
    //$('#apply-'+from).addClass('hide');
    //$('#apply-'+to).removeClass('hide');

	$('#step-'+from).hide();
	$('#step-'+to).show();
	$('#apply-'+from).hide();
	$('#apply-'+to).show();

    $(window).scrollTop();
    if(to=='3'){
        preview();
	}
}

function preview()
{
    copyValue('movie-name', 'movie_name');
    copyValue('embed-code', 'embed', 'html');
}

function checkTeamName(baseUrl, teamName)
{
	//alert(teamName);
	if(teamName == '')
	{
		alert('ตั้งชื่อทีมก่อนนะครับ ทราบแล้วเปลี่ยน');
		$('#team').focus();
		return false;
	}

	var iurl = baseUrl;

	$.ajax({
	   type: "POST",
	   url: iurl+"index.php/happyclip/checkTeam/",
	   data: "TeamName="+teamName,
	   success: function(msg){
	   //alert( "Check Team: " + msg );
	   
		 if(msg == 'This name is available') {
			alert('ชื่อทีมนี้ สามารถใช้ได้ครับ ทราบแล้วเปลี่ยน');
			$('#university').focus();
			return true;
		 } else {
			alert('ชื่อทีมนี้ใช้ในการสมัครไปแล้วนะครับ ทราบแล้วเปลี่ยน');
			$('#team').focus();
			return false;
		 }

	   }

	});
}

function copyValue(to, from, type)
{
    if(type=='html')
        dojo.byId(to).innerHTML = dojo.byId(from).innerHTML;
    else
        dojo.byId(to).innerHTML = dojo.byId(from).value;
}



/*
function uploadCard() 
{
	uri = '/index.php/happycard/upload_card';
	id = 'test';
		dojo.xhrPost({
			url: uri,
			form: "regis",
			handleAs: "text",
			handle: function(content) {
				//alert(content);
				dojo.byId(id).innerHTML = content;	
			}
		});


}
*/

function memberInput(id)
{
    for(var i=1; i<7; i++) {
        if(i<=id){
			$('#member-'+i).removeClass('hide');
		} else {
            $('#member-'+i).addClass('hide'); 
		}
    }
}


// vote Card
function voteCard(guidCard)
{
	vote = confirm('คุณต้องการ Vote ใช่หรือไม่');

  uri = 'http://www.happy.co.th/maichailen/index.php/happycard/vote/'+guidCard;
	//alert(uri);
  dojo.xhrPost({
    url: uri,
    handleAs: 'text',
    handle: function(data) {
			//alert(data);
			if(data=='timeLimit') {
				alert('โหวตได้ทุกๆ 1 ช.ม.');
			} else {
				alert("เพิ่มคะแนนโหวต +1");
				dojo.byId('showVote').innerHTML = data;
			}
   }
 });

}
