// JavaScript Document

//***********COOKIE / LOGIN FUNCTIONS**************//

exptime = new Date();
exptime.setMonth(exptime.getMonth()+6);
cName ="";
cPass ="";
vName ="";
vPass ="";
iName ="";
iPass ="";
iLoginName ="";

function showCookie()
	{//start function
	if (document.forms[0].name=="frmClient")
		{//starts if 'frmClient'
		if (document.cookie != "")
			{//start 'if cookie is not null'
			thisCookie = document.cookie.split("; ")
	 		for (i=0;i<thisCookie.length;i++)
				{//start for loop
				if (thisCookie[i].split("=")[0] == "Client Name")
					{cName = thisCookie[i].split("=")[1];
					document.frmClient.txtUsername.value = cName;
					thisCookie[i].split(";expires = ")+ exptime.toGMTString();}
				else if (thisCookie[i].split("=")[0] == "Client Password")
					{cPass = thisCookie[i].split("=")[1];
					document.frmClient.txtPassword.value = cPass;
					thisCookie[i].split(";expires = ")+ exptime.toGMTString();}	
				}//ends for loop
			}//ends 'if cookie is not null'
		}//ends if 'frmClient'/'frmIris'
		
		var args = getArgs(); 
		if( args.login )
		{
			if( args.login == 'fastrack')
			{
				checkLogin(1);	
			}else if( args.login == 'iris')
			{
				checkLogin(2);
			}
			else if( args.login == 'vendor')
			{
				checkLogin(3);
			}
		}
		
	}//ends function

function getArgs()
{ 
	var args = new Object(); 
	var query = location.search.substring(1); 
	var pairs = query.split("&"); 
	for(var i = 0; i < pairs.length; i++)
	{ 
		var pos = pairs[i].indexOf('='); 
		if (pos == -1) continue; 
		var argname = pairs[i].substring(0,pos); 
		var value = pairs[i].substring(pos+1); 
		args[argname] = unescape(value); 
	} 
	return args; 
} 

function getAllCookies() 
{
 var cookies  = document.cookie.replace(/ /g,"").split(";");
   for (var i = 0; i < cookies.length; i++){
     cookiePair = cookies[i].split("=");
     alert(cookiePair[0]+" = "+ cookiePair[1]);
   }
   //alert("those are all of the cookies");
   return true;
}

function gotoPage(url)
{
	window.location = url;
	return true;
}

////////////////////////set cookie functions///////////////////////////////////////
function setFastrakCookie()
{
	myDomain = ".imstransport.com";
	document.cookie= "Client Name = "+ document.frmClient.txtUsername.value +";domain = "+ myDomain +";expires = " 
	+ exptime.toGMTString()
	document.cookie= "Client Password = "+ document.frmClient.txtPassword.value +";domain = "+ myDomain +";expires = "
	+ exptime.toGMTString()
}//end function

function killFastrakCookie()
{
	myDomain = ".imstransport.com";
	if( document.getElementById("frmClient") )
	{
		if( document.getElementById("txtUsername") )
		{
			document.cookie= "Client Name = "+ document.getElementById("txtUsername").value +";domain = "+ myDomain +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
			document.getElementById("txtUsername").value = "";
		}else{
			document.cookie= "Client Name = "+ "" +";domain = "+ myDomain +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
		}
		if( document.getElementById("txtPassword") )
		{
			document.cookie= "Client Password = "+ document.getElementById("txtPassword").value +";domain = "+ myDomain +";expires = "
			+ exptime.setDate(exptime.getDate()-1);
			document.getElementById("txtPassword").value = "";	
		}else{
			document.cookie= "Client Password = "+ "" +";domain = "+ myDomain +";expires = "
			+ exptime.setDate(exptime.getDate()-1);
		}
	}else{
			document.cookie= "Client Name = "+ "" +";domain = "+ myDomain +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
			document.cookie= "Client Password = "+ "" +";domain = "+ myDomain +";expires = "
			+ exptime.setDate(exptime.getDate()-1);
	}
	return true;
}

function setIrisCookie()
{
	document.cookie= "Iris Name = "+ document.frmIris.txtiusername.value +";expires = " 
	+ exptime.toGMTString()
	document.cookie= "Iris Password = "+ document.frmIris.txtipassword.value +";expires = "
	+ exptime.toGMTString()
	document.cookie= "Iris LoginName = "+ document.frmIris.txtloginname.value +";expires = "
	+ exptime.toGMTString()
}//end function


