





/****************************************************/
/*ValidatePro Function:								*/
/*	Validates a pronumber							*/
/****************************************************/
function ValidatePro(sProNum) 
{
	// Declare Local Variables
	var sPrefix;
	var sTempProNum;
	var bProIsValid;
	var sBody;
	var sReturnMsg;
	
	// Set initial values
	bProIsValid = true;
	sReturnMsg = "Valid Pro";
	
	// Copy pro num to a temp variable
	sTempProNum = sProNum;
	
	// find the first dash
	nFirstDash = sTempProNum.indexOf('-');

	// If the Dash is >0 then continue else it's a bad
	//  pro
	if(nFirstDash > 0)
	{
		// Parse out the Pro Prefix
		sPrefix = sTempProNum.substring(0,nFirstDash);
		
		// Verify the terminal Prefix is a valid terminal
		var cTermCookie = document.cookie;
		if(cTermCookie == "")
		{
			// bad pro,  Term list cookie is invalid
			bProIsValid = false;
			sReturnMsg = "Unable to verify pro,  Term list invalid";
		}
		
		nIndexTerm = cTermCookie.indexOf(sPrefix);
		
		if(nIndexTerm < 1)
		{
			// bad pro,  Pre prefix not valid
			bProIsValid = false;
			sReturnMsg = "Pre prefix not valid";
		}
		
		sTempProNum = sTempProNum.substr(nFirstDash+1, sTempProNum.length );
		
		// Find the Second Dash
		nSecondDash = sTempProNum.indexOf('-');
		
		// If the Dash is >0 then continue else it's a bad
		//  pro
		if(nSecondDash > 0)
		{
			//Parse out the body of the pro
			sBody = sTempProNum.substring(0,nSecondDash);
			sTempProNum = sTempProNum.substr(nSecondDash+1, sTempProNum.length );
									
			//Parse out the check digit of the pro
			sCheckDigit = sTempProNum.substring(0, 1);
			
			// Check to see if we have a suffix pro
			if(sTempProNum.length > 1)
			{
				// Find the third Dash
				nThirdDash = sTempProNum.indexOf('-');
				
				if(nThirdDash > 0)
				{
					//Parse out the body of the pro
					sProSuffix = sTempProNum.substring(nThirdDash+1, sTempProNum.length );
					
					if( sProSuffix.length > 2 )
					{
							// bad pro,  Suffix length must be not > 2
							bProIsValid = false;
							sReturnMsg = "Suffix length must be not > 2";
					}
					else
					{
						if( !IsAlpha( sProSuffix ) )
						{
							// bad pro,  Suffix must be Alpha
							bProIsValid = false;
							sReturnMsg = "Suffix must be Alpha";
						}
					}
				}
				else
				{
					// bad pro,  Suffix pro with no suffix
					bProIsValid = false;
					sReturnMsg = "Suffix pro with no suffix";
				}
			}
			
			// Verify the Length of the Pro Body,  it must be 6 bytes
			nBodyLen = sBody.length;
			if(nBodyLen != 6)
			{
				// bad pro,  Pro Body must be 6 bytes
				bProIsValid = false;
				sReturnMsg = "Pro Body must be 6 bytes";
			}
			else
			{
				nCalcCheckDigit = CalculateChkDigit(sBody);
				
				if(nCalcCheckDigit != sCheckDigit)
				{
					// bad pro,  Invalid Check Digit
					bProIsValid = false;
					sReturnMsg = "Invalid Check Digit";
				}
			}
		}
		else
		{
			// bad pro,  no check digit supplied
			bProIsValid = false;
			sReturnMsg = "no check digit supplied";
		}
	}
	else
	{
		// bad pro,  no pro body supplied
		bProIsValid = false;
		sReturnMsg = "no pro body supplied";
	}
	
	
	// Return results
	return bProIsValid;
}

/****************************************************/
/*CalculateChkDigit Function:										*/
/*	Calculates the Check Digit for a pro number		*/
/****************************************************/
function CalculateChkDigit(sProBody)
{
	// Declare Local Variables
	var nFactor = 1;
	var nDigitTotal = 0;
	var nProduct = 0;
	
	aBodyChar = sProBody.split("");
	
	for(i = 0; i < 6; i++)
	{
		nProduct = aBodyChar[i] * nFactor;
		
		if(nProduct > 9)
			nProduct = (nProduct - 10) + 1;
			
		nDigitTotal = nDigitTotal + nProduct;
		
		if(nFactor == 1)
			nFactor = 2;
		else
			nFactor = 1;
	}
	
	//  Calculate check digit
	nFactor = 0;

	while(nFactor < nDigitTotal)
	{
		nFactor = nFactor + 10;
	}
	return (nFactor - nDigitTotal);
}

