// =======================Document mouse over / mouse out===========
function VOver(R) {
  if (R.className != "VIEWRow-Select") R.className = "VIEWRow-Over";
}
//===============VOut(R)==========================================
function VOut(R) {
  if (R.className != "VIEWRow-Select") R.className = "VIEWRow";
}
//===============TDSel==========================================
function TDSel(FldVal,FldName) {
	var SQLString = FldName + " = '" + FldVal +"'";	
      var targetFLD = 	window.parent.frames[0].document.forms[0].DataParams.value; 
	 if (targetFLD.indexOf(SQLString)==-1)	{
		if (targetFLD==""){
		targetFLD += SQLString;
	}
	else
	{
		targetFLD += ";" + SQLString;
	}
	window.parent.frames[0].document.forms[0].DataParams.value = targetFLD;
	window.parent.frames[0].document.forms[0].submit();
     }
}
//===============TDOver==========================================
function TDOver(R) {
   if (R.className != "TDSel") R.className = "TDOver";
}
//===============TDOut==========================================
function TDOut(R) {
  if (R.className != "TDSel") R.className = "View";
}
//===============btnGlassOver==========================================
function btnGlassOver(R) {
    R.className = "btnGlassOver";
}
//===============btnGlassOut==========================================
function btnGlassOut(R) {
   R.className = "btnGlass";
}
//===============SetSaveIndicator==========================================
function SetNewIndicator(ind)  {		 	
//	var NewInd =  document.forms[0].NewInd;
//	NewInd.value = ind; 
//		document.forms[0].NewInd.value = ind;
		if (document.forms[0].name !="makesForm") {
		document.forms[0].Flag.value = ind; 		
		}
		 document.forms[0].submit(); 
		 } 
//===============SetSaveIndicator===========
function SetSaveIndicator(ind){
	
	document.forms[0].Flag.value = ind;
	document.forms[0].submit();
}
//=================Validation Scripts==============================
	 function Form1_Validator() 
		 { 
		 var theForm = document.forms[0]; 
		 if ( theForm.lupMake.options[theForm.lupMake.selectedIndex].text =="" && 					theForm.txtMake.value == "") 
  		 { 
    		 alert("Please enter a value for the Make field.");
    		 theForm.txtMake.focus(); 
    		 return (false); 
  		 } 
  		 if ( theForm.txtMake.value != ""  && theForm.txtMake.value.length > 100) 
  		 { 
    		 alert("Please enter at most 100 characters in the Make field. ");
    		 theForm.txtMake.focus();
    		 return (false); 
 	 	 } 
		 if (theForm.lupModel.options[theForm.lupModel.selectedIndex].text ==""  && theForm.txtModel.value == "") 
  		 { 
    		 alert("Please enter a value for the Model field.");
     	 	 theForm.txtModel.focus(); 
   		  return (false); 
  		 } 
  		 if ( theForm.txtModel.value != "" && theForm.txtModel.value.length > 50) 
  		 { 
    		 alert("Please enter at most 50 characters in the Model field.");
    		 theForm.txtModel.focus(); 
    		 return (false); 
 	 	 } 
		 if ( theForm.txtSeries.value != ""  && theForm.txtSeries.value.length > 50) 
  		 { 
    		 alert("Please enter at most 50 characters in the Series field.");
    		 theForm.txtSeries.focus(); 
    		 return (false); 
  		 } 
		 if ( theForm.txtEngine.value != ""  && theForm.txtEngine.value.length > 50) 
  		 { 
    		 alert("Please enter at most 50 characters in the Engine field.");
    		 theForm.txtEngine.focus(); 
    		 return (false); 
  		 } 
		 if ( theForm.txtYearFrom.value != ""  && theForm.txtYearFrom.value.length > 4) 
  		 { 
    		 alert("Please enter at most 4 digits in the txtYearFrom  field. ");
    		 theForm.txtYearFrom.focus(); 
    		 return (false); 
  		 } 
  		
		 if ( theForm.txtYearTo.value != "" && theForm.txtYearTo.value.length > 4) 
  		 { 
    		 	alert("Please enter at most 4 digits in the YearTo field.");
    		 	theForm.txtYearTo.focus(); 
    		 	return (false); 
  		 } 
		alert('true');
 		 return (true); 
		 }   		