function killIrisCookie()
{
	if( document.getElementById("frmIris") )
	{
		if( document.getElementById("txtiusername") )
		{
			document.cookie= "Iris Name = "+ document.getElementById("txtiusername").value +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
			document.getElementById("txtiusername").value = "";
		}else{
			document.cookie= "Iris Name = "+ "" +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
		}
		if( document.getElementById("txtipassword") )
		{
			document.cookie= "Iris Password = "+ document.getElementById("txtipassword").value +";expires = "
			+ exptime.setDate(exptime.getDate()-1);
			document.getElementById("txtipassword").value = "";	
		}else{
			document.cookie= "Iris Password = "+ "" +";expires = "
			+ exptime.setDate(exptime.getDate()-1);
		}
		if( document.getElementById("txtloginname") )
		{
			document.cookie= "Iris LoginName = "+ document.getElementById("txtloginname").value +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
			document.getElementById("txtloginname").value = "";
		}else{
			document.cookie= "Iris LoginName = "+ "" +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
		}		
	}else{
			document.cookie= "Iris Name = "+ "" +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
			document.cookie= "Iris Password = "+ "" +";expires = "
			+ exptime.setDate(exptime.getDate()-1);
			document.cookie= "Iris LoginName = "+ "" +";expires = " 
			+ exptime.setDate(exptime.getDate()-1);
	}
	return true;
}

function FastrakSubmit(form)
{
 if (form.txtUsername.value=="")
	{
	alert("Please enter username.");
	form.txtUsername.focus();
	return false;
	}//end if
else if (form.txtPassword.value=="")
	{
	alert("Please enter password.");
	form.txtPassword.focus();
	return false;
	}//end else if
else
	{
  	form.txtUsername.value=form.txtUsername.value.toUpperCase();
  	form.txtPassword.value=form.txtPassword.value.toUpperCase();
  	setFastrakCookie();
	document.frmClient.submit();
 	}//end else
}//end function


//**********END COOKIE / LOGIN FUNCTIONS**********//
//global variable
function random_image()
{
  var myimages=new Array();
  myimages[1]="images/main/aerial.jpg"
  myimages[2]="images/main/cargoLoading.jpg"
  myimages[3]="images/main/lanes.jpg"
  myimages[4]="images/main/newoversize.jpg"
  myimages[5]="images/main/orangeTruck"
  myimages[6]="images/main/railCars.jpg"
  myimages[7]="images/main/topLoader.jpg"
  myimages[8]="images/main/trainCars.jpg"
  myimages[9]="images/main/trucks.jpg"
  myimages[10]="images/main/twoContainers.jpg"
  myimages[11]="images/main/whiteTruck.jpg"

  imgnbr=Math.floor(Math.random()*myimages.length)
  //alert(imgnbr);
  if (imgnbr==0)imgnbr=1;
  //alert(imgSource);
  document["imgSrc"].src = myimages[imgnbr];
}

function CenteredPop(mypage, myname, w, h, scroll,resize) 
	{
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize+''
		win = window.open(mypage, myname, winprops)
		if (parseInt(navigator.appVersion) >= 4) 
		{win.window.focus(); }
	}
/////////////////////////Measurement Conversion functions//////////////////////
function calcTemp()
{
var temp = document.frm.tempVal.value;
var fromTemp = document.frm.selTemp1.options.value;
var toTemp = document.frm.selTemp2.options.value;
var t;

	if (fromTemp=="f")
		{
		if (toTemp=="f")
			{
			document.frm.tempResult.value =(temp*1)
			}
		else
			{
			t=(5/9*(temp-32));
			document.frm.tempResult.value =(Math.round(t*100)/100)
			}
		}
	else if (fromTemp=="c")
		{
		if (toTemp=="f")
			{
			t=(temp*(9/5)+32);
			document.frm.tempResult.value=(Math.round(t*100)/100)
			}
		else
			{
			document.frm.tempResult.value=(temp*1)
			}
		}
}