/****************************************************/
/*Alpha Function:										*/
/*	Checks to see if the characters are Alpha		*/
/****************************************************/
function IsAlpha( str ) 
{
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "") 
		return false;
		
	var isValid = true;
	str += ""; // convert to a string for performing string comparisons.
	
	// Loop through string one character at time, breaking out of for
	// loop when an non Alpha character is found.
	for (i = 0; i < str.length; i++) 
	{
		// Alpha must be between "A"-"Z", or "a"-"z"
		if ( !( ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) || ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ) ) 
		{
			isValid = false;
			break;
		}
	} // end for loop
	
	return isValid;
} // end

/****************************************************/
/*Key Function:										*/
/*	Moves the curser for one field to the next		*/
/****************************************************/
function key(thisfield, nextfield){ 
	var num = thisfield.value; 
	if (num.length == thisfield.maxLength) nextfield.focus();
} 

function printView()
{
	 document.styleSheets[0].href ="http://sdokic/cinet/print.css";
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
	function ValidateForm(){
	var emailID=document.frmHeader.strFrom
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }



/*function sendEmail()
   {
    	var strHtml=document.getElementById("start").innerHTML;
		var t=/</g;
		var s=/>/g;
		var over=/onmouseover/g;
		var out=/onmouseout/g;
		var script=/javascript/g;
		var sub=/onsubmit/g;
		var chg=/onchange/g;
		var cl=/onclick/g;
		var k=/onkeyup/g;
		
		strHtml=strHtml.replace(t,"*$");
		strHtml=strHtml.replace(s,"!@");
		strHtml=strHtml.replace(over,"23#");
		strHtml=strHtml.replace(out,"35#")
		strHtml=strHtml.replace(script,"&@100");
		strHtml=strHtml.replace(sub,"!&@200");
		strHtml=strHtml.replace(chg,"&@300");
		strHtml=strHtml.replace(cl,"&@400");
		strHtml=strHtml.replace(k,"&@500");
		var title=document.getElementById("title_1").innerText;
		title=title.replace("Central Transport International, Inc. - ","");
		title=title.replace("Central Transport International - ","");
		text = ("<HTML\n><HEAD>\n");
		
	
		text=text+("<TITLE>E-mail Form</TITLE></HEAD>\n");
		text = (text +"<BODY BGCOLOR = '#FFFFFF' ><CENTER><B><FONT COLOR='#000000' size='2'>Central Transport Int.<BR></FONT></B></CENTER>\n");
		text=(text+"<hr>");
		text=(text+"<form name='frmHeader' method='post' action='../Components/EmailPage.aspx' onSubmit='return alidateForm()'>\n");
		text=(text+"<TABLE><TR><TD><b>From:</b></td>\n");
		text=(text+"<td><input type='text' name='strFrom' size='35' value='ksklar@centraltransportint.com'></td></tr>\n<tr><td><b>To:</b></td><td><input type='text' size='35' name='strTo' value='sdokic@centraltransportint.com'></td></tr>");
		text=(text+"<tr><td><b>Subject:</b></td><td><input type='text' size='35' name='strSubject' value='"+title+"'></td></tr>\n");
		text=(text+"<tr><td>Message:</td><td><TEXTAREA rows='5' cols='36' name='strText'></textArea></td></tr>\n<tr><td colspan='2'><TEXTAREA rows='1' cols='1' style='DISPLAY: none' name='strMessageHTML'>"+strHtml+"</TEXTAREA></td></tr>\n");
		text=(text+"<tr><td colspan='2' align='center'><input type='Submit' name='bSubmit' value='Send'></td></tr>\n</table></form>\n\n");
		text=(text+"</body></html>");
		var msgWindow=window.open("","displayWindow","toolbar=yes,width=440,height=280,directories=no,status=no,scrollbars=no,resize=no,menubar=no");
		msgWindow.document.write(text);
   }
   */
   
   
   function normalView()
   {
      document.styleSheets[0].href ="cti_style.css";
   }
   
/****************************/
/*Open Calendar Function	*/
/****************************/
function OpenCalendar(control){
		var path = '<asp:Literal id="AppPath" runat="server"/>'+ "/Components/Calendar.aspx?control=" + control;
	window.open(path,"","status=no,toolbar=no,menubar=no,location=no,resizable=yes,width=500,height=500");
}

/**************************************************/
/*Open Zip Function	 everything must be written in
/*MainTemplate.acsx and MainTemplate.ascx.cs files*/ 

/*************************************************/
function OpenZip(control){
		var path = '<asp:Literal id="AppPathZip" runat="server"/>'+ "/Components/ZipCode.aspx?control=" + control;
	window.open(path,"","status=no,toolbar=no,menubar=no,location=no,resizable=yes,width=500,height=500");
}

/****************************/
/*Toggle Menu Function		*/
/****************************/
function ToggleMenu(e)
				{
					
					var controlName = e.parentElement.parentElement.parentElement.id + "_Detail";
				
					var detailTable	= document.getElementsByName(controlName)[0];
					
					
					if (detailTable.style.display == "none")
					{	
						detailTable.style.display = "";	
					}	
					else
					{	
						detailTable.style.display = "none";
					}			
				}	

