function isNumber(pVal)
{
	var i;

	for(i = 0; i < pVal.length; i++) 
	{
		if(!isNaN(parseInt(pVal.substring(i, i + 1)))) 
		{
			return false;
		}
	} 
	return true;
}

// ********************************************************
// This function accepts a string variable and verifies if
// it is in the proper format for an e-mail address or not.

// The function returns true if the format is valid, false
// if not.
// ********************************************************

function isEmail(email) 
{
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    // Check for null
    if (email == "") 
	{
        return false;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) 
	{
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) 
		{
            return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) 
	{
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") 
	{
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) 
	{
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") 
		{
            return false;
        }
        if (Pos != -1) 
		{
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) 
	{
        return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) 
	{
        return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) 
	{
        return false;
    }
    if (periodPos+3 > email.length) 
	{
        return false;
    }
    return true;
}

function checkFields(thisform)
{
	//qtn 1
	if(thisform.requestor.value == "")
	{
		alert("Please provide a contact name.");
		thisform.requestor.focus();
        return false;
	}
	
	//qtn 2	
	if(!(isEmail(thisform.email.value)))
	{
		alert("Please provide a proper email.");
		thisform.email.focus();
		return false;	
	}
	
	//qtn 3	
	if(thisform.cgoType.value == "")
	{
		alert("Please provide the cargo type.");
		thisform.cgoType.focus();
        return false;
	}
	
	//qtn 4 - wgt ========================================================
	if( (thisform.wgt.value == "") )
	{
		alert("Please provide the weight for item 1.");
		thisform.wgt.focus();
        return false;
	}
	
	if( isNaN(thisform.wgt.value) )
	{
		alert("Please ensure the weight value is in numeric format.");
		thisform.wgt.focus();
        return false;
	}
	
	//qtn 4 - dims
	if(thisform.dims.value == "")
	{
		alert("Please provide the dimensions for item 1.");
		thisform.dims.focus();
		return false;
	}
	
	//qtn 4 - pcs
	if( (thisform.pieces.value == "") || isNaN(thisform.pieces.value) )
	{
		alert("Please provide the number of pieces for item 1.");
		thisform.pieces.focus();
		return false;
	}
	
	//qtn 4 item 2
	if( (thisform.wgt2.value != "") )
	{
		if(thisform.dims2.value == "")
		{
			alert("Please provide the dimensions for item 2.");
			thisform.dims2.focus();
			return false;
		}
		
		//qtn 4 - pcs
		if( (thisform.pieces2.value == "") || isNaN(thisform.pieces2.value) )
		{
			alert("Please provide the number of pieces for item 2.");
			thisform.pieces2.focus();
			return false;
		}
	}
	
	//qtn 4 item 3
	if( (thisform.wgt3.value != "") )
	{
		if(thisform.dims3.value == "")
		{
			alert("Please provide the dimensions for item 3.");
			thisform.dims3.focus();
			return false;
		}
		
		//qtn 4 - pcs
		if( (thisform.pieces3.value == "") || isNaN(thisform.pieces3.value) )
		{
			alert("Please provide the number of pieces for item 3.");
			thisform.pieces3.focus();
			return false;
		}
	}
	
	//========================= end qtn 4 ===================================
	
	
	//qtn 5
	if (thisform.specialHandlingOption.value == "Yes")
	{		
		if(thisform.specialHandling.value == "")
		{
			alert("Please provide special handling details.");
			thisform.specialHandling.focus();
			return false;
		}
	}
	
	//qtn 6
	if(thisform.prefUpl.value == "")
	{
		alert("Please provide the preferred uplift airport.");
		thisform.prefUpl.focus();
		return false;
	}
	
	//qtn 7
	if(thisform.prefDisc.value == "")
	{
		alert("Please provide the preferred discharge airport.");
		thisform.prefDisc.focus();
		return false;
	}
	
	
	// qtn 11
	if(thisform.regularity.value == "oneOff")
	{
		if(thisform.earliestUpl.value == "")
		{
			alert("Please provide the earliest uplift date/time at origin airport.");
			thisform.earliestUpl.focus();
			return false;
		}
		
		if(thisform.deliveryDate.value == "")
		{
			alert("Please provide the delivery date.");
			thisform.deliveryDate.focus();
			return false;
		}
	}
	
	// qtn 11
	if(thisform.regularity.value == "regular")
	{
		if(thisform.frequency.value == "")
		{
			alert("Please provide the movement frequency.");
			thisform.frequency.focus();
			return false;
		}
		
		if(thisform.startDate.value == "")
		{
			alert("Please provide the start date.");
			thisform.startDate.focus();
			return false;
		}
		
		if(thisform.endDate.value == "")
		{
			alert("Please provide the end date.");
			thisform.endDate.focus();
			return false;
		}
	}
	
	//qtn 12
	if(thisform.attendants.value == "Yes")
	{
		if( (thisform.attendantNbr.value == "") || isNaN(thisform.attendantNbr.value) )
		{
			alert("Please provide the attendant number.");
			thisform.attendantNbr.focus();
			return false;
		}
	}
	
}



