

/* reference of contact class
SCenterClass ::
	
	this.country
	this.state
	this.address
	this.tel
	this.fax
	this.addtel
	this.type
*/

var theScenter = SCENTER_CLASS;
var nLoop=0; //Looping Mem

var pcImgRoot = 'images/pcontact/';


var tempCountryNm = new Array("All", "Yemen", "Lebanon", "Kuwait", "Iran", "India", "Sri Lanka", 
							  "Myanmar", "China", "Hong Kong", "Vietnam", "Thailand", "Malaysia", "Indonesia");
var tempCountryNo = new Array(0, 1, 2, 3, 4, 5, 6, 
							  7, 8, 9, 10, 11, 12, 13);

function showContactList ( givemeID, showMethod ){
	nLoop=0; //reset this value;
	
	var theHtm = '';
	var theLayoutHtm = '';
	var theIDnm = givemeID;

//Matching the Method storing to memory
	var method = showMethod;
	var tempArry = new Array(); //to Assign a TEMPORARY list of CONTACT

	var nt=0;
	
	//MAP METHOD... which one is chosen then proceed the selected one 
	//show all by default
	if( method==tempCountryNo[0] || method==tempCountryNm[0] ){ 
		tempArry=theScenter; // point tempArry to ALL LIST OF CONTACT
	}
	for ( tc=1; tc<tempCountryNo.length; tc++ ){
		if ( method==tempCountryNo[tc] || method==tempCountryNm[tc] ){
			for ( td=1; td<theScenter.length; td++ ){
				if ( tempCountryNm[tc]==theScenter[td].country ){
					nt++;
					//alert ( tempCountryNm[tc] +' chosen, ' + nt +' found');
					tempArry[nt] = theScenter[td]; //point tempArry to CERTAIN PART of LIST
					//alert( tempArry.length-1 );
				}
			}
		}
	}
	
//end of Match and storing to memory

	var xCOL = 3;
	var totalItems = tempArry.length-1;
	var xColumn = new Array();
	var mod = totalItems%xCOL;
	var xtra = new Array();;
	
	// T%R = 0
	if ( mod==0 ){ 
		for( ol=0; ol<xCOL; ol++ ){
			xtra[ol] = 0;
			xColumn[ol] = Math.floor(totalItems/xCOL) + xtra[ol];
		}
	}

	// T%R > 0 
	if ( mod>0 ){ 
		for ( om=0; om<xCOL; om++ ){
			if ( om==0 ){ 
				xtra[om] = 1; 
				xColumn[om] = Math.floor(totalItems/xCOL) + xtra[om];
			}
			
			if ( om>0 && om<xCOL-1){
				if ( mod<2 ){
					xtra[om] = 0;
					xColumn[om] = Math.floor(totalItems/xCOL) + xtra[om];
				}
				if ( mod>1 ){
					modd = mod;
					if ( modd-1!=1 ){
						xtra[om] = Math.floor( modd/(modd-1) );
						xColumn[om] = Math.floor(totalItems/xCOL) + xtra[om];
						modd--;
					}
				}
			}
			
			if ( om==xCOL-1 ){ 
				xtra[om] = 0;
				xColumn[om] = Math.floor(totalItems/xCOL) + xtra[om];
			}
		}
	}
//	alert(xtra[0]+','+xtra[1]+','+xtra[2]+','+xtra[3]+','+xtra[4]);
//	alert(xColumn[0]+','+xColumn[1]+','+xColumn[2]+','+xColumn[3]+','+xColumn[4]);
//start
	theHtm += "<table width=744 border=0 cellpadding=0 cellspacing=0 bgcolor=#ffffff>";
	theHtm +=	"	<tr><!--ea-->";
	theHtm +=	"	<td colspan=7 height=20><img src=\"images/pcontact/plt-ea11.png\" width=744 height=34></td>";
	theHtm +=	"	<!--/ea--></tr>";
	theHtm +=	"	<tr><!--eaa-->";
	theHtm +=	"	<td width=2 height=10 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<td id=PcontactListCol_1 width=244 valign=top></td>";
	theHtm +=	"	<td width=4 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<td id=PcontactListCol_2 width=244 valign=top></td>";
	theHtm +=	"	<td width=4 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<td id=PcontactListCol_3 width=244 valign=top></td>";
	theHtm +=	"	<td width=2 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<!--/eaa--></tr>";
	//the content
	
	theLayoutHtm += "<tr><!--eb-->";
	theLayoutHtm += "	<td width=2 background=\"images/pcontact/plt-eb11.png\"></td>";
	theLayoutHtm += "	<td id=PcontactListCol_1 width=244 valign=top>";
	
	var x1_Htm = '';
	
//----------------
	x1_Htm = toGenerateHmt_PcontactList( tempArry, xColumn, 0 );

	theLayoutHtm += x1_Htm;
	
	theLayoutHtm += "	</td>";
	theLayoutHtm += "	<td width=4 background=\"images/pcontact/plt-eb11.png\"></td>";
	theLayoutHtm += "	<td id=PcontactListCol_2 width=244 valign=top>";

	var x2_Htm = '';
//----------------
	x2_Htm = toGenerateHmt_PcontactList( tempArry, xColumn, 1 );
	theLayoutHtm += x2_Htm;
	
	theLayoutHtm += "	</td>";
	theLayoutHtm += "	<td width=4 background=\"images/pcontact/plt-eb11.png\"></td>";
	theLayoutHtm += "	<td id=PcontactListCol_3 width=244 valign=top>";
	
	var x3_Htm = '';
//----------------
	x3_Htm = toGenerateHmt_PcontactList( tempArry, xColumn, 2 );
	theLayoutHtm += x3_Htm;
	
	theLayoutHtm += "	</td>";
	theLayoutHtm += "	<td width=2 background=\"images/pcontact/plt-eb11.png\"></td>";
	theLayoutHtm += "<!--/eb--></tr>";
	
	theHtm += theLayoutHtm;
	theHtm +=	"	<tr><!--eab-->";
	theHtm +=	"	<td width=2 height=10 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<td id=PcontactListCol_1 width=244 valign=top></td>";
	theHtm +=	"	<td width=4 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<td id=PcontactListCol_2 width=244 valign=top></td>";
	theHtm +=	"	<td width=4 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<td id=PcontactListCol_3 width=244 valign=top></td>";
	theHtm +=	"	<td width=2 background=\"images/pcontact/plt-eb11.png\"></td>";
	theHtm +=	"	<!--/eab--></tr>";
	theHtm +=	"	<tr><!--ec-->";
	theHtm +=	"	<td colspan=7 height=35>";
	theHtm +=	"	<img src=\"images/pcontact/plt-ec11.png\" width=744 height=35>";
	theHtm +=	"	</td>";
	theHtm +=	"	<!--/ec--></tr>";
	theHtm +=	"</table>";
//end
	document.getElementById(theIDnm).innerHTML = theHtm;
}

