var selectedRow = 0;
var defaultWidth= 1024;
var defaultHeight=768;
var Quadrilateral = "1"
var Round="2";
var FF06="3";
var FF09="4";
var Serrated="5";
var Shouldering="59";
var FaceMilling="61";
var Plunging="131";
var InternalCircularMilling="62";
var ExternalCircularMilling="63";
var SlotMilling="64";

//***********************************************************************
function setMobileUrl(mobileUrl)
{
	
	var r=confirm("Do you want to view mobile application?");
	if (r==true)
		window.location.href=mobileUrl;

}


function mSelectLanguage()
{
	var language = document.getElementById("languages").value;
var url = "http://mpwr.iscar.com/machiningpwr/"
if (language == 'German')
	url="http://mpwr.iscar.com/machiningpwr-ger/"
else
	url="http://mpwr.iscar.com/machiningpwr/"
		
window.open(url,'');
		
}
function downloadFile()
{
	var url="FileDownload.jsp"; 
	
//	if(fileName=='null' || fileName=="")
//		alert("The document is empty");
//	else
//		{
//		
		document.getElementById("submitaction").action=url;
		document.getElementById("submitaction").submit();
//		}
}
function mSetColor(obj,status)
{

if(status=="in")
	obj.style.color = "666666";	
else
	obj.style.color = "#ee4436";	
}
function mOpewNewWindow(url)
{
	//alert(InStr(url,"AboutMachiningPower.jsp"))
	var pos=url.search("AboutMachiningPower.jsp")
	
	if(pos>=0)
	{
		var windowOptions = 'scrollbars=no,resizable=no,width=500,height=500';
		newwindow=window.open(url,'',windowOptions);
	}
	else
		newwindow=window.open(url,'');
	if (window.focus) {newwindow.focus()}
}
function setBigResultion(val)
{
	
	
	if(val=="null")
	{
		
		
		var url="MainPage.jsp";
		var srcHeight=screen.height;
		var srcWidth=screen.width;
		var defaultWidth= 1024;
		var bigResultion="false";
		if(srcWidth==defaultWidth || srcHeight==defaultHeight)
			bigResultion="true"
		var unit_type= parent.Header.document.all.clickUnits.value
 	 	
		url+="?unittype=" + unit_type;
		
		document.submitaction.action=url;
 		document.submitaction.target="MainPage";
 		document.submitaction.submit();
 		
		
	}
		
		
}
function mSaveWorkpieceMaterial() 
{
	var lSelectedValue='';
	var i=0;
	var lMc;
	var lKc1_1;
	
	//document.all.aWorkpieceMaterialSelect.length
	//alert(document.all.aWorkpieceMaterialSelect.length);
	
	for(i=0;i<document.getElementById("aWorkpieceMaterialSelect").length;++i)
	{
		
		if(document.getElementById("aWorkpieceMaterialSelect").options[i].selected)
		{
			
			lSelectedValue=document.getElementById("aWorkpieceMaterialSelect").options[i].value;
			
			var str=lSelectedValue
			var mySplitResult = str.split(",",3);
			lSelectedValue=mySplitResult[0];
			lMc=mySplitResult[1];
			lKc1_1=mySplitResult[2];
		}
	}
	
	
	window.opener.mGetWorkpieceMaterialValue(lSelectedValue,lMc,lKc1_1);
	window.close();
}
//******************************************************************
function dlgWorkpieceMaterial() 
{
	var windowOptions = 'scrollbars=no,resizable=no,width=230,height=400';
	var newwin=window.open('workpiecematerial.jsp','WorkpieceMaterial', windowOptions);
	//var newwin=window.open('ExtendMaterialPage.jsp','WorkpieceMaterial', windowOptions);
	//var newwin=window.open('http://iscarsites/Ecat/mat.asp?caller=ita','WorkpieceMaterial', windowOptions);
	//var newwin=window.open('http://localhost/mp/test.aspx','WorkpieceMaterial', windowOptions);
	newwin.focus();
	
}
//******************************************************************
function dlgExtendShow() 
{
	var windowOptions = 'history=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=500,height=850,screenX=200,screenY=200';
	
	ExtendWindow=window.open('ExtendIndex.jsp','ExtendMaterial',windowOptions);
	//ExtendWindow=window.open('ExtendMaterialPage.jsp','ExtendMaterial',windowOptions);
	setExtendFrame(ExtendWindow);
}


//******************************************************************
function dlgUserDefinedShow() 
{
	var windowOptions = 'history=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=300,height=350,screenX=200,screenY=200';
	
	ExtendWindow=window.open('UserDefined.jsp','ExtendMaterial',windowOptions);
	//ExtendWindow=window.open('ExtendMaterialPage.jsp','ExtendMaterial',windowOptions);
	setExtendFrame(ExtendWindow);
}
//******************************************************************
function setExtendFrame(obj)
{
	
	var Deltaheight=window.opener.top.Header.document.getElementById("deltaheight").value;
	
	var srcHeight=screen.height;
	
	var percent=600*100/srcHeight;
	
	
	 var defaultRow=92;
	 
	  var secondRow=defaultRow-percent;
	 
	  window.opener.top.Header.document.getElementById("extendheight").value=secondRow*srcHeight/100*0.8;
	 
	 percent=eval(percent) + "%," + eval(secondRow) + "%,*";
	
		if(obj.extendframe!=null)
			obj.top.extendframe.rows=percent;		
}


//***********************************************************************
function mGetWorkpieceMaterialValue(iMaterial,iMc,iKc1_1)
{
	

	document.getElementById("materialtype").value=iMaterial;
	document.getElementById("materialtypes").value=iMaterial;
	document.getElementById("mc").value=iMc;
	document.getElementById("kc1_1").value=iKc1_1;
	
}
function mExtendClose()
{
window.opener.mGetWorkpieceMaterialValue("ffff","fff","fffff");
window.opener.close();
}
//***********************************************************************
function keyNomericCheck(eventObj, obj)
{
	var keyCode
	// Check For Browser Type
	if (document.all)
	{ 
		keyCode=eventObj.keyCode
	}
	else
		{
			keyCode=eventObj.which
		}
	
	var str=obj.value

	if(keyCode==46)
	{ 
		if (str.indexOf(".")>0)
		{
			return false
		}
	}
	if( keyCode==45) //minus
		return true;
	if((keyCode<48 || keyCode >58 )   &&   (keyCode != 46 ))
	{ // Allow only integers and decimal points
		return false
	}

	return true
}