//===============Submitting for VehMaint Servlet from VehQry2===========
	function submitVehicleMaint(Make,Model,IDNo,ServerName,PortName) {

var strWhereString=document.all.WhereString.value;
 
	
window.parent.parent.frames[1].location.href='http://'+ServerName+'/GroupCatalogue/GroupCatalogue.nsf/frmLoadEditVehicleFilter?OpenForm&txtOldMake='+Make+'&txtOldModel='+Model+'&VehSeqID='+IDNo+'&WhereString='+strWhereString+'&UserId='+document.all.UserId.value;
}
//===============TDSearch===========
//uncomment for dbn//function TDSearch2(FldVal,FldName,ServletName,ServerName,PortName) {
function TDSearch2(FldVal,FldName,ServletName,ServerName) {
	var SQLString = FldName + " = '" + FldVal +"'";	

//var servletURL = 'http://'+ServerName+':'+PortName+ServletName+'?WhereString='+document.all.WhereString.value+'&UserId='+document.all.UserId.value+'&DataParams='+SQLString;
var servletURL = 'http://'+ServerName+ServletName+'?WhereString='+document.all.WhereString.value+'&UserId='+document.all.UserId.value+'&DataParams='+SQLString;
//	alert(servletURL);
 window.parent.frames[1].location.href=servletURL;   
}
//---------------------TDSearch3-------------------------------------------------
function TDSearch3(FldVal,FldName,ServletName) {
	var SQLString = FldName + " = '" + FldVal +"'";	

var servletURL = ServletName+'?WhereString='+document.all.WhereString.value+'&UserId='+document.all.UserId.value+'&DataParams='+SQLString;
//	alert(servletURL);
 window.parent.frames[1].location.href=servletURL;   
}
		
//===============Submitting for VehMaint Servlet from VehMaint===========
	function submitVehMaintForm(ActionFlag) {
		document.forms[0].ActionFlag.value = ActionFlag;
		if (ActionFlag=='Save') {
		document.forms[0].submit();
		}
		else
		{
		openWin(ActionFlag);
		}
}
//===============Submitting for Filter Servlet===========

	function submitFilterAppForm(FilterNo,ServerName,PortName,Folder,strWhereString,CallServlet) {



window.parent.parent.frames[1].location.href='http://'+ServerName+':'+PortName+Folder+'/GCFilterAppSvlet?WhereString='+strWhereString+'&FilterNo='+FilterNo+'&UserId='+document.all.UserId.value+'&CallServlet='+CallServlet;	
		}


//===============Submitting for Filter App QryServlet===========

//	function submitFiltAppQry(FilterNo,ServerName,PortName) { //use for dbn testing
	function submitFiltAppQry(FilterNo,ServerName) {
// window.parent.parent.frames[1].location.href='http://'+ServerName+':'+PortName+'/examples/servlet/GCFiltAppQry?FilterNo='+FilterNo+'&UserId='+document.all.UserId.value;
 // alert("Filter Number: "+FilterNo);
  //alert("Server Name: "+ServerName);
  if(ServerName=="www2.gud.co.za"){
  ServerName = "192.168.13.7";
  }
  //alert("Server Name New: "+ServerName);
  //alert(PortName);
  //alert('is working');
//window.parent.parent.frames[1].location.href='http://'+ServerName+':'+PortName+'/WEBSITEQUERY/servlet/GCFiltAppQry?FilterNo='+FilterNo+'&UserId='+document.all.UserId.value;	 
//alert('hello');
//alert('http://'+ServerName+':'+PortName+'/WEBSITEQUERY/GCFiltAppQry?FilterNo='+FilterNo+'&UserId='+document.all.UserId.value);

//correct code for joomla 1.5
//use for dbn //window.parent.frames[1].location.href='http://'+ServerName+':'+PortName+'/WEBSITEQUERY/GCFiltAppQry?FilterNo='+FilterNo+'&UserId='+document.all.UserId.value;  
window.parent.frames[1].location.href='http://'+ServerName+':8083/WEBSITEQUERY/GCFiltAppQry?FilterNo='+FilterNo+'&UserId='+document.all.UserId.value;  
//alert("LINK : "+window.parent.frames[1].location.href);
//correct code for java
//window.parent.parent.frames[1].location.href='http://'+ServerName+':'+PortName+'/WEBSITEQUERY/GCFiltAppQry?FilterNo='+FilterNo+'&UserId='+document.all.UserId.value;		
   }



//===============DBSearch===========
function DBSearch(FldName,FldVal) {
	var SQLString = FldName + " = '" + FldVal +"'";	
  	window.parent.frames[1].document.forms[0].DataParams.value = SQLString;
	window.parent.frames[1].document.forms[0].submit();
}
//===============Submitting for Cross Ref Agent===========
	function submitCrossRefForm(Make,FilterNo,RefId,ServerName,PortName,sFolder) {
	
/*var url = sFolder+'/GHCrossRefSvlet?Flag=Edit&OldMake='+Make+'&WhereString='+document.all.WhereString.value+'&UserId='+document.all.UserId.value+'&OldRefId='+RefId+'&OldFilterNo='+FilterNo;
alert(url);	
*/
window.parent.parent.frames[1].location.href='GHCrossRefSvlet?Flag=Edit&OldMake='+Make+'&WhereString='+document.all.WhereString.value+'&UserId='+document.all.UserId.value+'&OldRefId='+RefId+'&OldFilterNo='+FilterNo;
		}