function toGenerateHmt_PcontactList( tempArry, xColumn, wRow ){
	var tmpArry = tempArry;
	var yQty = xColumn; //this is ARRAY !!
	var theHtm = '';
	
	if ( wRow==null || wRow<0 ){ 
		tmpArry = null;
		theHtm += '@'; 
	}
	
	if ( tmpArry!=null ){
		if ( nLoop!=tmpArry.length+1 ){
			for( a=0; a<yQty[wRow]; a++ ){
				nLoop++;
				if ( tmpArry[nLoop] != null ){
					var tmp_loop ='';
					//matching and locating the imglabel
					for ( loop=0; loop<tempCountryNm.length; loop++ ){
						if ( tmpArry[nLoop].country==tempCountryNm[loop] ){
							if ( tempCountryNo[loop]>0 && tempCountryNo[loop]<10 ){
								tmp_loop = '0';
							}else tmp_loop = '';
							
							tmpArry[nLoop].imglabel = pcImgRoot+   "country"   + tmp_loop + tempCountryNo[loop] +  ".png";
						}
					}
					
					if( a==0 ) {
						theHtm += "<table border=0 cellspacing=0 cellpadding=0>"; 
					}
					
					if ( tmpArry[nLoop-1] == null ){
						theHtm += "<tr><td width=244 height=24><img src=\""    +tmpArry[nLoop].imglabel+   "\" width=150 height=24 ";
						theHtm += " alt=\"" +tmpArry[nLoop].country+ "\"></td></tr>";
						//alert(tmpArry[nLoop].imglabel)
					}
					
					if ( tmpArry[nLoop-1] != null ){
						if ( tmpArry[nLoop].country == tmpArry[nLoop-1].country ){ 
						}
						if ( tmpArry[nLoop].country != tmpArry[nLoop-1].country ){
							theHtm += "<tr><td width=244 height=24><img src=\""   +tmpArry[nLoop].imglabel+   "\" width=150 height=24 ";
							theHtm += " alt=\"" +tmpArry[nLoop].country+ "\"></td></tr>";
						}
					}
					
					theHtm += "<tr><td>";
					theHtm += "<p class=\"redc33-bo-12\" style=\"margin:5px 15px 10px 15px; \">";
	
					if ( tmpArry[nLoop].state!=' - ' ){ theHtm += tmpArry[nLoop].state+  "<br>"; }
	
					theHtm += "<font class=\"redc00-normal-11\" style=\"letter-spacing:0.05em;\">";
					theHtm += tmpArry[nLoop].address+  "</font><br>";
					theHtm += "<span class=\"redc00-bo-11\">T: "  +tmpArry[nLoop].tel+  "<br>";
					theHtm += "F: "   +tmpArry[nLoop].fax+   "</span>";
					theHtm += "</p>";
					theHtm += "</td></tr>";
				}
				
				if ( a==yQty[wRow]-1 ) {
					theHtm += "</table>"; 
				}
			}
		}
	}else theHtm += '@'; 

	return theHtm;

}
