var onImageArray;
var offImageArray;
//to load all images to array
function preload_OnImages()
{
	onImageArray=new Array();
	onImageArray[4]=new Array();
	for(i=0;i<arguments.length;i++)
	{
		onImageArray[4][i]=new Image();
		onImageArray[4][i].src=arguments[i]; 	
	}

}

function preload_OffImages()
{
	offImageArray=new Array();
	for(i=0;i<arguments.length;i++)
	{
		offImageArray[i]=new Image();
		offImageArray[i].src=arguments[i]; 	
	}

}
//call this function on mouseover
function rollOnMenu(imgIndex)
{
	if(document.images)
	{
		var imgName;
		//imgName=eval("menuImageName"+imgIndex)
		
		imgName="menu_services"
		//document["menuImageName"+imgIndex].src=onImageArray[imgIndex].src
		//alert("imgname is "+ imgName);
		document[imgName].src=onImageArray[imgIndex][1].src
		imgName="menu_middle_bar"
		document[imgName].src=onImageArray[imgIndex][2].src
	}
	
}

function rollOffMenu(imgIndex)
{
	if(document.images)
	{
		var imgName;
		//imgName=eval("menuImageName"+imgIndex)
		//alert("imgname is "+ imgName);
		imgName="menu_services"
		//document["menuImageName"+imgIndex].src=onImageArray[imgIndex].src
		document[imgName].src=onImageArray[imgIndex][0].src
		imgName="menu_middle_bar"
		document[imgName].src=onImageArray[imgIndex][3].src

	}
	
}

// first, check if the image property exists
        if (document.images) {            
// next, preload the rollover state of the image, and assign it an 'on' name
            uparrow1on = new Image();      
            uparrow1on.src = "images/tri_red_small.gif"; 
// then, preload the off state of the image, and assign it an 'off' name
            uparrow1off = new Image(); 
            uparrow1off.src = "images/tri_org_small.gif";
         }
// this function changes images to the rollover state (assigned above)
// it's called by the ONMOUSEOVER attribute of the HREF element
function rollon(imgName) {
        if (document.images) {
            document[imgName].src =uparrow1on.src     //eval(imgName + "on.src");
        }
}
// this function changes images to the off state (assigned above)
// it's called by the ONMOUSEOUT attribute of the HREF element
function rolloff(imgName) {
        if (document.images) {
            document[imgName].src = uparrow1off.src    //eval(imgName + "off.src");
        }
}


//function for hiding and showing the layers when mouseovers on menu items
function showHideLayers()
{	
	var i, divLayer,theObj,args,strTemp;
	args=showHideLayers.arguments;
	//alert("in function and arg is " + args[0]);
	for(i=0;i<5;i++)
	{
		strTemp="menudiv"+(i+1);
		//alert("strTemp is  "+ strTemp);
		if (navigator.appName == 'Netscape' && document.layers != null) 	
		{
			strTemp="document.layers['"+strTemp+"']";
			//alert("in netscape strTemp value is " + strTemp);
			//theObj=eval('document.layers[\\\'menudiv'+(i+1)+'\\\']')
			theObj=eval(strTemp)
			if((i+1)==args[0])
			{
				if (theObj) theObj.visibility = 'show'
			}
			else
			{
				if (theObj) theObj.visibility = 'hide'
			}
		}
		else if (document.all != null) 
		{
			strTemp="document.all['"+strTemp+"']";
			//alert("in IE strTemp value is " + strTemp);			
			//theObj=eval('document.all[\\\'menudiv'+(i+1)+'\\\']')
			theObj=eval(strTemp)
			/*
			if(theObj)
				alert("true  "+i);
			else
				alert("false " +i);
			*/
			if((i+1)==args[0])
			{
				if (theObj) theObj.style.visibility = 'visible'
			}
			else
			{
				if (theObj) theObj.style.visibility = 'hidden'
			}
		}
	}
}

var divTimeLapse;

function showOffmenu()
{
	var args_1;
	args_1=showOffmenu.arguments;
	//alert("args_1 value is "+ args_1[1]);
	if(args_1[1]=="SHOW")
	{
		//alert("in if" +divTimeLapse);
		if(divTimeLapse)
			clearTimeout(divTimeLapse)
		showHideLayers(args_1[0]);
	}
	else
	{
		//alert(" in else" +divTimeLapse);
		if(divTimeLapse)
			clearTimeout(divTimeLapse)
			var strTempfun;
			strTempfun="showHideLayers('"+args_1[0]+"')"
			divTimeLapse=setTimeout(strTempfun,1000);
	}

}
var topBanImgIndex=1;
var topBanTextIndex=1;
var topBanTextMaxIndex=2;
var strLayerAll="";
var strShowVisible="";
var strHideHidden="";
var strStyle="";
if (document.getElementById !== null)
{
	strLayerAll="document.getElementById"
	strShowVisible="visible"
	strHideHidden="hidden"
	strStyle=".style.visibility";

}
else if (document.all != null) 
{
	strLayerAll="document.all"
	strShowVisible="visible"
	strHideHidden="hidden"
	strStyle=".style.visibility";

}
else if (navigator.appName == 'Netscape' && document.layers != null) 	
{
	strLayerAll="document.layers"
	strShowVisible="show"
	strHideHidden="hide"
	strStyle=".visibility";
}


