 


function featHeader(){
	//document.write("<h5> Featured Products </h5><p/>");
}

//today's date will be used to compare the start and end dates of feateured products

var todaysDate=new Date();
  var sCont=0;
  var sCont1=0;
  	var ProdLine_available=0;
  	var ProdFamily_available=0;
  	var ProdGroup_available=0;
  	var Application_available=0;
  	var IndSubset_available=0;
  	var Industry_available=0;
  	var Capability_available=0;
  	var Home_available=0;
  	var Any_available=0;
  	var counter_display=0;
	
	var Found=false;
	var Count=0;
	var Current = new Array(-1,-1,-1,-1,-1);
	var sTemp= new Array();


	var feat_title;
	var tag_prodline;
	var tag_prodfamily;
  var tag_prodgroup;
  var tag_application;
  var tag_indsubset;
	var tag_industry;
	var tag_capability;
	var feat_imgURL;
	var feat_text;
	var feat_linkURL;
	var feat_startDate;
	var feat_endDate;
	var feat_homePool;

	
	var sTemp1= new Array();
	var sTemp2= new Array();

	feat_title =new Array();
  tag_prodline =new Array();
	tag_prodfamily =new Array();
	tag_application = new Array();
	tag_prodgroup = new Array();
	tag_indsubset = new Array();
	tag_industry =new Array();
	tag_capability = new Array();	
	feat_imgURL =new Array();
	feat_text =new Array();
	feat_linkURL =new Array();
	feat_startDate =new Array();
	feat_endDate =new Array();
	feat_homePool=new Array();

	
	

feat_linkURL[0] = "../../../en/Products/FeaturedProducts/engineeringplasticscuttosizeprogram.html";
feat_title[0] = "Engineering Plastics Cut-to-Size Program" ; 
feat_startDate[0] = "09-17-2008" ; 
feat_endDate[0] = "12-31-2009" ; 
feat_homePool[0] = 1; 
tag_capability[0] = "##Supply Chain Management##" ; 
tag_prodgroup[0] = "" ; 
tag_prodfamily[0] = "" ; 
tag_prodline[0] = "" ; 
tag_industry[0] = "" ; 
tag_indsubset[0] = "" ; 
tag_application[0] = "" ; 
feat_imgURL[0] = "http://imageserver.geampod.kcbam.net/KBAMImagingServer/Scripts/resize.kix?FileName=http://kbam.geampod.com/KBAM/reflection/Assets/7778.jpg&Width1=60&Height1=60&Unit1=Pixels" ; 
feat_text[0] = "The SABIC Polymershapes engineering plastics cut-to-size program features no minimum order quantities, over 3,000 sku's in stock..." ; 
  
 feat_linkURL[1] = "../../../en/Products/FeaturedProducts/lexanpolycarbonatesheetfilm.html";
feat_title[1] = "Lexan* Polycarbonate Sheet & Film" ; 
feat_startDate[1] = "06-18-2008" ; 
feat_endDate[1] = "12-31-2009" ; 
feat_homePool[1] = 1; 
tag_capability[1] = "##Film Converting##" ; 
tag_prodgroup[1] = "" ; 
tag_prodfamily[1] = "" ; 
tag_prodline[1] = "" ; 
tag_industry[1] = "" ; 
tag_indsubset[1] = "" ; 
tag_application[1] = "" ; 
feat_imgURL[1] = "http://imageserver.geampod.kcbam.net/KBAMImagingServer/Scripts/resize.kix?FileName=http://kbam.geampod.com/KBAM/reflection/Assets/17903.eps&Width1=60&Height1=60&Unit1=Pixels" ; 
feat_text[1] = "SABIC Polymershapes is the largest distributor of Lexan* sheet and film.   These products serve a variety of industries with a..." ; 
  
 
//small piece of code to bubble sort the featured products according to their titles. this is necessary as the same
//arrays will be used for left hand nav