function setNewMaterial()
{
	if( document.getElementById("materialname").value=="" )
	{
		
		alert("Please fill material name")
		return;
	}
	if( document.getElementById("kc1").value=="" )
	{
		alert("Please fill Kc1,1")
		return;
	}
	if( document.getElementById("mc").value=="" )
	{
		alert("Please fill mc")
		return;
	} 
	var MaterialType=document.getElementById("materialname").value;
	var Kc1=parseFloat(document.getElementById("kc1").value)
	
	if(isNaN(Kc1))
	{
		alert("Please enter number value for kc1")
		return;	
	}
	var mc=parseFloat(document.getElementById("mc").value);
	if(isNaN(mc))
	{
		alert("Please enter number value for mc")
		return;	
	}





window.parent.opener.window.opener.mGetWorkpieceMaterialValue(MaterialType,mc,Kc1);

	window.parent.close();
	window.parent.opener.close();
}
//*******************************************************************************************
function mRound(Original,NOD)
{
	var i=0;
	var x=10;
	for(i=0;i<NOD-1;++i)
	{
		x=x*10;
	}
	var ret= Math.round(Original* x)/x; // Round(2*R0,2)
	
	//alert(ret);
	return ret;
	
}
//********************************************************************
function mGoto(iPage)
{
	location.href=iPage;
}
//********************************************************************
function mSetGraphName(iGraphName)
{
	document.all.GraphName.value=iGraphName;
}
//********************************************************************
function mSelectTab()
{
	var x=document.getElementById("TabForm");
	
	document.all.SelectedTabName.value=event.srcElement.id;
	//x.submit();
	var Url="MachiningPower.jsp?SelectedTab=" + document.all.SelectedTabName.value;
	window.open(Url, 'MainMachiningPower');
	
}


 function mUpdateUnit()
{
	
	
	//var selectTab=parent.MainPage.document.all.SelectedTabName.value;
	
		if(document.getElementById("clickUnits").value== " mm ")
			{
			
			unitType="mm" ;
			
			cvUnit="m/min"
			}
		else
			{
			unitType="inch";
			
			cvUnit="sfm" ;
			}
	
		doc=document.all;
		
		
		
		
		
		//doc.cutting_velocity.value=mRound(doc.cuttingvelocity.value*toSfm,1);
		
		if(document.all.SelectedTabName.value=="ML")   //milling
		{
		
		
		document.getElementById("tooldiameter_lable").innerHTML=unitType;
			
		
		document.getElementById("cuttingwidth_lable").innerHTML=unitType;
		
		
		if(document.getElementById("insert.value")!=FF06 && 
			doc.inserttype.value!=FF09 && doc.application.value==FaceMilling)
		{
			doc.eccentricity_lable.innerHTML=unitType;
			
		}	
				
		if(doc.application.value!=Plunging)   ////aSidePlunging
		{
			doc.depthofcut_lable.innerHTML=unitType;
			
			doc.feedpertooth_lable.innerHTML=unitType;
			
			
		}
		else
			{
			doc.feedperrevolution_lable.innerHTML=unitType;
			
			doc.predrilledholediameter_lable.innerHTML=unitType;
			
			
			}
		
			if(doc.insert.value==Round)
			{
			doc.insertdiameter_lable.innerHTML=unitType;
			
			
			}
			else
				if(doc.insert.value==Serrated)
				{	
		
				doc.insertwidt_lable.innerHTML=unitType;
				
				//doc.maxdepthofcut_lable.innerHTML=unitType;
				
				}
		//submit
		
		var srcHeight=screen.height;
	var srcWidth=screen.width;
	var defaultWidth= 1024;
	var bigResultion="false";
	
	if(srcWidth==defaultWidth || srcHeight==defaultHeight)
		bigResultion="true"
	
	var location="MainPage.jsp?Module=ML";
	
	
	
		//
		
		//parent.MainPage.document.getElementById("submitaction").target="MainPage";
		document.getElementById("submitaction").action=location;
		document.getElementById("submitaction").submit();	
			
		}
		
	
}
//********************************************************************
//function msetUnit(UnitVal)
//{
//	//alert("setunit")
//	
//	if(UnitVal==1)
//	{
//		
//		if(document.getElementById("clickUnits").value==" mm " || document.getElementById("clickUnits").value=="mm")
//			{
//				return
//			}
//		document.getElementById("aUnits").value="mm";
//		document.getElementById("unittype").value="mm";
//		
//	}
//	else
//	{
//		
//		if(document.getElementById("clickUnits").value!=" mm " )
//		{
//		
//		if(document.getElementById("clickUnits").value!="mm" )
//			return
//		}
//		document.getElementById("aUnits").value="inch";
//		document.getElementById("unittype").value="inch";
//		
//	}
//		//alert(document.getElementById("aUnits").value)
//		setUnit(UnitVal,true);
//		
//	//mUpdateCuttingVelocityUnit(UnitVal)	
//		
//}
//***********************************************

function msetUnit(UnitVal)
{
	
	
	if(UnitVal==1)
	{
		
//		if(document.getElementById("clickUnits").value==" mm " || document.getElementById("clickUnits").value=="mm")
//			{
//				return
//			}
		if(document.getElementById("aUnits").value=="mm" || document.getElementById("aUnits").value==" mm ")
			return;
		document.getElementById("aUnits").value="mm";
		document.getElementById("unittype").value="mm";
		
	}
	else
	{
		
//		if(document.getElementById("clickUnits").value!=" mm " )
//		{
//		
//		if(document.getElementById("clickUnits").value!="mm" )
//			return
//		}
		if(document.getElementById("aUnits").value=="mm" || document.getElementById("aUnits").value==" mm ")
		{
			document.getElementById("aUnits").value="inch";
			document.getElementById("unittype").value="inch";
		}
		
	}
		//alert(document.getElementById("aUnits").value)
		setUnit(UnitVal,true);
		
	//mUpdateCuttingVelocityUnit(UnitVal)	
		
}

