

/* reference of product class
nDate ::
	this.date //date
	this.day = day;
	this.month = month;
	this.year = year;

PEventClass ::
	this.eventdate //1
	this.eventdate2 //2
	
	this.eventitle //3
	this.eventvenue //4
	
	this.eventsite //5
	
	this.relatedsite //6, 7, 8, 9, 10
	
	this.sortofevent //11
	this.language //12
	this.country //13
	this.status //14
	this.keyword //15, 16, 17
};
*/

var thePevent = eval(PEVENT_CLASS);
var tempPevent = new Array; 
var blankPevent = new Array; 
var minus_length = 0;

var pnImgRoot = 'images/pevent/';
var pnLargeRoot = 'images/pevent/plarge/';
var pnLhumbRoot = 'images/pevent/pthumb/';
var news_event_Root = 'news_events/pevents/';

//var plt_cat_img1 = "images/pproducts/plt-epb-prc11.png";
//var plt_cat_img2 = "images/pproducts/plt-epb-prc12.png";

/////////////////////////PeventContentSelector -> to switch between different section
//Testing on the function

//getYear from server
var currentYear = oServerTime.getFullYear();
n=0;
function PeventContentSelector( yyyy, mm, stat ){
	var year = yyyy;
	//0 = all; 1-12 = months
	var month = mm; 
	// -1 : past // 0 : current/today // 1 : coming/future	
	var status = stat;
	
	var tt=0;
	//alert(thePevent.length)
	for ( ss=1; ss<thePevent.length; ss++ ){
		//case year<0; status = -1
		if ( parseInt(year)<0 && thePevent[ss].eventstatus == status ) { 
			if ( (thePevent[ss].eventdate.year >= year) && (thePevent[ss].eventstatus == status) ){
				tempPevent[tt]=thePevent[ss];
				alert(tempPevent[tt].eventitle);
			}
		}
		//case year>0; status = 1
		if ( (thePevent[ss].eventdate.year == year) && (thePevent[ss].eventstatus == status) ){
			//month set to 0; it is to show all month's news
			if ( mm==0 ){
				tt++;
				tempPevent[tt]=thePevent[ss];
			}
			//month set to 1-12; it is to show selected month's news
			if ( mm>0 && mm<13 ){
				if ( thePevent[ss].eventdate.month == mm ){
					tt++;
				tempPevent[tt]=thePevent[ss];
				}
			}
		}
	}
	
	//to make the unmatch data to be taken out.
	for ( st=1; st<tempPevent.length; st++ ){
		if (tempPevent[st]!=null){
			if (tempPevent[st].eventdate.year!=year){
				//alert(st+', year not same'+ tempPevent[st].eventdate.year);
				tempPevent[st]=null;
			}
		}
		if (tempPevent[st]==null){
			minus_length++;
		}
	}
	//alert(tempPevent[8].eventdate.year);
	document.getElementById("PeventList").innerHTML = peventlist(year, status);
}

