/*
$(document).ready(function(){
	alert("backend url : " + backendServerURL);
});
*/
function getJsonData(url)
{
	$.ajax({
	     type:'GET', 
	     dataType:'jsonp', 
	     url:url + '?jsoncallback=getMsg', 
	   error: function(xmlHttpRequest,error) {
	     alert('Ajax request ERROR');}
	  });
}

function getMsg(result) { 
	//alert(result);
  var divstr = "";
  if(result.name == 'news')
  {
    for(var i=0; i < result.items.length; i++)
    {
      divstr += "<table width='340' border='0' cellpadding='0' cellspacing='0' class='indexNewsList'><tr>";
      if(result.items[i].newsContentType=='F')
      	divstr += "<td width='65' align='center' valign='top' class='hilight05'>" + result.items[i].newsPublishDate + "</td>  <td width='275' align='left' valign='top' class='link02' style='padding-bottom:5px;'><a href='#' onclick='IndexSubmitForm(\""+backendServerURL+"NewsFAction@forwardToDetail.action\"," + result.items[i].key + ",\"newsUuid\",\"" + result.items[i].uuid + "\");return false;'>" + result.items[i].newsTitle + "</a></td>";
      else
      	divstr += "<td width='65' align='center' valign='top' class='hilight05'>" + result.items[i].newsPublishDate + "</td>  <td width='275' align='left' valign='top' class='link02' style='padding-bottom:5px;'><a href='/NCCC_backend/ExportFile@doDownLoadRegFile.action?FOLDER=NEWS&FILE="+result.items[i].newsFileName+"' target='_blank'>" + result.items[i].newsTitle + "</a></td>"; 	
      divstr += "</tr></table>";
    }
    divstr += "<table width='340' border='0' cellpadding='0' cellspacing='0' ><tr>";
    divstr += "<td align='right' valign='top' style='padding-right:10px;' ><span><span class='link03'><a href='#' onclick='location.href=\"";
    divstr += backendServerURL+result.action+"\";' >more</a>&nbsp;<a href='#' onclick='location.href=\""+backendServerURL+result.action+"\";' >";
    divstr += "</span><img src='images/index/index_icon01.gif' width='18' height='18' align='absmiddle'  border='0'/></a></span></td></tr></table>";
  }
  else if(result.name == 'message')
  {
    for(var i=0; i < result.items.length; i++)
    {
      divstr += "<table width='340' border='0' cellpadding='0' cellspacing='0' class='indexNewsList'><tr>";
      if(result.items[i].messageContentType=='F')
      	divstr += "<td width='65' align='center' valign='top' class='hilight05'>" + result.items[i].messagePublishDate + "</td>  <td width='275' align='left' valign='top' class='link02' style='padding-bottom:5px;'><a href='index.htm#' onclick='IndexSubmitForm(\""+backendServerURL+"MessageFAction@forwardToDetail.action\"," + result.items[i].key + ",\"messageUuid\",\"" + result.items[i].uuid + "\");return false;'>" + result.items[i].messageTitle + "</a></td>";
      else
      	divstr += "<td width='65' align='center' valign='top' class='hilight05'>" + result.items[i].messagePublishDate + "</td>  <td width='275' align='left' valign='top' class='link02' style='padding-bottom:5px;'><a href='/NCCC_backend/ExportFile@doDownLoadRegFile.action?FOLDER=MESSAGE&FILE="+result.items[i].messageFileName+"' target='_blank'>" + result.items[i].messageTitle + "</a></td>";
      divstr += "</tr></table>";
    }
    divstr += "<table width='340' border='0' cellpadding='0' cellspacing='0' ><tr>";
    divstr += "<td align='right' valign='top' style='padding-right:10px;' ><span><span class='link03'><a href='#' onclick='location.href=\"";
    divstr += backendServerURL+result.action+"\";' >more</a>&nbsp;<a href='#' onclick='location.href=\""+backendServerURL+result.action+"\";' >";
    divstr += "</span><img src='images/index/index_icon01.gif' width='18' height='18' align='absmiddle'  border='0'/></a></span></td></tr></table>";
  }
  else if(result.name == 'activity')
  {
    for(var i=0; i < result.items.length; i++)
    {
    	divstr += "<table width='340' border='0' cellpadding='0' cellspacing='0' class='indexNewsList'><tr>";
    	divstr += "<td width='65' align='center' valign='top' class='hilight05'>" + result.items[i].startDate + "</td>  <td width='275' align='left' valign='top' class='link02' style='padding-bottom:5px;'><a href='" + result.items[i].activityUrl + "' target='_blank'>" + result.items[i].activityName + "</a></td>";
    	divstr += "</tr></table>";
    }	
    divstr += "<table width='340' border='0' cellpadding='0' cellspacing='0' ><tr>";
    divstr += "<td align='right' valign='top' style='padding-right:10px;' ><span><span class='link03'><a href='#' onclick='location.href=\"";
    divstr += backendServerURL+result.action+"\";' >more</a>&nbsp;<a href='#' onclick='location.href=\""+backendServerURL+result.action+"\";' >";
    divstr += "</span><img src='images/index/index_icon01.gif' width='18' height='18' align='absmiddle'  border='0'/></a></span></td></tr></table>";
  }
  else if (result.name == 'glossary')
  {
    for(var i=0; i < result.items.length; i++)
    divstr += "<span class='hilight04' style='padding:10px 0 10px 0 ;'>『" + result.items[i].chName + "』</span>  <span class='link03' style='padding:14px 0 10px 0 ;'>" + result.items[i].gsyDescription + "</span><br/>";
  }
  else if (result.name == 'advertise')
  {
    for(var i=0; i < result.items.length; i++)
    {
    	//alert( result.items[i].headPhoto);
    	//alert( result.items[i].activeLink);
    	if(result.items[i].activeLink == "#")
    	{
    		//alert( result.items[i].headPhoto);
    		divstr += "<span style='padding:0px 1px 0px 0px;padding-bottom:8px '><img src='" + backendServerURL + result.items[i].headPhoto + "' border='0' width='234' height='72'/></span><br/>";
    	}
    	else
    	{
    		divstr += "<span style='padding:0px 1px 0px 0px;padding-bottom:8px '><a href='" + result.items[i].activeLink + "' target='_blank'><img src='" + backendServerURL + result.items[i].headPhoto + "' border='0' width='234' height='72'/></a></span><br/>";
    	}
    }
  }
  else if(result.name == 'marquee')
  {
	  if( result.items.length < 1) { return; }
	  divstr += "<table width='950' border='0' cellpadding='0' cellspacing='0' style='margin:15px 25px 0 25px;'><tr>";
	  divstr += "<td width='82' align='left' valign='middle'><img src='images/index/hotNews_icon.gif' width='82' height='26' /></td>";
	  divstr += "<td width='858' height='26' align='left' valign='middle' bgcolor='#E5E5E5' class='link02'>";
	  divstr += "<MARQUEE scrollAmount='3' scrolldelay='100'>";
	  for(var i=0; i < result.items.length; i++)
	  {
		  divstr += "<img src='images/index/cube.gif' width='13' height='7' />";
	      if( result.items[i].targetKey == "message") {
	    	  divstr += "<a href='#' onclick='IndexSubmitForm(\"" + 
	    	  backendServerURL + result.items[i].link+"\",\"" + 
	    	  //result.items[i].targetKey + "\",\"" + 
	    	  "2" + "\",\"" +  
	    	  result.items[i].uuidname + "\",\"" + 
	    	  result.items[i].uuid + "\");return false;'>" +
	      	  result.items[i].title + "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	      }else if( result.items[i].targetKey == "news" )
	      {
	    	  if( result.items[i].contentType == "O" )
	    	  {
	    		  divstr += "<a href='"+backendServerURL+result.items[i].link + "' target=\"" + 
	    		  result.items[i].targetKey + "'>" +
    		      result.items[i].title + "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    	  } else
	    	  {
	    		  divstr += "<a href='#' onclick='IndexSubmitForm(\"" +
	    		  backendServerURL + result.items[i].link+"\",\"" + 
	    		 // result.items[i].targetKey + "\",\"" + 
	    		  "1" + "\",\"" + 
	    		  result.items[i].uuidname+"\",\"" + 
	    		  result.items[i].uuid + "\");return false;'>" + 
    			  result.items[i].title + "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	          }
	      }else
	      {
	    	  divstr += "<a href='" + result.items[i].link + "' target='_blank'>" + 
	    	         result.items[i].title + "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	      }
	  }
	  divstr += "</MARQUEE></td>";
	  divstr += "<td width='10' align='left' valign='middle' bgcolor='#E5E5E5' class='link02'>&nbsp;</td></tr></table>";
	  //alert(divstr);
  }
  
  $('#tabs-' + result.name).html(divstr);
} 

function IndexSubmitForm(actionUrl, menuKey, tagKey, tagValue)
{
     //alert(actionUrl);
     document.paramForm.key.value = menuKey;
     document.getElementById(tagKey).value = tagValue;
     
     //alert("param form params : " + $('#paramForm').serialize());

     document.paramForm.action = actionUrl;
     document.paramForm.submit();
}

function ShowPic(sImage,tabName)
{
	$('#tabs-news').hide();
	$('#tabs-message').hide();
	$('#tabs-activity').hide();
	if(tabName=='tabs-news') $('#tabs-news').show();
	if(tabName=='tabs-message') $('#tabs-message').show();
	if(tabName=='tabs-activity') $('#tabs-activity').show();
	document.tabView.src = sImage;
}

$(document).ready(function() { 
	  
	 // alert("backendServerURL : " + backendServerURL);
	 // backendServerURL = "http://localhost:8080/NCCC_backend/";
      //News
      getJsonData(backendServerURL + 'NewsFAction@doGetListItem.action');
	  //Message
	  getJsonData(backendServerURL + 'MessageFAction@doGetListItem.action');
	  //Activity
	  getJsonData(backendServerURL + 'ActivityFAction@doGetListItem.action');
	  //Glossary
	  getJsonData(backendServerURL + 'GlossaryFAction@doGetListItem.action');			  
	  //Advertise
	  getJsonData(backendServerURL + 'AdvertiseFAction@doGetListItem.action');
	  //MarQuee
	  getJsonData(backendServerURL + 'MarQueeFAction@doGetListItem.action');
	  
	  $('#tabs-news').hide();
	  $('#tabs-message').hide();
	  $('#tabs-activity').show();
});