function mUpdateCuttingVelocityUnit(num)
{

 var d=document.all;


	 var Diam=d.tooldiameter.value;
	
				if(num==1)
				{
					if(d.spindelspeed.value!='')
					{
						d.cuttingvelocity.value=mRound(Math.PI* Diam* d.spindelspeed.value/1000,1)/10.0 ;
						d.cutting_velocity.value=d.cuttingvelocity.value/10.0;
						//d.spindel_speed.value=d.spindelspeed.value;
					}
				}
				
			
		
}
function setClick(UnitVal)
{
	
	
	if(UnitVal==1)
		document.all.clickUnits.value=" mm ";
	else
		document.all.clickUnits.value=" inch ";
}
//********************************************************************
function setUnit(num,multi)
{
	//var unit_type=(parent.Header.document.all.aUnits.value);
	//alert(document.all.unittype.value)
	
	if(typeof(num)!="number")
		var unittype=document.getElementById("unittype").value;
		
	
	var unitType;
	var conv;
	var toSfm;
	var cvUnit;
	var doc;
	var selectTab="";
	
	
	if(typeof(document.getElementById("aUnits"))== "object")
	{
		
		var selectTab=document.getElementById("SelectedTabName").value;
		
		if(document.getElementById("aUnits").value== " mm " || document.getElementById("aUnits").value=="mm")
			{
			
			unitType="mm" ;
			conv=25.4;
			toSfm=1/3.2808;
			cvUnit="m/min"
			}
		else
			{
			unitType="inch";
			conv=1/25.4;
			toSfm=3.2808;
			cvUnit="sfm" ;
			}
	
		
		document.getElementsByName('unittype').value=unitType;
		
		
		
		if(typeof(document.getElementById("cvlabel"))=="object")	
			document.getElementById("cvlabel").innerHTML=cvUnit;
		
		
		
		
		
		if(document.getElementById("SelectedTabName").value=="ML" )
		{
		
		if(typeof(document.getElementById("tooldiameter_lable"))=="object")
		{
		
		document.getElementById("tooldiameter_lable").innerHTML=unitType;
			document.getElementById("tooldiameter").value=
				mRound(document.getElementById("tooldiameter").value*conv,7);
		}
		if(document.getElementById("cuttingwidth_lable")!=null)
		{
		document.getElementById("cuttingwidth_lable").innerHTML=unitType;
		document.getElementById("cuttingwidth").value=
				mRound(document.getElementById("cuttingwidth").value*conv,7);
		}
		
			if(typeof(document.getElementById("eccentricity_lable"))=="object" & document.getElementById("eccentricity_lable")!=null)
			{
		
			document.getElementById("eccentricity_lable").innerHTML=unitType;
			
			if(typeof(document.getElementById("eccentricity"))=="object")
				document.getElementById("eccentricity").value=
				mRound(document.getElementById("eccentricity").value*conv,7);
			}
			
		//}	
		
		
		if(document.getElementById("application").value!=Plunging)  ///aSidePlunging
		{
			
			document.getElementById("depthofcut_lable").innerHTML=unitType;
			document.getElementById("depthofcut").value=
				mRound(document.getElementById("depthofcut").value*conv,7);
			if(document.getElementById("feedpertooth_lable")!=null)
			{	
			document.getElementById("feedpertooth_lable").innerHTML=unitType;
			document.getElementById("feedpertooth").value=
				mRound(document.getElementById("feedpertooth").value*conv,7);
				//alert(document.getElementById("feedpertooth").value)
				}
			
		}
		else
			{
			
			document.getElementById("feedperrevolution_lable").innerHTML=unitType;
			document.getElementById("feedperrevolution").value=
				mRound(document.getElementById("feedperrevolution").value*conv,7);
				
			document.getElementById("predrilledholediameter_lable").innerHTML=unitType;
			document.getElementById("predrilledholediameter").value=
				mRound(document.getElementById("predrilledholediameter").value*conv,7);	
			
			}
		
			if(document.getElementById("insert").value==Round)
			{
			document.getElementById("insertdiam_lable").innerHTML=unitType;
			document.getElementById("insertdiameter").value=
				mRound(document.getElementById("insertdiameter").value*conv,7);
			
			}
			else
				if(document.getElementById("insert").value==Serrated)
				{	
		
				document.getElementById("insertwidt_lable").innerHTML=unitType;
				document.getElementById("insertwidth").value=
					mRound(document.getElementById("insertwidth").value*conv,7);
				//document.getElementById("maxdepthofcut_lable").innerHTML=unitType;
				//document.getElementById("maxdepthofcut").value=
				//	mRound(document.getElementById("maxdepthofcut").value*conv,7);
				
				}
				//
//				if(document.getElementById("feedpertooth_lable")!=null)
//				{
//					document.getElementById("feedpertooth_lable").innerHTML=unitType;
//					document.getElementById("feedpertooth").value=
//					mRound(document.getElementById("feedpertooth").value*conv,7);
//				}	
				if(document.getElementById("hmax_lable")!=null)
				{
					document.getElementById("hmax_lable").innerHTML=unitType;
					document.getElementById("hmax").value=
					mRound(document.getElementById("hmax").value*conv,7);
				}	
				if(document.getElementById("dw_lable")!=null)
				{
					document.getElementById("dw_lable").innerHTML=unitType;
					document.getElementById("dw").value=
					mRound(document.getElementById("dw").value*conv,7);
				}	
				if(document.getElementById("stock_lable")!=null)
				{
					document.getElementById("stock_lable").innerHTML=unitType;
					document.getElementById("stock").value=
					mRound(document.getElementById("stock").value*conv,7);
				}	
				
				
				//
		}
		else
		{
			if(document.getElementById("SelectedTabName").value=="DR")
			{
			document.getElementById("drillingdiameter_label").innerHTML=unitType;
			document.getElementById("drillingdiameter").value=
					mRound(document.getElementById("drillingdiameter").value*conv,7);
			document.getElementById("internalholediameter_label").innerHTML=unitType;
			document.getElementById("internalholediameter").value=
					mRound(document.getElementById("internalholediameter").value*conv,7);
			document.getElementById("feedperrevolution_label").innerHTML=unitType;
			document.getElementById("feedperrevolution").value=
					mRound(document.getElementById("feedperrevolution").value*conv,7);
			
			}
		}
		
			var selTab=document.getElementById("SelectedTabName").value;
			
			if(selTab=="IS" || selTab=="BO" || selTab=="TG")
			{
			if(document.getElementById("insertdiam")!=null)
				{
				document.getElementById("insertdiam_lable").innerHTML=unitType;
				document.getElementById("insertdiam").value=
					mRound(document.getElementById("insertdiam").value*conv,7);
				}
			document.getElementById("workpiecediameter_lable").innerHTML=unitType;
			document.getElementById("workpiecediameter").value=
					mRound(document.getElementById("workpiecediameter").value*conv,7);
			document.getElementById("feedperrevolution_lable").innerHTML=unitType;
			document.getElementById("feedperrevolution").value=
					mRound(document.getElementById("feedperrevolution").value*conv,7);
			
			
			if(document.getElementById("application").value=="aTurning" 
				||document.getElementById("application").value=="aBoring")	
				{	
				document.getElementById("depthofcut_lable").innerHTML=unitType;
				document.getElementById("depthofcut").value=
						mRound(document.getElementById("depthofcut").value*conv,7);
			
				}
			else
				{
				if(document.getElementById("application").value=="aGrooving/Parting off")
					{
					
					document.getElementById("insertwidth_lable").innerHTML=unitType;
					document.getElementById("insertwidth").value=
						mRound(document.getElementById("insertwidth").value*conv,7);
					}
				}
			}
		
//			if(document.getElementById("inserttype").value==Round)
//			{
//				
//				document.getElementById("insertdiam_lable").innerHTML=unitType;
//				document.getElementById("insertdiameter").value=
//						mRound(document.getElementById("insertdiameter").value*conv,7);
//				alert(document.getElementById("insertdiameter").value)
//			}
//			
		//insertdiam_lable	
		document.getElementById("cuttingvelocity").value=mRound(document.getElementById("cuttingvelocity").value*toSfm,1);
		document.getElementById("cutting_velocity").value=document.getElementById("cuttingvelocity").value;
		
	}
	//

	//Module=ML&Application=aFullImmersion&InsertType=1&bigResultion=false&Home=iscar&Diameter=1&Ae=1&Z=1&spindleSpeed=101&cuttingVelocity=0.3&WorkPiece=AISI%204340&kc1=1775.0&Mc=0.24&RakeAngle=0&LeadAngle=90&e=0&fz=1&Ap=1&unittype=mm&newunittype=inch
	//end replace
//	var newUrl="Main.jsp?Module=" + document.getElementById("SelectedTabName").value + "&Application=" +  document.getElementById("application").value + 
//	"&InsertType=" + document.getElementById("insert").value + "&bigResultion=false&Home=" + document.getElementById("home").value 
//	var updateValue=UpdateValue(unittype,conv)
//	newUrl+="&" + updateValue + "&spindleSpeed=" + document.getElementById("spindelspeed").value +.......
//	newUrl+="&nittype=" + unitType
//	
//		//	location+="&unittype=" + unit_type + "&Module=ML&Application=" + 
//	  	//		applicationName ;  		
//			
// 	 		document.getElementById("submitaction").action=newUrl; 		
//	  		
//			document.getElementById("submitaction").submit();
	//
	
}
function UpdateValue(unittype,conv)
 {
 
 var Ref=""
 var toolDiam=0;
 var CuttingWidth=0;
 var NumberOfInsert=0;
 var DepthOfCutt=0;
 var Eccentricity=0;
 var RakeAngle=0;
 var LeadAngle=0;

			
			 toolDiam= mRound(document.getElementById("tooldiameter").value*conv,7);
			 
			 CuttingWidth=mRound(document.getElementById("cuttingwidth").value*conv,7);
			 NumberOfInsert=document.getElementById("numberofinsert").value;
			 var selInsertInd=document.getElementById("inserttype").selectedIndex
			var selAppInd=document.getElementById("applications").selectedIndex
			 if(document.getElementById("inserttype")[selInsertInd].value!=FF06 && 
			 	document.getElementById("inserttype")[selInsertInd].value!=FF09)
			 	{
			 		if(typeof(document.getElementById("rakeangle"))=="object" & document.getElementById("rakeangle")!=null)
			 		{
				 		RakeAngle=document.getElementById("rakeangle").value;
				 		
				 		if(document.getElementById("inserttype")[selInsertInd].value!=Round)
				 		{	if(typeof(document.getElementById("leadangle"))=="object" & document.getElementById("leadangle")!=null)
				 				LeadAngle= document.getElementById("leadangle").value;
				 		}
				 	}
			 	}
			 var spindlespeed=document.getElementById("spindelspeed").value;
			 
			 var cuttingVel=mGetCuttingVelocity(spindlespeed,unittype)
			 
			 Ref="Diameter=" +  toolDiam+ "&Ae=" + CuttingWidth + 
			 	"&Z=" + NumberOfInsert + 
			 	"&spindleSpeed=" + document.all.spindelspeed.value+ 
			 	"&cuttingVelocity=" + cuttingVel + 
			 	"&WorkPiece=" + document.all.materialtype.value + 
			 	"&kc1=" + document.all.kc1_1.value + 
			 	"&Mc=" + document.all.mc.value+ 
			 	"&RakeAngle=" + RakeAngle + "&LeadAngle=" + LeadAngle ;
			 	
			 	if(document.getElementById("applications")[selAppInd].value==Plunging) ////aSidePlunging
			 		{
			 		
			 		if(typeof(document.getElementById("feedperrevolution"))=="object" && document.getElementById("feedperrevolution")!=null)
				 	{
				 		
				 		var FeedPerRev=mRound(document.getElementById("feedperrevolution").value*conv,7);;
				 		
				 		Ref=Ref + "&f=" +FeedPerRev  ;
				 		
				 	}
				 
				 		if(typeof(document.getElementById("predrilledholediameter"))=="object" &  document.getElementById("predrilledholediameter")!=null)
				 		{
				 			var predrill=document.getElementById("predrilledholediameter").value;
				 			Ref+="&d="+ predrill
				 		}
			 		}
			 	
			
			if(document.getElementById("inserttype")[selInsertInd].value==Serrated)
			{
				
				if(typeof(document.getElementById("insertwidth"))=="object" & document.getElementById("insertwidth")!=null)
				{
					var insertwidth=mRound(document.getElementById("insertwidth").value*conv,7);
					Ref+="&w=" + insertwidth 
				}
				if(typeof(document.getElementById("maxdepthofcut"))=="object" & document.getElementById("maxdepthofcut")!=null)
				{
					var MaxDept=mRound(document.getElementById("maxdepthofcut").value*conv,7)
					Ref+="&ApMax=" + MaxDept;
				}
			}
	
	if(typeof(document.getElementById("insertdiameter"))=="object" &  document.getElementById("insertdiameter")!=null)
			 		Ref+="&d=" + document.getElementById("insertdiameter").value;
	
	if(typeof(document.getElementById("eccentricity"))=="object" & document.getElementById("eccentricity")!=null)
			 		Ref+="&e=" + mRound(document.getElementById("eccentricity").value*conv,7);
	
	if(typeof(document.getElementById("feedpertooth"))=="object" & document.getElementById("feedpertooth")!=null)
			 		Ref+="&fz=" + mRound(document.getElementById("feedpertooth").value*conv,7);
			 		
	if(typeof(document.getElementById("depthofcut"))=="object" & document.getElementById("depthofcut")!=null)
			 		Ref+="&Ap=" + mRound(document.getElementById("depthofcut").value*conv,7);
			 		
		 
	 return Ref;
 }
