var CookExp = "expires=Tue, 31-Dec-2009 00:00:00 GMT;";
var arrPro = new Array (1,2,3,4,5,6,7,8,9,10);
var arrVal = new Array (1,2,3,4,5);
var arrCnt = new Array();
var arrCtlg = new Array();
var arrMB = new Array ();

function genHomeContent ()
{
	genProducts ();
	genValue ();
	makeVisible();
}

function genProducts ()
{
	if (!isCookieKey ("Catalogue"))
		makeCount ("2","4","1",arrPro)
	else 
		initCtlg ();
}

function initCtlg ()
{
	arrCnt = getCookieValue ("CatCount").split ("|");
	arrCtlg = getCookieValue ("Catalogue").split ("|");
	if (arrCtlg.length == 20 )
		makeCount ("2","4","1",arrPro);
	else
		switch (arrCnt.length)
		{
			case 20 :
				makeCount ("2","4","1",arrPro);
				break;
			case 0 :
				makeCount ("2","4","1",arrPro);
				break;
			case 1 :
				if (arrCtlg[0])
					makeCount (arrCnt[0],"4","1",arrPro);
				else
					makeCount ("2","4","1",arrPro);
				break;
			case 2 :
				makeCount (arrCtlg[0],arrCtlg[1],"1",arrPro);
				break;
			default:
				doCtlg ();
				break;
		}
}

function doCtlg ()
{
	arrMB = arrCnt;
	arrNew = new Array();
	for (i=0;i<3;i++)
		arrNew [i] = getNew()+"";
	makeCount (arrNew[0],arrNew[1],arrNew[2],arrMB);
}

function getNew ()
{
	isO = false;
	var a;
	do
	{
		a = genRandomNum();
		for (x=0;x<arrMB.length;x++)
			if (arrMB[x])
				if (arrMB[a] == arrMB [x])
				{
					a = arrMB[x] + "";
					delete arrMB [x];
					isO = true;
					break;
				}
	} while (!isO)
	return(a);
}

function genRandomNum ()
{
	ranNum = Math.random ();
	ranNum = ranNum + "";
	ranNum = ranNum.substr (ranNum.length-3,1);
	return (parseInt(ranNum));
}

function makeCount (a,b,c,arrP)
{
	sCat = "";
	arrProBuffer = new Array (a,b,c);
	for (j=0; j<arrP.length; j++)
	{
		for (j1=0; j1<arrProBuffer.length; j1++)
			if (arrP [j] == arrProBuffer[j1])
				delete arrP [j];
		if (arrP [j])
			sCat += arrP [j] + "|";
	}
	sCat = sCat.substring (0,sCat.length-1);
	SetCat (a,b,c,sCat);
}

function SetCat (pro1,pro2,pro3,count)
{
	document.getElementById("procat_1").innerHTML = eval("M_" + pro1 + "()");
	document.getElementById("procat_2").innerHTML = eval("M_" + pro2 + "()");
	document.getElementById("procat_3").innerHTML = eval("M_" + pro3 + "()");
	oldCtlg = "";
	if (isCookieKey ("Catalogue")&& arrCtlg.length != 20)
		for (j=0; j < arrCtlg.length; j++)
			oldCtlg += arrCtlg [j] + "|";
	document.cookie = "Catalogue=" + oldCtlg + pro1 + "-" + pro2 + "-" + pro3 + ";" + CookExp;
	document.cookie = "CatCount=" + count + ";" + CookExp;
}

function genValue ()
{
	if (!isCookieKey ("Values"))
		SetVal ("1","");
	else 
		initValues ();
}

function initValues ()
{
	arrValues = getCookieValue ("Values").split ("|");
	switch (arrValues.length)
	{
		case 5 :
			SetVal ("1","");
			break;
		case 0 :
			SetVal ("1","");
			break;
		default:
			getVal (arrValues);
			break;
	}
}