function topbanText1show()
{
	var banTextObj;
	banTextObj=eval(strLayerAll+"('topbantext1')");
	if(banTextObj) 
	{		
		if (document.all != null || document.getElementById != null) 
			banTextObj.style.visibility = strShowVisible;	
		else if (navigator.appName == 'Netscape' && document.layers != null) 
			banTextObj.visibility = strShowVisible;		
	
	}
	topBanTextIndex=2;
	setTimeout("topbanTextshow()",3000);		
}

function topbanTextshow()
{
	//alert("in function and value is " + topBanTextIndex + " and strHideHidden is " + strHideHidden) ;
	var topBanStrTemp,banImgObj;
	topBanStrTemp="topbantext"+(topBanTextIndex-1)		
	topBanStrTemp=strLayerAll+"('"+topBanStrTemp+"')";
	banImgObj=eval(topBanStrTemp);
	if(banImgObj)
	{
		if (document.all != null || document.getElementById != null) 
			 banImgObj.style.visibility = strHideHidden;
		else if (navigator.appName == 'Netscape' && document.layers != null)
			 banImgObj.visibility = strHideHidden;
			 
	}

	if(topBanTextIndex > topBanTextMaxIndex)
	{		
		setTimeout("topbanImgShow()",50);
	}
	else
	{
		topBanStrTemp="topbantext"+(topBanTextIndex)		
		topBanStrTemp=strLayerAll+"('"+topBanStrTemp+"')";
		//alert(" in else is topBanStrTemp is  " + topBanStrTemp);
		banImgObj=eval(topBanStrTemp);
	//	alert("in else and topBanTextIndex is " + topBanTextIndex + " and " + banImgObj.visibility);

		if(banImgObj)
		{
			if (document.all != null || document.getElementById != null) 
				banImgObj.style.visibility = strShowVisible;
			else if (navigator.appName == 'Netscape' && document.layers != null)	
				 banImgObj.visibility = strShowVisible;		

		}
		topBanTextIndex++;
		setTimeout("topbanTextshow()",3000);		
	}
}

function topbanImgShow()
{
	var topBanStrTemp,banImgObj;
	topBanStrTemp="topbanimg"+topBanImgIndex
	if (document.getElementById != null) 
	{
		topBanStrTemp="document.getElementById('"+topBanStrTemp+"')";
		banImgObj=eval(topBanStrTemp);
		if (banImgObj) banImgObj.style.visibility = 'visible'

	}
	else if (document.all != null) 
	{
		topBanStrTemp="document.all['"+topBanStrTemp+"']";
		banImgObj=eval(topBanStrTemp);
		if (banImgObj) banImgObj.style.visibility = 'visible'

	}
	else if (navigator.appName == 'Netscape' && document.layers != null) 	
	{
		topBanStrTemp="document.layers['"+topBanStrTemp+"']";
		banImgObj=eval(topBanStrTemp);
		if(banImgObj) banImgObj.visibility = 'show';
	}
	topBanImgIndex++;
	if(topBanImgIndex >8)
	{
		topBanImgIndex--;
		setTimeout("topbanImgHide()",2000);
	}
	else
		setTimeout("topbanImgShow()",50);		

}

function topbanImgHide()
{
	var topBanStrTemp,banImgObj;
	topBanStrTemp="topbanimg"+topBanImgIndex
	if (document.getElementById != null) 
	{
		topBanStrTemp="document.getElementById('"+topBanStrTemp+"')";
		banImgObj=eval(topBanStrTemp);
		if (banImgObj) banImgObj.style.visibility = 'hidden'

	}
	else if (document.all != null) 
	{
		topBanStrTemp="document.all['"+topBanStrTemp+"']";
		banImgObj=eval(topBanStrTemp);
		if (banImgObj) banImgObj.style.visibility = 'hidden'

	}
	else if (navigator.appName == 'Netscape' && document.layers != null) 	
	{
		topBanStrTemp="document.layers['"+topBanStrTemp+"']";
		banImgObj=eval(topBanStrTemp);
		if(banImgObj) banImgObj.visibility = 'hide';
	}
	topBanImgIndex--;
	if(topBanImgIndex <1)
	{
		topBanImgIndex++;
		setTimeout("topbanText1show()",50);
	}
	else
		setTimeout("topbanImgHide()",50);		

}