function setExtandVal(aisi,Mc,Kc,Din)
{
	
	parent.ExtendButton.document.all.aisi.value=aisi;
	parent.ExtendButton.document.all.mc.value=Mc;
	parent.ExtendButton.document.all.kc.value=Kc;
	parent.ExtendButton.document.all.din.value=Din;
	
	
}
function setExtend(iSelectedValue,lMc,lKc1_1)
{
var MaterialType;

if(parent.ExtendButton.document.all.aisi.value!="null")
	MaterialType="AISI " +parent.ExtendButton.document.all.aisi.value;
else
	MaterialType="Din " +parent.ExtendButton.document.all.din.value;



var lMc=parent.ExtendButton.document.all.mc.value;
var lKc1_1=parent.ExtendButton.document.all.kc.value;
if(lMc=="" ||  lKc1_1=="")
{
	alert("select value")
	return;
}
window.parent.opener.window.opener.mGetWorkpieceMaterialValue(MaterialType,lMc,lKc1_1);

	window.parent.close();
	window.parent.opener.close();

}
function setValue(Aisi,lMc,lKc1_1)
{


var Url="ExtendButton.jsp?Aisi=" + Aisi + "&Kc1=" + lKc1_1 + "&Mc=" + lMc;
	window.open(Url, 'ExtendButton');
}
function setSelect(num,line)
{
	
	var Url="ExtendFooter.jsp?Num=" + num + "&Line=" + line;
	window.open(Url, 'ExtendFooter');
}
function setSearchSelect(line,SearchString,SearchType)
{
	
	var Url="SearchResult.jsp?Line="+ line +"&SerchTxt=" + SearchString + "&searchExt=" + SearchType;
	window.open(Url, 'ExtendFooter');
}
function chkInt(eventObj, obj)
{
	
	var keyCode
	// Check For Browser Type
	if (document.all)
	{ 
		keyCode=eventObj.keyCode
	}
	else
		{
			keyCode=eventObj.which
		}
	
	var str=obj.value
	
		if (str.indexOf(".")>0)
		{
			
			if(document.all.SelectedTabName.value=="ML")
				{alert("Number of insert must be integer");
				document.all.numberofinsert.value=0;}
			else
				{
				alert("Number of cutting edges must be integer");
				document.all.numberofcuttingedges.value=0;}
		}
}