/////////////////////////peventlist() -> id=PeventList
function peventlist( yyyy, stat ) {
	var theHtm = '';
	
	var layoutHtm = '';
	
	//var imgTabNext = "plt-ea-100.png";
	//var imgTab2005 = "plt-ea-110.png";
	//var imgTab2004 = "plt-ea-120.png";
	imgTabNext = "plt-ea-1a"+ ( (yyyy==currentYear && stat==-1)?1:0 ) + ".png";
	imgTab2010 = "plt-ea-16"+ ( (yyyy==2010 && stat==1)?1:0 ) + ".png";
	imgTab2009 = "plt-ea-15"+ ( (yyyy==2009 && stat==1)?1:0 ) + ".png";
	imgTab2008 = "plt-ea-14"+ ( (yyyy==2008 && stat==1)?1:0 ) + ".png";
	imgTab2007 = "plt-ea-13"+ ( (yyyy==2007 && stat==1)?1:0 ) + ".png";
	
	//alert(imgTabNext+', '+ imgTab2006 + ', '+ imgTab2005);
	
	
	//the Year of Archives
	layoutHtm += "<table width=744 border=0 cellpadding=0 cellspacing=0 bgcolor=\"#ffffff\">";
	layoutHtm += "<tr><!--ea-->"
	layoutHtm += "<td colspan=7 height=34 background=\"images/bgcolor.gif\">";
	layoutHtm += "  <table width=744 height=34 cellpadding=0 cellspacing=0>";
	layoutHtm += "  <tr>";
	layoutHtm += "<td valign=bottom><a href=\"pevents.htm?year="+ currentYear +"&status=-1\">";
	layoutHtm +="<img src=\"images/pevent/"+ imgTabNext +"\" border=0\">";
	layoutHtm +="</td></a>";
	layoutHtm += "<td width=5></td>";
	if ( currentYear>=2010 ){
		layoutHtm += "<td valign=bottom><a href=\"pevents.htm?year=2010&status=1\">";
		layoutHtm +="<img src=\"images/pevent/"+ imgTab2010 +"\" border=0\">";
		layoutHtm +="</td></a>";
		layoutHtm += "<td width=5></td>";
	}
	if ( currentYear>=2009 ){
		layoutHtm += "<td valign=bottom><a href=\"pevents.htm?year=2009&status=1\">";
		layoutHtm +="<img src=\"images/pevent/"+ imgTab2009 +"\" border=0\">";
		layoutHtm +="</td></a>";
		layoutHtm += "<td width=5></td>";
	}
	if ( currentYear>=2008 ){
		layoutHtm += "<td valign=bottom><a href=\"pevents.htm?year=2008&status=1\">";
		layoutHtm +="<img src=\"images/pevent/"+ imgTab2008 +"\" border=0\">";
		layoutHtm +="</td></a>";
		layoutHtm += "<td width=5></td>";
	}
	if ( currentYear>=2007 ){
		layoutHtm += "<td valign=bottom><a href=\"pevents.htm?year=2007&status=1\">";
		layoutHtm +="<img src=\"images/pevent/"+ imgTab2007 +"\" border=0\">";
		layoutHtm +="</td></a>";
		layoutHtm += "<td width=5></td>";
	}

	layoutHtm += "  </tr>";
	layoutHtm += "  </table>";
	layoutHtm += "</td>";
	layoutHtm += "<!--/ea--></tr>";
	//

	//the Title of menu
	layoutHtm += "<tr><!--eb-->";
	layoutHtm += "<td colspan=2 width=180><img src=\"images/pevent/plt-eb11.png\" width=180 height=34></td>";
	layoutHtm += "<td width=2><img src=\"images/pevent/plt-eb10.png\" width=2 height=34></td>";
	layoutHtm += "<td width=476><img src=\"images/pevent/plt-eb12.png\" width=476 height=34></td>";
	layoutHtm += "<td width=2><img src=\"images/pevent/plt-eb10.png\" width=2 height=34></td>";
	layoutHtm += "<td colspan=2 width=84><img src=\"images/pevent/plt-eb14.png\" width=84 height=34></td>";
	layoutHtm += "<!--/eb--></tr>";
	//
	
	d_totalpn = (tempPevent.length-1)-minus_length;
	minus_length=0;
	d_step = 7;
	
	//Here's the main Programming
	layoutHtm+= "<tr><!--ec1-->";
    layoutHtm+= "<td width=100 height=1 background=\""   +pnImgRoot+   "plt-ec12.png\"></td>";
	layoutHtm+= "<td width=80 align=center><font class=\"green996-bo-12\"></font></td>";
										
	layoutHtm+= "<td width=2 background=\"images/pevent/plt-ec12.png\"></td>";
	layoutHtm+= "<td width=476><a class=\"green996-normal-11\"></a></td>";
	layoutHtm+= "<td width=2 background=\"images/pevent/plt-ec12.png\"></td>";
	
	layoutHtm+= "<td width=82></td>";
	layoutHtm+= "<td width=2 background=\"images/pevent/plt-ec12.png\"></td>";
	layoutHtm+= "<!--/ec1--></tr>";
	
	
	var innerLayHtm = new Array();
	var nmonth= '';

	for ( ne=1; ne<d_totalpn+1; ne++ ){ //cycle all the Obj in memory
		//month bg condition
		if ( tempPevent[ne-1]!=null){ 													//Prev Obj is not null then
			if ( tempPevent[ne].eventdate.month != tempPevent[ne-1].eventdate.month ){	//Current Obj's Properties_1 not equal Prev Obj's Properties_1 then
				month_img = tempPevent[ne].eventdate.month_img; 						//variable set to current Obj's properties
			}
			if ( tempPevent[ne].eventdate.month == tempPevent[ne-1].eventdate.month ){	//Current Obj's Properties_1 EQUAL to Prev Obj's Properties_1 then
				if ( tempPevent[ne].eventdate.month>0 && tempPevent[ne].eventdate.month<10 ){
					nmonth = '0' + tempPevent[ne].eventdate.month;
				}else if ( tempPevent[ne].eventdate.month>9 ){ 
					nmonth = tempPevent[ne].eventdate.month; 
				}
				month_img = pnImgRoot + 'plt-ec21' + nmonth + '.png';					//variable assigned manually (not in Obj's properties_2)
			}
		}else if ( tempPevent[ne-1]==null){ 				//Prev Obj is null then 
			month_img = tempPevent[ne].eventdate.month_img; //variable set to current Obj's properties_2
		}
		//
		
		var the_HREF ="";
		//rendering the ouput
	  	if( tempPevent[ne]!=null ){
			innerLayHtm[ne] = '';
			innerLayHtm[ne] += "<tr style=\"background:#ffffff;\" onMouseOver=\"this.style.background='#e7e7c7'\" ";
			innerLayHtm[ne] +=     " onMouseOut=\"this.style.background='#ffffff'\"><!--ec1-->";
			
			innerLayHtm[ne] += "<td width=100 height=40><img src=\""   +month_img;
			innerLayHtm[ne] += "\" width=100 height=40 alt=\""   +tempPevent[ne].eventdate.month+    "\"></td>";
			innerLayHtm[ne] += "<td width=80 align=center><font class=\"green996-bo-12\">"  +tempPevent[ne].eventdate.day+  "</font></td>";
			
			innerLayHtm[ne] += "<td width=2 background=\""   +pnImgRoot+   "plt-ec12.png\"></td>";
			
			innerLayHtm[ne] += "<td width=476><p class=\"green996-normal-11\" style=\"margin-left:12px;\">";
			innerLayHtm[ne] += "<a  ";
			
			if ( tempPevent[ne].eventsite != '-undefined-' ){
				 the_HREF = "class=\"green996-normal-11-hu\" href=\""  +tempPevent[ne].eventsite+   "\"";
			}else {
				the_HREF = "class=\"green996-normal-11\" ";
			}
			innerLayHtm[ne] += the_HREF;
			innerLayHtm[ne] += " target=_parent><b>";
			innerLayHtm[ne] += tempPevent[ne].eventitle+   "</b><br>";
			innerLayHtm[ne] += "venue : "   +tempPevent[ne].eventvenue+   "</a></td>";
			
			innerLayHtm[ne] += "<td width=2 background=\""   +pnImgRoot+   "plt-ec12.png\"></td>";
			
			innerLayHtm[ne] += "<td width=82 class=\"green996-normal-11\" align=center>";
			innerLayHtm[ne]	+= tempPevent[ne].sortofevent+   "</td>";
			
			innerLayHtm[ne] += "<td width=2 background=\""   +pnImgRoot+   "plt-ec12.png\"></td>"; 
	
			innerLayHtm[ne] += "<!--/ec1--></tr>";
			
			layoutHtm+=innerLayHtm[ne];
		}
		//
	}
	
	//
	//the Bottom and the End of Table
	layoutHtm+= "<tr><!--ed-->";
	layoutHtm+= "<td colspan=7>";
	layoutHtm+= "<table border=0 cellpadding=0 cellspacing=0>";
	layoutHtm+= "<tr>";
	layoutHtm+= "<td colspan=2 width=126 height=35><img src=\"images/pevent/plt-ed11.png\" width=126 height=35></td>";
	layoutHtm+= "<td colspan=7 width=618 height=35 background=\"images/pevent/plt-ed12-bg.png\">";
	layoutHtm+= "</td>";
	layoutHtm+= "</tr>";
	layoutHtm+= "</table>";
	layoutHtm+= "</td>";
	layoutHtm+= "<!--/ed--></tr>";
	layoutHtm+= "</table>";
	//
	
	theHtm = layoutHtm;

	return theHtm;
}