// first, check if the image property exists
        if (document.images) {            
// next, preload the rollover state of the image, and assign it an 'on' name
            upcircle1on = new Image();      
            upcircle1on.src = "images/nextpageprodmenu_02.gif"; 
// then, preload the off state of the image, and assign it an 'off' name
            upcircle1off = new Image(); 
            upcircle1off.src = "images/nextpageprodmenu-1_05.gif";
         }
// this function changes images to the rollover state (assigned above)
// it's called by the ONMOUSEOVER attribute of the HREF element
function rollonCircle(imgName) {
        if (document.images) {
            document[imgName].src =upcircle1on.src     //eval(imgName + "on.src");
        }
}
// this function changes images to the off state (assigned above)
// it's called by the ONMOUSEOUT attribute of the HREF element
function rolloffCircle(imgName) {
        if (document.images) {
            document[imgName].src = upcircle1off.src    //eval(imgName + "off.src");
        }
}

function showsearchTip()
{
	//need to impletement
	var tiparg=arguments

	if(tiparg[0] == "I")
	{
		divObj.setBody("<div class='clsProdSub2' align=justify>Allows you to search inventory at our warehouse in the corporate head quarters</div>");
		divObj.moveTo("550","250");
		divObj.setWidth("200");
		if(isNS6)			
			divObj.setHeight("35");

		divObj.show();

	}
	else if(tiparg[0] == "P")
	{
		divObj.setBody("<div class='clsProdSub2' align=justify>Allows you to search at our different warehouses across the globe and will take few minutes to return the results</div>");
		divObj.moveTo("580","250");
		divObj.setWidth("200");
		if(isNS6)	
			divObj.setHeight("45");
		divObj.show();
	}

}

function Rtrim(FieldValue)
{
	
	ReturnValue=""

	for(i=FieldValue.length-1;i>=0; i--)
		{
			if(FieldValue.charAt(i) != " ")
			{
				ReturnValue += FieldValue.substring(0,i+1)
				break;
			}
		}
         return ReturnValue;
}


function Ltrim(FieldValue)
{
	
	ReturnValue=""

	for(i=0;i<FieldValue.length;i++)
		{
			if(FieldValue.charAt(i) != " ")
			{
				ReturnValue += FieldValue.substring(i,FieldValue.length)
				break;
			}
		}
         return ReturnValue;
}


function Trim(FieldValue)
{
	return Ltrim(Rtrim(FieldValue));
}
//var AppsRoot='http://b2b.ampel.com/combiz/' ;
var AppsRoot='http://63.238.143.39/combiz/' ;
//var AppsRoot='http://192.54.0.2/combiz/' ;

function submitLogin( userType )
{
	//alert(document.forms[1].elements[0].name);
	if(Trim(document.LoginForm.uname.value).length == 0)
	{
		alert("Null value is not accepted as Login Name. Please Enter a valid user name");
		document.LoginForm.uname.focus();
		return;
	}
	if(Trim(document.LoginForm.pword.value).length == 0)
	{
		alert("Null value is not accepted as Password. Please Enter a valid password");
		document.LoginForm.pword.focus();
		return;
	}		

	if(userType == "C")
	{
		document.CustLogin.UserName.value=document.LoginForm.uname.value;
		document.CustLogin.Password.value=document.LoginForm.pword.value;
		document.CustLogin.action = AppsRoot + "cust-login/LoginReceiver.jsp";		
		document.CustLogin.submit();
			
	}
	else if(userType == "V")
	{
		document.VendLogin.UserName.value=document.LoginForm.uname.value;
		document.VendLogin.Password.value=document.LoginForm.pword.value;
		document.VendLogin.action = AppsRoot + "vend-login/LoginReceiver.jsp";		
		document.VendLogin.submit();	
	
	}



}


function instantSearch()
{
	var awx;
	var awy;

	awx=screen.availWidth
	awy=screen.availHeight

	if((document.SearchForm.SearchString.value).length == 0)
	{
		alert("Need to enter a part number to search");
		document.SearchForm.SearchString.focus();
		return;
	}
	else
	{
		//var popupURL ="http://www.ampel.com/search.asp?part_no="+document.SearchForm.SearchString.value;
		var popupURL ="search.asp?part_no="+document.SearchForm.SearchString.value;

		var popup = window.open(popupURL,"Popup",'toolbar=1,location=1,directories=1,status=0,menubar=1,scrollbars=1,resizable=1,width=780,height=580');
		if( navigator.appName.substring(0,8) == "Netscape" )
		{
			popup.location = popupURL;
		}
	}
	

}