function setMainHeader(val,application)
{

switch (val)
{
case "ML":
	{
	val="Milling";
	break;
	}
case "DR":
	{
	val="Drilling";
	break;
	}
case "IS":
	{
	
		val="Turning";
		break;
	}
case "BO":
	{
	
		val="Boring";
		break;
	}
	case "TG":
	{
		val="Grooving/Parting off";
		break;
	}
}

document.getElementById("mainheader").innerHTML="<br>&nbsp;&nbsp;"+ val;

}
function OpenReport()
 {
 	
 	var module=document.getElementById("module").value;
 	
 	var applicationName;
 	var url;
	var home=(document.getElementById("home").value)
	
 	switch (module)
 	{
	 	case "ML":
	 	{
		
		 
		 	applicationName=document.getElementById("application").value;
		 	var selInsertInd=document.getElementById("inserttype").selectedIndex
		 	var application;
		 	if(applicationName!=Plunging) ////aSidePlunging
		 	{
			 	var insertType=document.getElementById("inserttype")[selInsertInd].value;
			 	
			 	if(insertType==Quadrilateral)//aGeneralShaped
			 	{
			 		url="MillGeneralShapeReport.jsp?ApplicationName=" + applicationName;
			 		
			 	}
			 	else
				 	if(insertType==Round)
				 	{
				 		url="MillRoundReport.jsp?ApplicationName=" + applicationName;
				 		
				 	}
				 	else
					 	if(insertType==Serrated)
					 	{
					 		url="MillSerratedReport.jsp?ApplicationName=" + applicationName;
					 		
					 	}
			 		else
			 			url="MillFwReport.jsp?ApplicationName=" + applicationName;
			 	}
			 	else
			 		url="MillPlungingReport.jsp?ApplicationName=" + applicationName;
		 	
		 	break;
		 	
		 	
	 		}//end milling
			case "IS":
			{
				
				
				applicationName=document.all.applicationval.value;
 				url="TurningReport.jsp?ApplicationName=" + applicationName + "&InsertType=" + document.getElementById("inserttype").value;
 				
 	
 	
				break;
			}
			
			case "BO":
			{
				
				
				applicationName=document.all.applicationval.value;
 				url="TurningReport.jsp?ApplicationName=" + applicationName;
 		
 	
 	
				break;
			}
			
			case "TG":
			{
				
				
				applicationName=document.all.applicationval.value;
 				url="TurningReport.jsp?ApplicationName=" + applicationName;
 		
 	
 	
				break;
			}
			case "DR":
			{
				
				var applicationName=document.all.applicationval.value;
		 		url="DrillingDrilReport.jsp?ApplicationName=" + applicationName;
		 		
				break;
			}	
		}
		url+="&Home=" + home
		
		document.submitaction.action=url;
 		document.submitaction.target="_blank";
 		
 		document.submitaction.submit();
 		
 		document.submitaction.target=""
	} 