function getVal (arrP)
{
	ranValues = new Array();
	arrMB = arrVal;
	for (n=0;n<arrMB.length;n++)
		for (n1=0;n1<arrP.length;n1++)
			if (arrMB[n] == arrP [n1])
				delete arrMB[n];
	for (n=0;n<arrMB.length;n++)
		if (arrMB[n])
			ranValues [ranValues.length] = arrMB[n];
	isO = false;
	var newVal = "";
	do
	{
		newVal = genRandomVal () + "";
		for (i=0;i<ranValues.length;i++)
			if (ranValues[newVal] == ranValues [i])
			{
				isO = true;
				break;
			}
	} while (!isO)
	var oldVals = "";
	for (j=0;j<arrP.length;j++)
		oldVals += arrP [j] + "|";
	SetVal (ranValues[newVal],oldVals);
}

function genRandomVal ()
{
	ranVal = Math.random () + "";
	ranVal = ranVal.substr (ranVal.length-3,1);
	return (parseInt(ranVal));
}

function SetVal (val,oldval)
{
		document.getElementById("ValueText").innerHTML = eval("V_" + val + "()");
		document.cookie = "Values=" + oldval + val + ";" + CookExp;
}

//To make hidden td's visible
function makeVisible ()
{
		if (document.getElementById)
		{
			document.getElementById("procat_1").style.visibility="visible";
			document.getElementById("procat_2").style.visibility="visible";
			document.getElementById("procat_3").style.visibility="visible";
			document.getElementById("ITMustValues").style.visibility="visible";
		}
}

function makeTD (pHref,pTitle,pImg,pText)
{
	str = "<a href='" + pHref + "'>"
	str += "<img src='" + pImg + "' width='50' height='50' align='right' border='0'>"
	str += "</a><img src='images/home_sel.gif' border='0'>&nbsp;&nbsp;"
	str += "<a href='" + pHref + "'><span class='insection'>" + pTitle + "</span>"
	str += "<br></a><br>"
	str += "<span class='home_text'>" + pText + "</span>&nbsp;"
	str += "<a href='" + pHref + "' class='home_links'>[more]</a>"
	return (str);
}

//CallMust
function M_1()
{
	pH = "pro_callmust.htm";
	pT = "CallMust";
	pI = "images/home/img_crm_small.jpg";
	pTx = "Leveraging the Internet, messaging systems and a quick-response-and-action setup, CallMust will eliminate the time gap between complaint and response while accomplishing an impeccable quality of service.";
	return (makeTD (pH,pT,pI,pTx));
}

//InsureMust
function M_2()
{
	pH = "pro_insuremust.htm";
	pT = "InsureMust";
	pI = "images/home/img_insur_small.jpg";
	pTx = "InsureMust is a revolutionary insurance application software designed to give the highest level of usability. InsureMust gives the user full control to customise the application to the requirements of the business without any developer intervention.";
	return (makeTD (pH,pT,pI,pTx));
}

//SchoolMust
function M_3()
{
	pH = "pro_schoolmust.htm";
	pT = "SchoolMust";
	pI = "images/home/img_school_small.jpg";
	pTx = "SchoolMust is a School Management Software with a difference. Apart from performing regular tasks of school management, SchoolMust provides critical performance analyses from various \"perception angles\" that help to monitor performance curves...";
	return (makeTD (pH,pT,pI,pTx));
}

//QualityMust
function M_4()
{
	pH = "pro_qualitymust.htm";
	pT = "QualityMust";
	pI = "images/home/img_qms_small.jpg";
	pTx = "With increase in pace of software development, project management tools become a necessity. Featuring Resource Management, Task Management and powerful Report utilities, QualityMust is one such powerful tool.";
	return (makeTD (pH,pT,pI,pTx));
}

//HotelMust
function M_5()
{
	pH = "pro_hotelmust.htm";
	pT = "HotelMust";
	pI = "images/home/img_hotel_small.jpg";
	pTx = "HotelMust consists of an advanced suite of management and accounting tools that make monitoring and management of hotel assets a breeze. Extensive 'live' reports that reveal trends make HotelMust a must-have for the hospitality industry.";
	return (makeTD (pH,pT,pI,pTx));
}