var tempExchange;
var dateArray;
for (var sort=0;sort < feat_title.length;sort++)
{
	for (var sortIn =sort+1;sortIn< feat_title.length; sortIn++)
	{
		if(feat_title[sort] > feat_title[sortIn])
		{
			tempExchange=feat_title[sort];
			feat_title[sort]= feat_title[sortIn];
			feat_title[sortIn]=tempExchange;


			tempExchange=feat_linkURL[sort];
			feat_linkURL[sort]= feat_linkURL[sortIn];
			feat_linkURL[sortIn]=tempExchange;

			tempExchange=feat_imgURL[sort];
			feat_imgURL[sort]= feat_imgURL[sortIn];
			feat_imgURL[sortIn]=tempExchange;

			tempExchange=feat_text[sort];
			feat_text[sort]= feat_text[sortIn];
			feat_text[sortIn]=tempExchange;
			
			
			tempExchange=tag_prodgroup[sort];
			tag_prodgroup[sort]= tag_prodgroup[sortIn];
			tag_prodgroup[sortIn]=tempExchange;


			tempExchange=tag_prodfamily[sort];
			tag_prodfamily[sort]= tag_prodfamily[sortIn];
			tag_prodfamily[sortIn]=tempExchange;

			tempExchange=tag_prodline[sort];
			tag_prodline[sort]= tag_prodline[sortIn];
			tag_prodline[sortIn]=tempExchange;


			tempExchange=tag_industry[sort];
			tag_industry[sort]= tag_industry[sortIn];
			tag_industry[sortIn]=tempExchange;

			tempExchange=tag_indsubset[sort];
			tag_indsubset[sort]= tag_indsubset[sortIn];
			tag_indsubset[sortIn]=tempExchange;

			tempExchange=tag_application[sort];
			tag_application[sort]= tag_application[sortIn];
			tag_application[sortIn]=tempExchange;

			tempExchange=feat_startDate[sort];
			feat_startDate[sort]= feat_startDate[sortIn];
			feat_startDate[sortIn]=tempExchange;

			tempExchange=feat_endDate[sort];
			feat_endDate[sort]= feat_endDate[sortIn];
			feat_endDate[sortIn]=tempExchange;

			tempExchange=feat_homePool[sort];
			feat_homePool[sort]= feat_homePool[sortIn];
			feat_homePool[sortIn]=tempExchange;
			
			tempExchange=tag_capability[sort];
			tag_capability[sort]= tag_capability[sortIn];
			tag_capability[sortIn]=tempExchange;



			
		
		}
 


	}
 //convert to dates

      dateArray=feat_startDate[sort].split("-");
      feat_startDate[sort]=new Date(dateArray[2],dateArray[0]-1,dateArray[1]);
      dateArray=feat_endDate[sort].split("-");
      feat_endDate[sort]=new Date(dateArray[2],dateArray[0]-1,dateArray[1]); 

}




function featProdBody(indexToDisplay){
   	document.write("<div class=\"imageBlock\"><p class=\"image\">");
  	document.write("<img src=\"" + feat_imgURL[indexToDisplay] + "\"/></p><h5><a href=\""+feat_linkURL[indexToDisplay]+"\">" + feat_title[indexToDisplay] + "</a></h5><p>"+feat_text[indexToDisplay]+"</p></div><br/>");
}

function featAllLink(){
	document.writeln("<p align=\"right\">&gt;<a href=\"../../../en/Products/FeaturedProductsLanding/featuredproductslanding.html\">View All Products</a></p>");  
}



function displayFeatProducts_ProductLine(product){
	//alert("-"+product+"-");

	forProductLine(product,2);
	//alert(ProdLine_available);
  
	if (ProdLine_available>0)
  {
  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (ProdLine_available > 2 ? 2:ProdLine_available);
		  featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }		 
		  featAllLink();
	}
	

}