function msetPicture()
{
	var appName=(document.getElementById("application").value)
	var module=document.getElementById("module").value;
	if(module=="ML")
	{
	if(document.all.applications.value=="aFullImmersion")
		{
		//start
		
		if(document.all.inserttype[0].value==Quadrilateral)//generalShape
		 	{
			document.all.aApplicationImg.src='images/small/Full-Immersion.jpg';
			
			return; 	 
		 	
		 	 }
 		else
 			if(document.all.inserttype[0].value==Round)//round
 	 			{
 	 			document.all.aApplicationImg.src='images/small/RoundInsertFull.jpg';
				return;
 	 			}
 	 		else
 				if(document.all.inserttype[0].value==Serrated)//seraated
 				{
 	 			
 	 			document.all.aApplicationImg.src='images/small/SerrattedInsertFull.jpg';
				return;
 	 			}
 	 		else
 	 			
 	 				{
 	 				document.all.aApplicationImg.src='images/small/FFWOMTFull.jpg';
					return;
					}
 	 			
 	 			
		}
		
	if(document.all.applications.value==Shouldering)
		{
		if(document.all.inserttype[0].value==Quadrilateral)//generalShape
		 	{
			document.all.aApplicationImg.src='images/small/Shouldering.jpg';
			return; 	 
		 	
		 	 }
 		else
 			
 			if(document.all.inserttype[0].value==Round)//round
 	 		{
 	 		document.all.aApplicationImg.src='images/small/RoundInsertFaceS.jpg'; /////????
			return;
 	 		}
 	 		else
 				if(document.all.inserttype[0].value==Serrated)//seraated
 				{
 	 			
 	 			document.all.aApplicationImg.src='images/small/SerrattedInsertS.jpg';
				return;
 	 			
 	 			
 	 			}
 	 			else
 	 			
 	 				{
 	 				document.all.aApplicationImg.src='images/small/FFWOMTS.jpg';
					return;
					}
 	 			
		}//end shouldering
	if(document.all.applications.value==FaceMilling)
		{
		if(document.all.inserttype[0].value==Quadrilateral)//generalShape
		 	{
			document.all.aApplicationImg.src='images/small/face-milling.jpg';
			return; 	 
		 	
		 	 }
 		else
 			if(document.all.inserttype[0].value==Round)//round
 	 		{
 	 		document.all.aApplicationImg.src='images/small/RoundInsertFace.jpg';
			return;
 	 		}
 	 		else
 				if(document.all.inserttype[0].value==Serrated)//seraated
 					{
 	 			
 	 				document.all.aApplicationImg.src='images/small/SerrattesInsertFace.jpg';
					return;
 	 			
 	 			
 	 				}
 	 			else
 	 			
 	 				{
 	 				document.all.aApplicationImg.src='images/small/FFWOMTFace.jpg';
					return;
					}
		
		}//end face milling
		if(document.all.applications.value==InternalCircularMilling)   /////temp
		{
		if(document.all.inserttype[0].value==Quadrilateral)//generalShape
		 	{
			document.all.aApplicationImg.src='images/small/Internal_Milling-intranet.jpg';
			return; 	 
		 	
		 	 }
 		else
 			if(document.all.inserttype[0].value==Round)//round
 	 		{
 	 		document.all.aApplicationImg.src='images/small/Internal_Milling_Round-intranet.jpg';
			return;
 	 		}
 	 		else
 				if(document.all.inserttype[0].value==Serrated)//seraated
 					{
 	 			
 	 				document.all.aApplicationImg.src='images/small/Internal_Milling_Serrated-intranet.jpg';
					return;
 	 			
 	 			
 	 				}
 	 			else
 	 			
 	 				{
 	 				document.all.aApplicationImg.src='images/small/Internal_Milling_Feed_Mill-intranet.jpg';
					return;
					}
		
		}//end internal....
		if(document.all.applications.value==ExternalCircularMilling)   /////temp
		{
		if(document.all.inserttype[0].value==Quadrilateral)//generalShape
		 	{
			document.all.aApplicationImg.src='images/small/External_Milling-intranet.jpg';
			return; 	 
		 	
		 	 }
 		else
 			if(document.all.inserttype[0].value==Round)//round
 	 		{
 	 		document.all.aApplicationImg.src='images/small/External_Milling_Round-intranet.jpg';
			return;
 	 		}
 	 		else
 				if(document.all.inserttype[0].value==Serrated)//seraated
 					{
 	 			
 	 				document.all.aApplicationImg.src='images/small/External_Milling_Serrated-intranet.jpg';
					return;
 	 			
 	 			
 	 				}
 	 			else
 	 			
 	 				{
 	 				document.all.aApplicationImg.src='images/small/External_Milling_Feed-Intranet.jpg';
					return;
					}
		
		}//end external....
		if(document.all.applications.value==SlotMilling)   /////temp
		{
		//alert(document.all.applications.value)
		//alert(document.all.slotradio1 )
		//alert( document.getElementById("slotradio1").value)
		if(document.all.inserttype[0].value==Quadrilateral)//generalShape
		 	{
			if(document.getElementById("slotradio1").checked)
				document.all.aApplicationImg.src='images/small/STRAIGHT_GROOVE-intranet.jpg';
			else
				document.all.aApplicationImg.src='images/small/T_SLOT-intranet.jpg';
			
			return; 	 
		 	
		 	 }
 		else
 			if(document.all.inserttype[0].value==Round)//round
 	 		{
 	 		if(document.getElementById("slotradio1").checked)
 	 			document.all.aApplicationImg.src='images/small/STRAIGHT_GROOVE_ROUND-intranet.jpg';
 	 		else
 	 			document.all.aApplicationImg.src='images/small/T_SLOT_ROUND-intranet.jpg';
			return;
 	 		}
 	 		else
 				if(document.all.inserttype[0].value==Serrated)//seraated
 					{
 	 			
 	 				if(document.getElementById("slotradio1").checked)
		 	 			document.all.aApplicationImg.src='images/small/STRAIGH_GROOVE_SERRATED-intranet.jpg';
		 	 		else
		 	 			document.all.aApplicationImg.src='images/small/T_SLOT_SERRATED-intranet.jpg';
					return;
 	 			
 	 			
 	 				}
 	 			
		
		}//end slot....
	if(document.all.applications.value==Plunging)   ///aSidePlunging
		{
		document.all.aApplicationImg.src='images/small/Plunging.jpg';
			return;
		}
	}	
	else if(appName=="aTurning")//aTurning
  	{
	  	document.all.aApplicationImg.src='images/small/Turning.jpg';
	  	return;
	 }	
	 else if(appName=="aGrooving/Parting off")//grooving
  	{
	  	document.all.aApplicationImg.src='images/small/parting.jpg';
	  	return;
	 }	
	else if(appName=="aBoring")//boring
  	{
	  	document.all.aApplicationImg.src='images/small/Boring.jpg';
	  	return;
	 }	
	
	
}

	
function keepTurningValue()
 {
 var Ref=""
 var WorkPieceDiam=0;
 var FeedPerRevolution=0;
 var RakeAngle=0;
 var Spindle=0;
 var LeadAngle=0;
 var DeptOfCut=0;
 var cuttingVel=0;
 var Material=0;
 var kc1=0;
 var mc=0;
 var LeadAngle=0;
 var DeptOfCut=0;
 
//if(parent.MachiningPower.document.all.SelectedTabName.value=="Turning")
//	 {

	if(typeof(document.getElementById("workpiecediameter"))=="object" & document.getElementById("workpiecediameter")!=null)
	 	WorkPieceDiam=document.getElementById("workpiecediameter").value;
	 
	if( document.getElementById("feedperrevolution")!=null )
	 	FeedPerRevolution=document.getElementById("feedperrevolution").value;
	 
	if(typeof(document.getElementById("rakeangle"))=="object" & document.getElementById("rakeangle")!=null)
	 	RakeAngle=document.getElementById("rakeangle").value;
	 
	 if(typeof(document.getElementById("spindelspeed"))=="object" & document.getElementById("spindelspeed")!=null)
	 	Spindle=document.getElementById("spindelspeed").value;
	 	
	 if(typeof(document.getElementById("cuttingvelocity"))=="object" & document.getElementById("cuttingvelocity")!=null)
	 	cuttingVel=document.getElementById("cuttingvelocity").value;
	  if(typeof(document.getElementById("materialtype"))=="object" & document.getElementById("materialtype")!=null)	
	 	Material=document.getElementById("materialtype").value;
	  if(typeof( document.getElementById("kc1_1"))=="object" & document.getElementById("kc1_1")!=null)		
	 	kc1=document.getElementById("kc1_1").value;
	  if(typeof( document.getElementById("mc"))=="object" & document.getElementById("mc")!=null)	
	  	mc=	document.getElementById("mc").value; 
	  if(typeof( document.getElementById("leadangle"))=="object" & document.getElementById("leadangle")!=null)	
	 		LeadAngle= document.getElementById("leadangle").value;
	  if(typeof(  document.getElementById("depthofcut"))=="object" & document.getElementById("depthofcut")!=null)	
	 		DeptOfCut=document.getElementById("depthofcut").value;
	 Ref="Diameter=" + WorkPieceDiam + "&f=" + FeedPerRevolution + 
	 	"&RakeAngle=" + RakeAngle + 
	 	"&spindleSpeed=" + Spindle + 
	 	"&cuttingVelocity=" + cuttingVel + 
			 	"&WorkPiece=" + Material + 
			 	"&kc1=" + kc1 + 
			 	"&Mc=" +mc+ "&LeadAngle=" + LeadAngle + "&Ap=" + DeptOfCut;
	
	

 return Ref;
 }
 function updateModule(val)
 {
 	document.getElementById("module").value=val;
 }	