//HealthMust
function M_6()
{
	pH = "pro_healthmust.htm";
	pT = "HealthMust";
	pI = "images/home/img_hosp_small.jpg";
	pTx = "HealthMust is a software product suite designed to improve the quality and management of clinical care and hospital/health care management in the areas of clinical process analysis and activity-based costing.";
	return (makeTD (pH,pT,pI,pTx));
}

//BankMust
function M_7()
{
	pH = "pro_bankmust.htm";
	pT = "BankMust";
	pI = "images/home/img_bank_small.jpg";
	pTx = "To stay ahead of the competition, banks require flexibility to quickly adjust and cash-in on volatile financial environments.  Here is where BankMust makes that discerning difference with unbeatable flexibility, user-friendly design combined with state-of-the-art technology.";
	return (makeTD (pH,pT,pI,pTx));
}

//ShippingMust
function M_8()
{
	pH = "pro_shippingmust.htm";
	pT = "ShippingMust";
	pI = "images/home/img_ship_small.jpg";
	pTx = "Integrated Internet Cargo Tracking, Full Job Costing , Packing List , Management Information (Graphs & Data) , Accounting, Multiple Branches & Departments . With the feature mentioned, ShippingMust is a runaway success.";
	return (makeTD (pH,pT,pI,pTx));
}

//SupplyMust
function M_9()
{
	pH = "pro_supplymust.htm";
	pT = "SupplyMust";
	pI = "images/home/img_supply_small.jpg";
	pTx = "SupplyMust gives you the power to handle volatile supply chain requirements with ease. As usual, agility being the mantra, SupplyMust is a one stop management solution for warehouse management, yard management, transportation management...";
	return (makeTD (pH,pT,pI,pTx));
}

//StockMust
function M_10()
{
	pH = "pro_stockmust.htm";
	pT = "StockMust";
	pI = "images/home/img_stock_small.jpg";
	pTx = "StockMust is aimed at live stock trading. StockMust brings about a 2-way communication between a client and his Portfolio Manager. Packed with powerful Business Analysis tools, StockMust makes an ideal choice for Portfolio Managers.";
	return (makeTD (pH,pT,pI,pTx));
}

//ITMust Values 1
function V_1 ()
{
	return ("&quot;If it's not on time...<br>it's obsolete.&quot;");
}

//ITMust Values 2
function V_2 ()
{
	return ("&quot;Compromise does not exist<br>in our dictionary.&quot;");
}

//ITMust Values 3
function V_3 ()
{
	return ("&quot;We rely on our reliability,<br>Our lives depend on it.&quot;");
}

//ITMust Values 4
function V_4 ()
{
	return ("&quot;Budgets are guidelines,<br>not restraints.&quot;");
}

//ITMust Values 5
function V_5 ()
{
	return ("&quot;Satisfaction is your<br>right.&quot;");
}

// To find if cookie exists
function isCookieKey (sKey)
{
	var arrCookie = document.cookie.split (";");
   	var bCookieSet = false;
   	for (var j=0; j < arrCookie.length; j++)
   	{
    	var arrKey = arrCookie [j].split ("=");
    	var sKeyObj = trimObject (sKey);
    	var sParamObj = trimObject (arrKey [0]);
		if ((sKeyObj.toString () == sParamObj.toString ()) && arrKey [1] != "null")
			bCookieSet = true
	}
	return bCookieSet;
}

//To remove extra spaces from cookie value
function trimObject (oParam)
{
	var oValue = "";
	oParam = oParam.toLowerCase ();
	for (var j=0; j < oParam.length; j++)
	{
		if (oParam.charAt (j) != ' ')
		oValue += ""+oParam.charAt (j);
	}
   	return  oValue;  
}

//To fetch cookie value
function getCookieValue (sKey)
{
	if (isCookieKey ("Catalogue"))
	{
		var arrCookie = document.cookie.split (";");
		for (var j = 0; j < arrCookie.length; j++)
		{
			var arrKey = arrCookie [j].split ("=");
			if (arrKey [0].search (sKey) > -1)
				return arrKey [1];
		}
	}
}