function displayFeatProducts_ProductFamily(productFamily){
	forProductFamily(productFamily,2);
	if (ProdFamily_available>0)
  {
  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (ProdFamily_available > 2 ? 2:ProdFamily_available);
		  featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }		 
		  featAllLink();
	}

}

function displayFeatProducts_ProductGroup(productGroup){
	forProductGroup(productGroup,2);
	if (ProdGroup_available>0)
  {
	  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (ProdGroup_available > 2 ? 2:ProdGroup_available);
  	  featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }		 
		  featAllLink();
	}

}

function displayFeatProducts_IndustryDetail(industry){
    forIndustry(industry,2);
		if (Industry_available>0)
    {
	  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (Industry_available > 2 ? 2:Industry_available);
		  featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }		 
		  featAllLink();
			}
	
}

function displayFeatProducts_IndustrySubset(industrySubset){
    forIndustrySubset(industrySubset,2);
		if (IndSubset_available>0)
    {
	  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (IndSubset_available > 2 ? 2:IndSubset_available);
      featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }		 
		  featAllLink();
			}
	
}

function displayFeatProducts_Application(app){
	forApplication(app,2);
	
	if(Application_available>0)
	{
	  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (Application_available > 2 ? 2:Application_available);
	    featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }
     	featAllLink();
  }
}

function displayFeatProducts_Capability(cap){
	forCapability(cap,2);
	
	if(Capability_available>0)
	{
	  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (Capability_available > 2 ? 2:Capability_available);
	    featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }
     	featAllLink();
  }
}

function displayFeatProducts_HomePage(){
	forHomePage(2);
	
	if(Home_available>0)
	{
	  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (Home_available > 2 ? 2:Home_available);
	    featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }
     	featAllLink();
  }
}


function displayFeatProducts_Generic(){
  Any_available=0;
  forAll(2);
	
	if(Any_available>0)
	{
	  //since we have to display only two max, if available to display is greater than 2, then set counter to 2
      counterDisplay = (Any_available > 2 ? 2:Any_available);
	    featHeader();
    	for (var countFeat=0;countFeat<counterDisplay;countFeat++)
    	{
    	   featProdBody(sTemp[Current[countFeat]]);
      }
     	featAllLink();
  }
}


