
function printStar(star)
{
	for(i=1; i<6; i++)
	{
		if(star>=i)
		{
			document.write('<img src="/images/icon_star.gif" /> ')
		}
		else if(star>i-1 && star<i)
		{
			document.write('<img src="/images/icon_star1.gif" /> ')
		}
		else
		{
			document.write('<img src="/images/icon_star2.gif" /> ')
		}
	}
}

function setpic_callback(text)
{
	picNum = parseInt(text.split('?')[1]);
	currpicidx = parseInt(text.split('?')[2]);
	$('#imgpic').attr('src',text.split('?')[0]);
	html = '';
	for(i=0;i<picNum; i++)
	{
		if(i==currpicidx)
		{
			html += '<img src="/images/dot_02.gif">';
		}
		else
		{
			html += '<img src="/images/dot_01.gif">';
		}
	}
	$('#sc_dot').html(html);
}

function getpic(appid,dir)
{
	$.ajax(  {type: "GET",
  url: "/getpic?index="+((currpicidx+dir+picNum)%picNum).toString()+"&appid="+appid,
  dataType: "text",
  success:setpic_callback});
}
var vpindex = 0;
function GotoVideoPage(dir)
{
	lis = $('#vlst').children();
	if(lis.length == 0)
		return;
	if((vpindex+dir)*6>=lis.length || (vpindex+dir)<0)
		return;
	vpindex = vpindex+dir;
	staridx = vpindex*6 ;
	for(i=0; i<lis.length; i++)
	{
		lis[i].style.display='none';
	}
	for(i=0; i<6&&(staridx+i)<lis.length; i++)
	{
		lis[staridx+i].style.display='';
	}
}
function GotoVideoPage_(dir)
{
	lis = $('#vlst_').children();
	if(lis.length == 0)
		return;
	if((vpindex+dir)*6>=lis.length || (vpindex+dir)<0)
		return;
	vpindex = vpindex+dir;
	staridx = vpindex*6 ;
	for(i=0; i<lis.length; i++)
	{
		lis[i].style.display='none';
	}
	for(i=0; i<6&&(staridx+i)<lis.length; i++)
	{
		lis[staridx+i].style.display='';
	}
}
function GotoVideoPage_ix(dir)
{
	lis = $('#vlst_ix').children();
	if(lis.length == 0)
		return;
	if((vpindex+dir)*6>=lis.length || (vpindex+dir)<0)
		return;
	vpindex = vpindex+dir;
	staridx = vpindex*6 ;
	for(i=0; i<lis.length; i++)
	{
		lis[i].style.display='none';
	}
	for(i=0; i<6&&(staridx+i)<lis.length; i++)
	{
		lis[staridx+i].style.display='';
	}
}

function setSP_callback(text)
{
	$('#suggestion').text('mobaapp would like to hear your suggestions.');
	$('#r_feedback_main').hide();
	$('#r_thanks').show();
	setTimeout("$('#r_thanks').hide();$('#r_feedback_main').show();",20000);
	$('#postbotton').attr('disabled',false);
}

function getSuggestion()
{
	content=$('#suggestion').val();
	$.ajax( {type: "POST",
	url: "/msg",
	data: 'content='+escape(content),
	dataType: "text",
	success:setSP_callback});
	$('#postbotton').attr('disabled',true)
}

function getInfo()
{
	name=$('#name').val();
	content=$('#content1').val();
	email=$('#email1').val();
	email2=$('#email_2').val();
	company=$('#company1').val();
	department=$('#department1').val();
	url=$('#url1').val();
	tag=true;
	if(name.length<2){
		$('#name_s').show();
		tag=false;
	}else{
		$('#name_s').hide();
	}
	if(email==''){
		$('#email_s').show();
		tag=false;
	}else{
		$('#email_s').hide();
	}
	if(email2!=email){
		$('#email2_s').show();
		tag=false;
	}else{
		$('#email2_s').hide();
	}
	if(content.length<5){
		$('#content_s').show();
		tag=false;
	}else{
		$('#content_s').hide();
	}
	
	if(tag==true){
		$.ajax( {type: "POST",
		url: "/storeinfo",
		data: 'content='+escape(content)+'&name='+escape(name)+'&email='+escape(email)+'&company='+escape(company)+'&department='+escape(department)+'&url='+escape(url),
		dataType: "text",
		success:feedback_checkinfo});
		$('#postbotton1').attr('disabled',true)
	}	
}
	function feedback_checkinfo(text){
		$('#postbotton1').hide();
		$('#info_thanks').show();
		setTimeout("$('#info_thanks').hide();$('#postbotton1').show();",10000);
		$('#postbotton1').attr('disabled',false);		
	}
	