function openApplication(appName,appText)
{
	var home=(document.getElementById("home").value)
	var srcHeight=screen.height;
	var srcWidth=screen.width;
	var defaultWidth= 1024;
	var bigResultion="false";
	if(srcWidth==defaultWidth || srcHeight==defaultHeight)
		bigResultion="true"
	var location="Main.jsp?Parameters=Module=" + appName+ 
		"&Module=" + appName + "&Home=" + home ;
	//alert(document.getElementById("module"))
	
	document.getElementById("module").value=appName;
	
	if(appName=="IS" || appName=="BO" || appName=="TG" )
	{
		
		var Application;
		var ref=keepTurningValue();
		
		/*location+="&Application=";
		
		if(appText=="Boring")
			location+="aBoring";
		else
			if(appText=="Turning")
				location+="aTurning";
			else
				if(appText=="Grooving/Parting Off")
					location+="aGrooving/Parting off";
		*/
			//keep value
			location+="&" + ref;
	}
	
	var unit_type= document.getElementById("clickUnits").value
	
	location+="&unittype=" + unit_type;
	
	//document.getElementById("submitaction").target="MainPage";
	document.forms['submitaction'].action=location;
	
	
	document.forms['submitaction'].submit();
	
	
	//parent.MainPage.document.getElementById("mainheader").innerHTML=appText;
		
}
function setClickUnit(val)
{
	
	document.all.clickUnits.value=val
}
function SelectRow(rowID,numCol,firstrow)
{
		
		
		if(parent.ExtendHeader.document.all.selectrow.value=="")
			parent.ExtendHeader.document.all.selectrow.value=firstrow
		
        //UnHighlightRow( selectedRow,numCol );
        UnHighlightRow( parent.ExtendHeader.document.all.selectrow.value,numCol );
		//selectedRow = rowID;
    	parent.ExtendHeader.document.all.selectrow.value=rowID;
    HighlightRow( rowID,numCol );
    
  
}
function SelectDetailRow(rowID,numCol)
{
		
		
		var targetRow = document.getElementById(rowID);
		
     
    if(typeof(targetRow)=="object")
	   {
	   
	   targetRow.style.background = "#D3D3D3";
	   //chgtextColor("white",numCol,rowID)
	   }
	   var lastrow=(document.all.selectrow)
	   var id=(lastrow.value)
	   alert(id)
	   var obj=("document.getElementById(" + "row0" + ")")
	   alert(eval(obj))
	    if(typeof(obj)=="object" & obj!=null)
	    {
	   			alert(typeof(obj))
	   			alert(obj.style)
	   			obj.style.background = "#F5F5F5";
	   			}
		document.all.selectrow.value=rowID
		alert(document.all.selectrow.value)
        //UnHighlightRow( selectedRow,numCol );
        //UnHighlightRow( parent.ExtendHeader.document.all.selectrow.value,numCol );
		//selectedRow = rowID;
    	//parent.ExtendHeader.document.all.selectrow.value=rowID;
    //HighlightRow( rowID,numCol );
    
  
}
function MSIEHighlightRow( rowNumber,numCol ){}
function MSIEUnHighlightRow( rowNumber,numCol ){}
function NetscapeHighlightRow( rowNumber,numCol ){}
function NetscapeUnHighlightRow( rowNumber,numCol ){}