//modified sammy
 //added sammy

 function forProductLine(sProdL,howMany){
 	sProdL="#"+sProdL+"#";
		for (i=0;i < feat_title.length;i++){
		//alert(tag_prodline[i]+"--"+sProdL);
		//The sProdL product line has to match the tag_prodLine arrays for that paritular featured product and that
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
			if ((tag_prodline[i].indexOf(sProdL)!=-1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
      {
			   
			//	alert("found a match");
				sTemp[sCont]=i;
				sTemp1[sCont]=i;
				sCont++;
				ProdLine_available++;
			}
		}
		if (sCont!=0){
		GetUnique(sCont-1,howMany);
		}
 }
 
 function forProductFamily(sProdF,howMany){
 	sProdF="#"+sProdF+"#";
					for (i=0;i < feat_title.length;i++){
		//The sProdF product family has to match the tag_prodFam array for that paritular featured product and that
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
						if ((tag_prodfamily[i].indexOf(sProdF)!=-1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
            {
							sTemp[sCont]=i;
							sTemp1[sCont]=i;
							sCont++;
							ProdFamily_available++;
						}
					}
					if (sCont!=0){
					GetUnique(sCont-1,howMany);
			}
 }
 
 function forProductGroup(sProdG,howMany){
 	sProdG="#"+sProdG+"#";
		for (i=0;i < feat_title.length;i++){
		//The sProdG product group has to match the tag_prodgroup arrays for that paritular featured product and that
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
			if ((tag_prodgroup[i].indexOf(sProdG)!= -1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
      {
			//	alert("found a match");
				sTemp[sCont]=i;
				sTemp1[sCont]=i;
				sCont++;
				ProdGroup_available++;
			}
		}
		if (sCont!=0){
		GetUnique(sCont-1,howMany);
		}
 } 
 
 
 function forIndustry(sIndus,howMany){
 	sIndus="#"+sIndus+"#";
				for (i=0;i < feat_title.length;i++){
			//The sIndus industry has to match the tag_idnustry  array for that paritular featured product and that
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
  				if ((tag_industry[i].indexOf(sIndus)!=-1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
          {
						sTemp[sCont]=i;
						sTemp1[sCont]=i;
						sCont++;
						Industry_available++;
					}
				}
				if (sCont!=0){
				GetUnique(sCont-1,howMany);
		}
 }
 
 function forIndustrySubset(sIndusSubset,howMany){
 	sIndusSubset="#"+sIndusSubset+"#";
				for (i=0;i < feat_title.length;i++){
		//The sIndussubset industry subset has to match the tag_indussubset array for that paritular featured product and that
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
					if ((tag_indsubset[i].indexOf(sIndusSubset)!=-1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
          {
						sTemp[sCont]=i;
						sTemp1[sCont]=i;
						sCont++;
						IndSubset_available++;
					}
				}
				if (sCont!=0){
				GetUnique(sCont-1,howMany);
		}
 } 
 
 function forApplication(sApp,howMany){
 	sApp="#"+sApp+"#";
				for (i=0;i < feat_title.length;i++){
		//The sApp application has to match the tag_application array for that paritular featured product and that
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
					if ((tag_application[i].indexOf(sApp)!=-1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate)){
						sTemp[sCont]=i;
						sTemp1[sCont]=i;
						sCont++;
						Application_available++;
					}
				}
				if (sCont!=0){
				GetUnique(sCont-1,howMany);
		}
 }
 
function forCapability(sCap,howMany){
 	sCap="#"+sCap+"#";
				for (i=0;i < feat_title.length;i++){
		//The sCap capability has to match the tag_capabilty array for that paritular featured product and that
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
					if ((tag_capability[i].indexOf(sCap)!=-1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
          {
						sTemp[sCont]=i;
						sTemp1[sCont]=i;
						sCont++;
						Capability_available++;
					}
				}
				if (sCont!=0){
				GetUnique(sCont-1,howMany);
		}
 }
 
function forHomePage(howMany){
 	
				for (i=0;i < feat_title.length;i++){
	     // the flag for having the product on the home page must be equal to 1 and the
		//new product must have valid start and end date i.e, today's date must be b/w start date and end date
					if ((feat_homePool[i]==1)&&(feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
          {
						sTemp[sCont]=i;
						sTemp1[sCont]=i;
						sCont++;
						Home_available++;
					}
				}
				if (sCont!=0){
				GetUnique(sCont-1,howMany);
		}
 }

 function forAll(howMany){
 		for (i=0;i < feat_title.length;i++)
     {
 		   if((feat_startDate[i]<todaysDate)&& (feat_endDate[i] > todaysDate))
 		   {
					sTemp[sCont]=i;
					sTemp1[sCont]=i;
					sCont++;
					Any_available++;
				}
		}
				if (sCont!=0){				
  	     GetUnique(sCont-1,howMany);
  	     }
 }

 function GetUnique(MaxValue,howMany)
   {
   	if (howMany>MaxValue){
   		howMany=MaxValue;
   	}
     for (i=0;Count<=howMany;Count++)
     {
       Found=false;
       var rndValue = get_random(MaxValue);
       var j=0;
       for (j=0;j<Current.length;j++)
       {
         if (Current[j] == rndValue)
         {
           Found=true;
           break;
         }
       }
       if (Found)
       {
         Count--;
       } else {
         Current[Count]=rndValue;
       }
     }
   }
   
   function get_random(MaxValue)
   {
     var ranNum= Math.round(Math.random()*(MaxValue));
     return ranNum;
   }
 //added sammy