function makeCal(stat){
	if(stat=='onload'){
		var d =new Date();
		year = d.getFullYear();
		month = d.getMonth()+1;
		$('#span_year').html(year);
		$('#input_year').val(year);
		switch(Number(month)){
		case 1: s_month='January';break; case 2: s_month='February';break;
		case 3: s_month='March';break; case 4: s_month='April';break;
		case 5: s_month='May';break; case 6: s_month='June';break; case 7: s_month='July';break;
		case 8: s_month='August';break; case 9: s_month='September';break;
		case 10: s_month='October';break; case 11: s_month='November';break; case 12: s_month='December';break;
		}
		//$('#span_month').html(s_month);
		$('#span_month').html(Number(month));
		$('#input_month').val(Number(month));
	}
	else{
		var year=$('#input_year').val();
		var month=$('#input_month').val();
		if(stat=='next')
		{
			month=Number(month)+1;
		}
		if(stat=='last')
		{
			month=Number(month)-1;
		}
		if(Number(month)>12)
		{
			year=Number(year)+1;
			month=1;
		}
		if(Number(month)<0)
		{
			year=Number(year)-1;
			month=12;
		}
		$('#span_year').html(year);
		$('#input_year').val(year);
		switch(Number(month)){
		case 1: s_month='January';break; case 2: s_month='February';break;
		case 3: s_month='March';break; case 4: s_month='April';break;
		case 5: s_month='May';break; case 6: s_month='June';break; case 7: s_month='July';break;
		case 8: s_month='August';break; case 9: s_month='September';break;
		case 10: s_month='October';break; case 11: s_month='November';break; case 12: s_month='December';break;
		}
		//$('#span_month').html(s_month);
		$('#span_month').html(Number(month));
		$('#input_month').val(Number(month));
	}
	$.ajax( {type: "GET",
	url: "/makeCal?year="+year+"&month="+month,
	dataType: "text",
	success:makeCal_callback});
}

function makeCal_callback(text){
	var count=0;
	var date=1;
	html='';
	html+='<tr>';
	html+='<td class="weeek">Su</td>';
	html+='<td width="25" height="25" align="center" valign="middle" bordercolor="#CCCCCC" bgcolor="#f7f7f7">M</td>';
	html+='<td width="25" height="25" align="center" valign="middle" bordercolor="#CCCCCC" bgcolor="#f7f7f7">Tu</td>';
	html+='<td width="25" height="25" align="center" valign="middle" bordercolor="#CCCCCC" bgcolor="#f7f7f7">W</td>';
	html+='<td width="25" height="25" align="center" valign="middle" bordercolor="#CCCCCC" bgcolor="#f7f7f7">Th</td>';
	html+='<td width="25" height="25" align="center" valign="middle" bordercolor="#CCCCCC" bgcolor="#f7f7f7">F</td>';
	html+='<td width="25" height="25" align="center" valign="middle" bordercolor="#CCCCCC" bgcolor="#f7f7f7">Sa</td>';
	html+='</tr><tr>';
    var appcount=text.split(',');
	var year=$('#input_year').val();
	var month=$('#input_month').val();
	var dayValue = year+'/'+month+'/'+'1';
	if(month<10){month='0'+month;}
	var day = new Date(Date.parse(dayValue)); 
	var m=day.getDay(); 
	if(m != 7){
		for(i=0;i<m;i++){html+='<td class="wbg">&nbsp;</td>';}
	}
	for(i=m+1;i<=7;i++){
			if(appcount[count]&&appcount[count]!=' '){
			html+='<td class="wbg">'+'<DIV class="info01"><a>'+date+'</a></DIV>';
			if(date<10){date_='0'+date;}else{date_=date;}
			if(appcount[count]=='>1000'){appcount_=1000;}else{appcount_=appcount[count];}
			html+='<DIV class="info02"><a href="/cal'+year+month+date_+'/'+appcount_+'/">'+appcount[count].replace(' ','')+'</a></DIV></td>';
			}
			else{
			html+='<td class="no_date">'+date+'</td>';
			}
			count++;
			date++;
	}
	html+='</tr><tr>';
	for(i=0;i<appcount.length;i++){
		if(i!=0&&i%7==0){
			html+='</tr><tr>';
		}
		if(appcount[count]&&appcount[count]!=' '){
		html+='<td class="wbg">'+'<DIV class="info01"><a>'+date+'</a></DIV>';
		if(date<10){date_='0'+date;}else{date_=date;}
		if(appcount[count]=='>1000'){appcount_=1000;}else{appcount_=appcount[count];}
		html+='<DIV class="info02"><a href="/cal'+year+month+date_+'/'+appcount_+'/">'+appcount[count].replace(' ','')+'</a></DIV></td>';
		}
		else{
		html+='<td class="no_date">'+date+'</td>';
		}
		count++;
		date++;
		if(date>appcount.length){break;}
	}
	for(i=0;i<(7-(appcount.length+m)%7)%7;i++){
		html+='<td class="wbg">&nbsp;</td>';
	}
	html+='</tr>';
	$('#caltable').html(html);
}