function calcVolume()
{
var vL = document.frm.vLength.value;
var vW = document.frm.vWidth.value;
var vH = document.frm.vHeight.value;
var fromVal = (vL*vW*vH);
var Cube1 = document.frm.selCube1.options.value;
var Cube2 = document.frm.selCube2.options.value;
var z;
     if (Cube1=="in")
		{
		if (Cube2=="ft")
			{document.frm.volResult.value=(fromVal*12)}
		else
			{z =(fromVal*0.0254); 
			document.frm.volResult.value =(Math.round(z*100)/100);}	
		}
     else if (Cube1=="ft")	   
		{
		if (Cube2=="ft")
			{document.frm.volResult.value=(fromVal*1)}
		else
			{z =(fromVal*0.3048); 
			document.frm.volResult.value =(Math.round(z*100)/100);}	
		}
     else if (Cube1=="yd")
		{
		if (Cube2=="ft")
			{document.frm.volResult.value=(fromVal/3)}
		else
			{z =(fromVal*0.9144); 
			document.frm.volResult.value =(Math.round(z*100)/100);}	
		}
     else if (Cube1=="mm")
		{
		if (Cube2=="ft")
			{z =(fromVal*304.8); 
			document.frm.volResult.value =(Math.round(z*100)/100);}
		else
			{z =(fromVal*0.001); 
			document.frm.volResult.value =(Math.round(z*100)/100);}	
		}
     else if (Cube1=="cm")
		{
		if (Cube2=="ft")
			{z =(fromVal*30.48); 
			document.frm.volResult.value =(Math.round(z*100)/100);}
		else
			{z =(fromVal*0.01); 
			document.frm.volResult.value =(Math.round(z*100)/100);}	
		}
     else if (Cube1=="m")
		{
		if (Cube2=="ft")
			{z =(fromVal*3.281); 
			document.frm.volResult.value =(Math.round(z*100)/100);}
		else
			{document.frm.volResult.value=(fromVal*1)}	
		}
}