// set functions according to browser type
if( navigator.appName.search(  /Microsoft Internet Explorer/i ) > -1 )
{
    HighlightRow = MSIEHighlightRow;
    UnHighlightRow = MSIEUnHighlightRow;
}
else
{
    // else assume Netscape (a real application should do more complete checking!)
    HighlightRow = NetscapeHighlightRow;
    UnHighlightRow = NetscapeUnHighlightRow;
}
function MSIEUnHighlightRow( rowNumber,numCol )
{
   
  

    var targetRow = document.getElementById("row" + rowNumber);
   
   
	
    if(typeof(targetRow)=="object")
    	{
    		
    		targetRow.style.background = "#F5F5F5";	
    		
    		
    		for(var i=0;i<numCol;i++)
		   {
		   
		   	var hrefname="href" + eval(i+1)+ rowNumber;
		   	
		   
		   	if(typeof(document.getElementById(hrefname)=="object"))
		   		{
		   		
			   	document.getElementById(hrefname).style.color="gray";
		   }
	   }
	  		
 }   	
    	 
}
function MSIEHighlightRow( rowNumber,numCol )
{
   
    var targetRow = document.getElementById("row" + rowNumber);
     
    if(typeof(targetRow)=="object")
	   {
	   
	   targetRow.style.background = "#D3D3D3";
	   chgtextColor("white",numCol,rowNumber)
	   }
	   
}
function chgtextColor(color,numCol,rowNumber)
{
	
	for(var i=0;i<numCol;i++)
		   {
		   	var hrefname="href" + eval(i+1)+ rowNumber;
		   	document.getElementById(hrefname).style.color=color;
		   }
	   
}

function setDeltaWidth()
{
	
 top.Header.document.getElementById("deltawidth").value=screen.width/defaultWidth;

}
function setDeltaHeight()
{
	
 top.Header.document.getElementById("deltaheight").value=screen.height/defaultHeight;

}
//***********************************************************************
function setMainFrame()
{
	
	
	var Deltaheight=top.Header.document.getElementById("banner");
	
	var srcHeight=screen.height;
	
	var percent=95*100/srcHeight;
	var percentMain=660*100/srcHeight;
     
     if(Deltaheight>1)
	 	percent=eval(percent) + "%," + eval(percentMain+5) + "%,4*";
	 else
	 	percent=eval(percent) + "%," + eval(percentMain+5) + "%,*";
	 /*if(Deltaheight>1)
		 percent=eval(percent) + "%,70%,4%";
	else
		percent=eval(percent) + "%,70%,*";
	alert(percent);
	*/
	
		top.mainframe.rows=percent;
		
	
}
function setMenu(val)
{
alert(val)
}
function setMainTable()
{
	var pageHeight;
	
	var Deltaheight=document.getElementById("deltaheight").value;
	var DeltaWidth=document.getElementById("deltawidth").value;
	
	if(Deltaheight >1) 
	{	
		if(screen.width> 1152)
			pageHeight="96%";
		else
			pageHeight="94.8%";
	}
	else
		pageHeight="98%";
		
	
	document.getElementById("mainpagetable").style.height=pageHeight;	
	if(DeltaWidth>1)
	{
		
		if(screen.width> 1152)
			var picWidth =eval(668+ 16*DeltaWidth) + "px";
		else
			var picWidth =eval(668+ 10*DeltaWidth) + "px";
			
		document.getElementById("banner").style.width=picWidth;
	}
}
//***********************************************************************
function setScroll()
{

	if(typeof(window.parent.opener.window.opener.top.Header.document)=="object")
	{
		var Deltaheight=(window.parent.opener.window.opener.top.Header.document.getElementById("deltaheight").value);
		
		var scroll= document.getElementById("scrolllist");
		var extendFooter=( window.parent.opener.window.opener.top.Header.document.getElementById("extendheight").value);
		
		scroll.style.height=0.75*extendFooter;
	}
	
}

//***********************************************************************
function SelectMaterial(MaterialType,SearchString)
{
	
	setExtendList(MaterialType,SearchString);
}

function setStyle()
{
	var browserName=navigator.appName; 
	
	document.getElementById("maintable").style.position="relative";
	document.getElementById("maintable").style.left="-1px"
	if(browserName=="Microsoft Internet Explorer")
	{
		document.getElementById("menumachiningpower").style.position="relative";
		document.getElementById("menumachiningpower").style.left="-5px";
		document.getElementById("menumachiningpower").style.top="-12px"
		document.getElementById("mainpage").style.position="relative";
		document.getElementById("mainpage").style.left="-12px";
		document.getElementById("mainpage").style.top="-15px"
		document.getElementById("maintable").style.top="3px"
		document.getElementById("emptytop").style.width="23px"
		document.getElementById("mainheader").style.top="-1px"
		document.getElementById("maindivtable").style.top="-3px"
		document.getElementById("mainheadertable").style.top="-1px"
		document.getElementById("mainheadertable").style.left="-2px"
		
	}
	else
	{
		document.getElementById("menumachiningpower").style.position="relative";
		document.getElementById("menumachiningpower").style.left="-20%";
		document.getElementById("menumachiningpower").style.top="-6px"
		document.getElementById("mainpage").style.position="relative";
		document.getElementById("mainpage").style.left="15.5%";
		document.getElementById("mainpage").style.top="-5px"
		document.getElementById("mainmenu").style.background="white"
		document.getElementById("mainmenu").style.width="23px"
		document.getElementById("maintable").style.top="-2px"
		document.getElementById("emptytop").style.width="23px"
		document.getElementById("mainheader").style.top="-6px"
		document.getElementById("mainheadertable").style.top="-6px"
		document.getElementById("mainheadertable").style.left="-2px"
		document.getElementById("maindivtable").style.top="-2.5px"
		
		//style="background: white ;width:20px;font-size: 12px;height:521px"
	}
	
	
	
}