function CalDays(year,month){
switch(month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12: days=31;break;
case 4: case 6: case 9: case 11: days=30;break;
case 2: if(isLeapYear(year)) days=29;
else days=28;
break;
}
return days;
}

function isLeapYear(year){
if((year %4==0 && year %100!=0) || (year %400==0)) return true;
else return false;
}

function index_title(id){
	$.ajax( {type: "GET",
	url: "/ixt?id="+id.toString(),
	dataType: "text",
	success:index_title_callback});
	}

function index_title_callback(text){
	var arr=text.split('__');
	f_appname=arr[0];
	f_appid=arr[1];
	f_picurl=arr[2];
	f_urlname=arr[3];
	f_oldprice=arr[4];
	f_newprice=arr[5];
	f_summary=arr[6];
	f_uprange=arr[7];
	f_catid=arr[8];
	f_catname=arr[9];
	p_c=arr[10];
	p_i=arr[11];
	p_v=arr[12];
	$('#soft_left_appimg').html('<a href="/app/'+f_appid+'/'+f_urlname+'.html " style="cursor:pointer" ><img src="http://a1.phobos.apple.com/'+f_picurl+'.100x100-75.jpg" border="0" width="80" height="80" alt="'+f_appname+'" class="corner iradius16"></a>');
	$('#soft_left_appname').html('<a  href="/app/'+f_appid+'/'+f_urlname+'.html " target="_self">'+f_appname+'</a>');
	$('#soft_left_appcat').html('<a  href="/star/cat'+f_catid+'/" target="_self" >[  '+f_catname+'  ]</a>');
/*
	if(f_uprange<0){
		$('#soft_left_oldprice').html(f_oldprice);
		$('#pdpic').show();
	}
	else{
		$('#pdpic').hide();
		$('#soft_left_oldprice').hide();
	}
*/
	$('#soft_left_newprice').html(f_newprice);
	$('#soft_left_des').html(f_summary);
	$('#icon_apps_fouth').html('<a title="'+p_v+'" href="/app/'+f_appid+'/'+f_urlname+'.html#posvideo"></a>');
	$('#icon_apps_three').html('<a title="'+p_c+'" href="/app/'+f_appid+'/'+f_urlname+'.html#pfpl_data"></a>');
	$('#icon_apps_two').html('<a title="'+p_i+'" href="/app/'+f_appid+'/'+f_urlname+'.html#posdes"></a>');
	$('#icon_apps_one').html('<a title="App Store" href="http://click.linksynergy.com/fs-bin/stat?id=zeoGCQ/DI8U&amp;offerid=94348&amp;type=3&amp;subid=0&amp;tmpid=2192&amp;RD_PARM1=http%253A%252F%252Fitunes.apple.com%252FWebObjects%252FMZStore.woa%252Fwa%252FviewSoftware%253Fid%253D'+f_appid+'%2526mt%253D8%2526partnerId%253D30" target="_blank"></a>')
}

function sendEmailToCustom_callback(text)
{
	$('#email_s').text(' ');
	$('#email_s').hide();
	$('#sub_s').hide();
	$('#thank_s').show();
	setTimeout("$('#divSuspended').hide();$('#email_s').show();$('#sub_s').show();$('#thank_s').hide();",7000);
	$('#sub_s').attr('disabled',false);
}

function sendEmailToCustom()
{
	id=$('#id_s').val();
	email=$('#email_s').val();
	var regx=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(regx.test(email)&&email!=''){
	$.ajax( {type: "GET",
	url: '/sendmail?id='+id.toString()+'&email='+email,
	dataType: "text",
	success:sendEmailToCustom_callback});
	$('#sub_s').attr('disabled',true);
	}
	else
	{
		alert('wrong email type');
	}
}

function sendEmailToCustom_callback_1(text)
{
	$('#mail_0_b_1').hide();
	$('#mail_0_b_2').show();
	$('#mail_0_a').attr('disabled',false);
}

function sendEmailToCustom_1(id)
{
	$('#mail_0_b_1').hide();
	$('#mail_0_b_2').hide();
	email=$('#mail_0').val();
	var regx=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(regx.test(email)&&email!=''){
	$.ajax( {type: "GET",
	url: '/sendmail?id='+id+'&email='+email,
	dataType: "text",
	success:sendEmailToCustom_callback_1});
	$('#mail_0_a').attr('disabled',true);
	}
	else
	{
		$('#mail_0_b_1').show();
		$('#mail_0_b_2').hide();
	}
}