//===============Submitting for Filter Servlet===========
	function submitFilter(FilterNo,ServerName,PortName,sFolder) {

	window.parent.parent.frames[1].location.href='GCFilterSvlet?Flag=Edit&WhereString='+document.all.WhereString.value+'&UserId='+document.all.UserId.value+'&FilterNo='+FilterNo;
		}


//===============PopUpWindow Function for VehMaint===========
	function openWin(flag) {
	var urlStr = '/servlet/VehMaint?Flag='+flag;
	win = window.open(urlStr,'VehMaint','width=400,height=300,top=0,left=0,resizable=yes,scrollbars=yes');
	}
//===============PassArguments====================
	function passArg(origOBJ,ACTION) {
	var fldLen;
	var fldPrefix;
	var fldIndex;
	var fldName = origOBJ.name;
	var targetFld ;
	var newPrefix;	
	var updRecs;
	var TmpStr;

	fldLen = fldName.length;
	fldPrefix = fldName.substr(0,1);
	fldIndex = fldName.substr(fldLen-1,1);

	if(fldPrefix=='A') {
		newPrefix = "AIR";
	}
	if(fldPrefix=='O') {
		newPrefix = "OIL";
	}
	if(fldPrefix=='F') {
		newPrefix = "FUEL";
	}
	if(fldPrefix=='o') {
		newPrefix = "other";
	}
	targetFld = newPrefix+fldIndex;	
	
	if (ACTION=='chg'){	
		updRecs = document.forms[0].ChgRecNames.value;
	}
	else
	{
		updRecs = document.forms[0].DelRecNames.value;	
	}
	if (updRecs==""){
		updRecs += targetFld;
	}
	else
	{
		updRecs += ';';
		updRecs += targetFld;
	}
	if (ACTION=='chg'){	
		document.forms[0].ChgRecNames.value = updRecs;
	}
	else
	{
		document.forms[0].DelRecNames.value = updRecs;
	}
	updateAction(ACTION);
	if(origOBJ.type=="button") origOBJ.className = "btnDELlblueb";
	if(origOBJ.type=="text") origOBJ.className += "CHG";	

	if(ACTION=='del') {
		TmpStr = document.forms[0].ChgRecNames.value;
		myRegExp = new RegExp(targetFld,"g");
		 if(TmpStr.indexOf(targetFld+";")>0) TmpStr.replace(myRegExp,"");
		 if(TmpStr.indexOf(targetFld)>0) TmpStr.replace(myRegExp,"");
	}
	}
	function updateAction(actionVal) {
		var currVal;
		var targetFLD = document.forms[0].NewInd;
		currVal = targetFLD.value;
		
		if (currVal.length != 0)	{
			if(currVal.indexOf(actionVal)==-1)	{
				targetFLD.value = currVal+';'+actionVal;
			}
		}
		else	{
			targetFLD.value = actionVal;		
		}		
	}
//===============Used for Undo of last filter action====================
	function UndoLastFilter() {
	      var targetFLD = window.parent.frames[0].document.forms[0].DataParams.value;
	      var prevSQLStr;
	        if (targetFLD.lastIndexOf(";")>0)
			prevSQLStr = targetFLD.substr(0,targetFLD.lastIndexOf(";"));
	     else
			prevSQLStr = "";
                 window.parent.frames[0].document.forms[0].DataParams.value = prevSQLStr;
	     document.forms[0].submit();
	   }	
		
		
// =======================Document mouse over / mouse out===========

function UpdQryBldr(Fstr,Vstr,Updstr)
{
var Bstr = eval("document.all."+Updstr+".value");
var TmpStr=Updstr.substring(0,(Updstr.length-2))
if (TmpStr=="BrandSalUpdStr" || TmpStr=="SerIntUpdStr" )
{
Fstr=Fstr.substring(0,(Fstr.length-1))
}
var Tstr = Fstr+"="
var str = Fstr+"='" +Vstr+"'"
var i
i= Bstr.indexOf(Tstr)
// this checks the duplicate and runs the good shit when required
if ( Bstr.indexOf(Tstr) >  -1)
{
while ( Bstr.charAt(i) != ",") 
{
  i ++
 }
var oldVar
 oldVar = Bstr.substring(Bstr.indexOf(Tstr),i)
var newStr = replaceString(oldVar,str,Bstr)
eval("document.all."+Updstr+".value=  newStr") 
}
else
{
var  temp =Bstr +  str +","
eval("document.all."+Updstr+".value= temp") 
}
}



function replaceString(oldS,newS,fullS) 
{
for (var i=0; i<fullS.length; i++) 
{      
if (fullS.substring(i,i+oldS.length) == oldS) 
{         fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length) ;     
}  
 }  
 return fullS
}