function powerSearch()
{
	var awx;
	var awy;

	awx=screen.availWidth
	awy=screen.availHeight

	if((document.SearchForm.SearchString.value).length == 0)
	{
		alert("Need to enter a part number to search");
		document.SearchForm.SearchString.focus();
		return;
	}
	else
	{
		//var popupURL ="http://www.ampel.com/Powersearch.asp?part_no="+document.SearchForm.SearchString.value;
		var popupURL ="Powersearch.asp?part_no="+document.SearchForm.SearchString.value;
		//var popup = window.open(popupURL,"Popup",'toolbar=1,location=1,directories=1,status=0,menubar=1,scrollbars=1,resizable=1,width=780,height=580');		
		var popup = window.open(popupURL,"Popup",'toolbar=1,location=1,directories=1,status=0,menubar=1,scrollbars=1,resizable=1,width='+awx+',height='+awy+',top=0,left=0');
		if( navigator.appName.substring(0,8) == "Netscape" )
		{
			popup.location = popupURL;
		}
	}
	

}



var offerSize=10;
var offerLastIndex=0;
function changeOffers()
{
	if(items.length > offerSize)
	{
		var offerObj;
		var strOfferText="";
		for (offerI=0;offerI<offerSize;offerI++,offerLastIndex++)
		{
			if(offerLastIndex >= items.length)
				offerLastIndex=0;
			strOfferText +=items[offerLastIndex]+"<br>";
		}
		offerObj=eval(strLayerAll+"['hotspan']");
		if (document.getElementById != null)
		{
			//alert(" in hotoffers");
			document.getElementById("hotspan").innerHTML=strOfferText;		
		}
		else if(document.all)
		{
			if(offerObj)
			{
				offerObj.innerHTML=strOfferText;
			}	
		}

		else if (navigator.appName == 'Netscape' && document.layers != null)
		{
			if(offerObj)
			{
				offerObj.document.write(strOfferText);
				offerObj.document.close();
			}			
	
		}
		
		setTimeout("changeOffers()",1000);
	}	
	
}



function createNewDiv()
{

	popdivObj=new NewDiv(window,"d1","menuid",0,0,200,30,1,"absolute");
	popdivObj.output();
	popdivObj.hide();
	popdivObj.setBgColor("#EFF3FF");
	popdivObj.setBorder("thin solid","1px","#31659C");

}
//this function is being called up when user click on sign up
function showPopUp()
{
	var swidth,sheight,dwidth,dheight;
	swidth=screen.width;
	sheight=screen.height;
	
	
	if(isNS || isNS6)
	{
		dwidth=innerWidth;
		dheight=innerHeight;
	}
	else if(isIE)
	{
		dwidth=document.body.clientWidth;		
		dheight=document.body.clientHeight;
	}
	//alert("mouseXval= is "+ mouseXval + "mouseYval=" + mouseYval);
	//alert(document.body.clientHeight + " and offset Height is " + document.body.offsetHeight);
	var moveX,moveY;
	moveX=((dwidth-350)/2);
	moveY=((dheight-100)/2);
	strMesg="";
	strMesg +="<table border=0 cellspacing=0 width=100% cellpadding=0>"
	strMesg +="<tr><td align=left height='20' class='clsPopupTop'>&nbsp;User Type Selction</td><td align=right height='20' valign=top class='clsPopupTop'><img src='images/close-button.gif' onClick='popdivObj.hide()' title='Close' alt='close'></td></tr>"
	strMesg += "<tr><td colspan=2 height='35' align=center valign=bottom><a href='javascript:signup(\"C\")' class='clsSingUppop'>Customer Sign Up</a> </td></tr><tr><td align=center colspan=2 height=35 valign=bottom>  <a href='javascript:signup(\"V\")' class='clsSingUppop'>Vendor SignUp</a></td></tr></table>";
	
	popdivObj.setBody(strMesg);
	popdivObj.moveTo(580,310);
	popdivObj.setWidth("200");
	if(isNS6)
		popdivObj.setHeight("110");
	popdivObj.show();
}

//***********************************************************************
//End for code of popup window when user clicks on signup
//***********************************************************************


function userSignup()
{
	
	showPopUp()	

}

function signup(usertype)
{
	//alert("in function ");
	if(usertype == "C")
	{
		document.CustLogin.method="post"
		document.CustLogin.action = AppsRoot + "uadmin/CVUserRegistration.jsp";		
		document.CustLogin.submit();	
	}
	else if(usertype=="V")
	{
		document.VendLogin.method="post"
		document.VendLogin.action = AppsRoot + "uadmin/CVUserRegistration.jsp";		
		document.VendLogin.submit();	
	}
}



createNewDiv();