function calcLength()
{
var qty = document.frm.lengthQty.value;
var length1 = document.frm.selLength1.options.value;
var length2 = document.frm.selLength2.options.value;
var x;
     if (length1=="in")
		{
		if (length2=="in")
			{document.frm.lengthResult.value=(qty*1);}
		else if (length2=="ft")
			{x=(qty/12);
			document.frm.lengthResult.value =(Math.round(x*100)/100);}	
		else if (length2=="yd")
			{x =(qty/36); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="mm")
			{x =(qty*25.4); 
			document.frm.lengthResult.value = (Math.round(x*100)/100);}
		else if (length2=="cm")
			{x =(qty*2.54); 
			document.frm.lengthResult.value = (Math.round(x*100)/100);}
		else
			{x =(qty*0.0254); 
			document.frm.lengthResult.value = (Math.round(x*100)/100);}
		}
     else if (length1=="ft")	   
		{
		if (length2=="in")
			{document.frm.lengthResult.value=(qty*12)}
		else if (length2=="ft")
			{document.frm.lengthResult.value=(qty*1)}	
		else if (length2=="yd")
			{x =(qty/3); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="mm")
			{x =(qty*304.79); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="cm")
			{x =(qty*30.479); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else
			{x =(qty*0.30479); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		}
     else if (length1=="yd")
		{
		if (length2=="in")
			{document.frm.lengthResult.value=(qty*36)}
		else if (length2=="ft")
			{document.frm.lengthResult.value=(qty*3)}	
		else if (length2=="yd")
			{document.frm.lengthResult.value=(qty*1)}
		else if (length2=="mm")
			{x =(qty*914.4); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="cm")
			{x =(qty*91.44); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else
			{x =(qty*0.9144); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		}
     else if (length1=="mm")
		{
		if (length2=="in")
			{x =(qty*0.03937); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="ft")
			{x =(qty*0.0032808); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}	
		else if (length2=="yd")
			{x =(qty*0.0010936); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="mm")
			{document.frm.lengthResult.value=(qty*1)}
		else if (length2=="cm")
			{document.frm.lengthResult.value=(qty*0.1)}
		else
			{document.frm.lengthResult.value=(qty*0.001)}
		}
     else if (length1=="cm")
		{
		if (length2=="in")
			{x =(qty/2.54); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="ft")
			{x =(qty/30.48); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}	
		else if (length2=="yd")
			{x =(qty/91.44); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="mm")
			{document.frm.lengthResult.value=(qty*10)}
		else if (length2=="cm")
			{document.frm.lengthResult.value=(qty*1)}
		else
			{document.frm.lengthResult.value=(qty*0.01)}
		}
     else if (length1=="m")
		{
		if (length2=="in")
			{x =(qty*39.3700787); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="ft")
			{x =(qty*3.281); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}	
		else if (length2=="yd")
			{x =(qty*1.0936133); 
			document.frm.lengthResult.value =(Math.round(x*100)/100);}
		else if (length2=="mm")
			{document.frm.lengthResult.value=(qty*1000)}
		else if (length2=="cm")
			{document.frm.lengthResult.value=(qty*100)}
		else
			{document.frm.lengthResult.value=(qty*1)}
		}
}

function calcWeight()
{
var qty = document.frm.weightQty.value;
var weight1 = document.frm.selWeight1.options.value;
var weight2 = document.frm.selWeight2.options.value;
var y;
     if (weight1=="lb")
		{
		if (weight2=="lb")
			{document.frm.weightResult.value=(qty*1)}
		else if (weight2=="kg")
			{y =(qty*0.4536); 
			document.frm.weightResult.value =(Math.round(y*100)/100);}	
		else
			{y =(qty*0.0004535); 
			document.frm.weightResult.value =(Math.round(y*100)/100);}
		}
     else if (weight1=="kg")	   
		{
		if (weight2=="lb")
			{y =(qty*2.2046); 
			document.frm.weightResult.value =(Math.round(y*100)/100);}
		else if (weight2=="kg")
			{document.frm.weightResult.value=(qty*1)}	
		else
			{y =(qty/1000);
			document.frm.weightResult.value=(Math.round(y*100)/100);}
		}
     else if (weight1=="mt")
		{
		if (weight2=="lb")
			{y =(qty*2204.6); 
			document.frm.weightResult.value =(Math.round(y*100)/100);}
		else if (weight2=="kg")
			{document.frm.weightResult.value=(qty*1000)}	
		else
			{document.frm.weightResult.value=(qty*1)}
		}
}

function clearLength()
	{
		document.frm.lengthQty.value=0;
		document.frm.selLength1.options.value="in";
		document.frm.selLength2.options.value="ft";
		document.frm.lengthResult.value=0;		
	}

function clearWeight()
	{
		document.frm.weightQty.value=0;
		document.frm.selWeight1.options.value="lb";
		document.frm.selWeight2.options.value="kg";
		document.frm.weightResult.value=0;		
	}

function clearVolume()
	{
		document.frm.vLength.value=0;
		document.frm.vWidth.value=0;
		document.frm.vHeight.value=0;
		document.frm.selCube1.options.value="in";
		document.frm.selCube2.options.value="ft";
		document.frm.volResult.value=0;		
	}

function clearTemp()
	{
		document.frm.tempVal.value=0;
		document.frm.selTemp1.options.value="f";
		document.frm.selTemp2.options.value="c";
		document.frm.tempResult.value=0;		
	}
	
///////////////////////////////////////////////////////////////////////////////
	
function checkSpecs()
	{//validate that something has been selected
	if (document.frmSpecs.Size.value==""){alert("Please select a size.");document.frmSpecs.Size.focus();return false;}
	if (document.frmSpecs.Type.value==""){alert("Please select a Type.");document.frmSpecs.Type.focus();return false;}
	}//end of function

function checkZipForm()
	{//validate that one of the three fields has been filled, to continue with search
	if ((document.frmZip.txtZip.value=="")&&(document.frmZip.txtCity.value==""))
		{
		if (document.frmZip.txtState.value=="")
			{
			alert("Please enter search criteria!");document.frmZip.txtZip.focus();return false;
			}
		}
	}//end of function

function getDistance()
	{//validate that both fields have been filled, to continue with search
	if((document.frmDistance.zipOne.value.length==0)||(document.frmDistance.zipOne.value==null))
		{alert("Please provide Zip One information");document.frmDistance.zipOne.focus();return false;}	
	if((document.frmDistance.zipTwo.value.length==0)||(document.frmDistance.zipTwo.value==null))
		{alert("Please provide Zip Two information");document.frmDistance.zipTwo.focus();return false;}	
	}//end function
	
function clearZipSearch()
	{//used to reset zip search
	document.frmZip.txtZip.value="";
	document.frmZip.txtCity.value="";
	document.frmZip.txtState.value="";
	document.frmZip.txtZip.focus();
	}//end of function

function clearDistance()
	{//used to reset distance search
	document.frmDistance.zipOne.value="";
	document.frmDistance.zipTwo.value="";
	document.frmDistance.selMeasure.value="M";
	document.frmDistance.zipOne.focus();
	}//end of function
	
function validateContactUs(frm)
{//validate that these 4 fields have been filled...
		if (frm.Department.value.length == 0){alert("Please select a department.");frm.Department.focus();return false;}
		else if (frm.Name.value.length == 0){alert("Please enter your name.");frm.Name.focus();return false;}
		else if (frm.Comments.value.length == 0){alert("Please supply your comments/suggestions.");frm.Comments.focus();return false;}
		else if (frm.email.value.length == 0){alert("Please advise your email address, so we can contact you.");frm.email.focus();return false;}
		else {return true;}
}//end function

function validateVendorProfile(profile)
{//validate that these 6 fields have been filled...
		if (profile.CompanyName.value.length==0){alert("Please enter Company Name.");profile.CompanyName.focus();return false;}
		else if (profile.Address.value.length==0){alert("Please enter Company Address.");profile.Address.focus();return false;}
		else if (profile.City.value.length==0){alert("Please enter Company City.");profile.City.focus();return false;}
		else if (profile.State.value.length==0){alert("Please enter Company State.");profile.State.focus();return false;}
		else if (profile.email.value.length==0){alert("Please enter Company Email Address.");profile.email.focus();return false;}
		else {return true;}
}//end function

/////////////////////////////////////////////////
function VendorSubmit(frm)
{
	 if(document.frmVendor.username.value=="")
	 	{
		alert("Please enter username.");document.frmVendor.username.focus();return false;
		}//end if
	 else if (document.frmVendor.password.value=="")
	 	{
		alert("Please enter password.");document.frmVendor.password.focus();return false;
		}//end else if
	 else
		{
		document.frmVendor.username.value=document.frmVendor.username.value.toUpperCase();
		document.frmVendor.password.value=document.frmVendor.password.value.toUpperCase();
		document.frmVendor.submit();
		}//end else
}
/////////////////////////////////////////////////
function checkLogin(num)
{	
	if(num==1)
		{
		  if(document.getElementById("txtUsername").value.length==0)
			  {				  
 			  document.getElementById("FTRKloginDiv").style.visibility = "hidden";
			  document.getElementById("FTRKloginDiv").style.display = "none";
			  document.getElementById("FTRKfields").style.visibility = "visible";
			  document.getElementById("FTRKfields").style.display = "block";
			  document.getElementById("IRISfields").style.visibility = "hidden";
			  document.getElementById("IRISfields").style.display = "none";
			  document.getElementById("VENDfields").style.visibility = "hidden";
			  document.getElementById("VENDfields").style.display = "none"; 
			  }
		  else
		  {
		  //cookie must be set, so submit
		   document.frmClient.submit();
		  }
		}
	else if(num==2)
		{
			  document.location = "https://apps.imstransport.com/login.php?login=client";
		}
	else if(num==3)
		{
			  document.location = "https://apps.imstransport.com/login.php?login=vendor";
		}
}

/////////////////////////////////////////////////
function isVtrackCookieSet()
{
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttpUniqueInv = new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttpUniqueInv = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttpUniqueInv = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  var url = "http://64.19.190.102/vtrack/vTrackLogin.php";
  var retval = 0;
//  xmlHttpUniqueInv.open("GET",url,false);

//  xmlHttpUniqueInv.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
//  xmlHttpUniqueInv.send(null);

/*
alert(xmlHttpUniqueInv.status);

  if(xmlHttpUniqueInv.readyState==4)
  {
    retval = xmlHttpUniqueInv.responseText;
	alert(retval);
  }
*/
return retval;
}

function viewAnswer(answer)
{
		if(document.getElementById('A'+answer).innerHTML == "[+]&nbsp;")
		{
		document.getElementById('A'+answer).innerHTML = "[-]&nbsp;";
		document.getElementById(answer).style.visibility = "visible";
		document.getElementById(answer).style.display = "block";
		}
		else
		{
		document.getElementById('A'+answer).innerHTML = "[+]&nbsp;";
		document.getElementById(answer).style.visibility = "hidden";
		document.getElementById(answer).style.display = "none";
		if(answer == '2')
			{
			document.getElementById(answer+'a').style.visibility = "hidden";
			document.getElementById(answer+'a').style.display = "none";
			document.getElementById(answer+'b').style.visibility = "hidden";
			document.getElementById(answer+'b').style.display = "none";
			document.getElementById(answer+'c').style.visibility = "hidden";
			document.getElementById(answer+'c').style.display = "none";
			document.getElementById(answer+'d').style.visibility = "hidden";
			document.getElementById(answer+'d').style.display = "none";
			document.getElementById(answer+'e').style.visibility = "hidden";
			document.getElementById(answer+'e').style.display = "none";
			document.getElementById(answer+'f').style.visibility = "hidden";
			document.getElementById(answer+'f').style.display = "none";
			}	
		}
}

function viewAnswerSub(subanswer)
{
		if(document.getElementById(subanswer).style.visibility =="hidden")
		{
		document.getElementById(subanswer).style.visibility = "visible";
		document.getElementById(subanswer).style.display = "block";
		}
		else
		{
		document.getElementById(subanswer).style.visibility = "hidden";
		document.getElementById(subanswer).style.display = "none";
		}
}