From: Utkarsh Upadhyay [mailto:[email protected]] Sent: Friday, February 24, 2006 1:08 PMTo: '[email protected]'Subject: if attchment is not opening in prv mail copy this code in .js file
//Created By : Utkarsh Upadhyay
//Created Date : 02/02/06
//Description : Consist of Client-side validations
//Modified By : Utkarsh Upadhyay
//Modified Date : 13/02/06
function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}
function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }
function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) {els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
//Browser check
//Used for compatibility with firefox.Gets the sibling of element
function getPrvSibling(startBrother)
{
endBrother=startBrother.previousSibling;
while(endBrother.nodeType!=1){
endBrother = endBrother.previousSibling;
return endBrother;
//For Calender
function callDate(txtId,txtIdPosition)
x=document.getElementById(txtId);
x1=document.getElementById(txtIdPosition);
popUpCalendar(x1,x,'dd/mm/yyyy');
//Not in Use: Backspace and delete do not work when using these functions.
//allows only alpahbets and space
/*function funNotNumbers(e)
var keynum;
var keychar;
var numcheck;
if(window.event) // IE
keynum = e.keyCode;
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which;
keychar = String.fromCharCode(keynum);
numcheck = /^[A-Za-z ]/;
return numcheck.test(keychar);
*/
//returns only numbers
/* function funOnlyNumbers(e)
numcheck = /\d/;
//Allows only numbers and hyphen in the text field
//Used for validating BSB no in payment
function funOnlyNumbersandHyphen(e)
numcheck = /[\d-]/;
//Validates Email
//I/P param: Takes id of the control to validate.
function funEmailValidation(id)
var emailPat = /^[A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)*[@][A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)+$/;
if(document.getElementById(id).value==''|| document.getElementById(id).value ==null)
return true;
var objEmail = document.getElementById(id).value;
var matchArray = objEmail.match(emailPat);
if (matchArray == null)
// alert ("Enter valid email address.");
document.getElementById(id).value="";
document.getElementById(id).focus();
return false;
//Capitilise the first letter of the string provided as i/p
//I/p parameter: id of the control whose text has to be changed.
function funCapitilise(id)
var tmpStr, tmpChar, preString, postString, stringLen ,i,loop;
tmpStr = document.getElementById(id).value.toLowerCase();
strLen= tmpStr.length;
if (strLen > 0)
for (j= 0; j < strLen; j++)
if (tmpStr.substring(0,1) ==" ")
postString = tmpStr.substring(1,strLen);
tmpStr = postString;
stringLen = tmpStr.length;
if (stringLen > 0)
for (i = 0; i < stringLen; i++)
if (i == 0 )
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,stringLen);
tmpStr = tmpChar + postString;
else
tmpChar = tmpStr.substring(i,i+1);
if (tmpChar == " " && i < (stringLen-1))
tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
preString = tmpStr.substring(0,i+1);
postString = tmpStr.substring(i+2,stringLen);
tmpStr = preString + tmpChar + postString;
document.getElementById(id).value = tmpStr;
return tmpStr;
// Validates Date
//i/p parameter: Takes id of day,month and year control
function funDate(idDay,idMonth,idYear)
var day = document.getElementById(idDay).value;
var month = document.getElementById(idMonth).value;
var year = document.getElementById(idYear).value;
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
document.getElementById(idMonth).value='1';
if (month == 2) // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
// Comapares date with the current date , if entered date is greater than today's date
// it returns false. i/p parameter: id of control,current year is passed from the server.
function funCurrentDate(objCurDate,currYear)
var curDate=document.getElementById(objCurDate).value;
var dt=curDate.split("/");
var day = dt[0];
var month = dt[1];
var year1 = dt[2];
var currentDate = new Date();
var brwName = navigator.appName;
if(year1 > currYear)
// alert("Year cannot be greater than current year");
alert("Enter valid date.");
if(year1 < currYear)
if(year1 == currYear)
// return false;
if(month > (currentDate.getMonth()+1))
alert("Month cannot be greater than current month");
if(day > currentDate.getDate() && month == (currentDate.getMonth()+1))
alert("Date cannot be greater than today's date");
//Not in use.
function funCurrentDate1(strDate)
// var ArrDt=document.getElementById(strDate).value;
// var day = ArrDt[0];
// var month = ArrDt[1];
// var year = ArrDt[2];
// var currentDate = new Date();
// var currentYear = currentDate.getYear();
// if(year < currentYear)
// {
// return true;
/// }
// if(year > currentYear)
// alert("Year can not be greater than current year.")
// }
// if(year == currentYear)
// // alert("Year cannot be greater than current year");
// // return false;
//
// if(month > (currentDate.getMonth()+1))
// alert("Month cannot be greater than current month");
// document.getElementById(strDate).focus();
// else
// if(day > currentDate.getDate() && month == (currentDate.getMonth()+1))
// alert("Date cannot be greater than today's date");
// Required field validator
// i/p parameter: array of controls which are mandatory and to be validated.
function funRequiredFields(arrControls)
var len = arrControls.length;
var arrReturnedControls = new Array();
for (i=0;i<len;i++)
//For radio button
if(document.getElementById(arrControls[i]).type == 'radio' && document.getElementById(arrControls[i+1]).type == 'radio' )
i=i+1;
if(document.getElementById(arrControls[i]).checked==false && document.getElementById(arrControls[i-1]).checked==false)
document.getElementById(arrControls[i]).focus();
if(document.getElementById(arrControls[i]).title != "XYZ")
var chd=document.createElement("ABC");
chd.style.color="Red";
var txt =document.createTextNode("*","nodeStar");
chd.appendChild(txt);
if(brwName=="Microsoft Internet Explorer")
document.getElementById(arrControls[i]).parentNode.insertBefore(chd, document.getElementById(arrControls[i]).previousSibling);
document.getElementById(arrControls[i]).title="XYZ";
document.getElementById(arrControls[i]).parentNode.appendChild(chd);
arrReturnedControls[arrReturnedControls.length] =arrControls[i];
//For text box
else if(document.getElementById(arrControls[i]).type == 'text')
var i , strLen,tempStr;
tmpStr = document.getElementById(arrControls[i]).value.toLowerCase();
{ //Removes all the leading spaces
if(document.getElementById(arrControls[i]).value=='' || document.getElementById(arrControls[i]).value.length <= 0 )
//Array of controls to be returned
//For checkbox
else if(document.getElementById(arrControls[i]).type == 'checkbox')
if(document.getElementById(arrControls[i]).checked!=true)
//For rest of controls
if( document.getElementById(arrControls[i]).value=="Select.." || document.getElementById(arrControls[i]).value=="" || document.getElementById(arrControls[i]).value=="Years" || document.getElementById(arrControls[i]).value=="Months" ||document.getElementById(arrControls[i]).value=="Days" ||
document.getElementById(arrControls[i]).value=="Year" || document.getElementById(arrControls[i]).value=="Month" ||document.getElementById(arrControls[i]).value=="Day")
if(arrReturnedControls.length != 0)
document.getElementById(arrReturnedControls[0]).focus(); //Sets focus to the first control to be validated.
return arrReturnedControls; //Array of controls to be returned.
//Validates Phone no's
//At least two Ph no are mandatory.
function funValidateNoOfPhones()
var count;
var objPh1 = document.getElementById("txtHomePh2").value;
var objPh2 = document.getElementById("txtWorkPh2").value;
var objPh3 = document.getElementById("txtMobNo").value;
var objPh4 = document.getElementById("txtHomePh1").value;
var objPh5 = document.getElementById("txtWorkPh1").value;
if((objPh1 == '____ ____' && objPh4 != '__') || (objPh1 != '____ ____' && objPh4 == '__'))
alert("Enter valid phone number!");
return;
if((objPh2 == '____ ____' && objPh5 != '__') ||(objPh2 != '____ ____' && objPh5 == '__'))
count=0;
if (objPh1 != '____ ____' && objPh4 != '__')
count= count +1;
if (objPh2 != '____ ____' && objPh5 != '__')
if (objPh3 != '____ ___ ___')
if (count < 2)
alert("Enter atleast two Phone Numbers");
document.getElementById("txtHomePh1").focus();
//Populates the Year combo
//i/p parameter: Id of year control
function funPopulateYear(idYear)
var optn;
var currentYear = currentDate.getYear();
for(var iCount =currentYear ; iCount>=1900;iCount--)
optn = document.createElement("option");
var txt = document.createTextNode(iCount);
optn.appendChild(txt);
optn.setAttribute("value",iCount);
document.getElementById(idYear).appendChild(optn);
//This function is currently not in use.
function funPopulateYearforQuote4(idYear)
for(var iCount =1988 ; iCount>=1900;iCount--)
for(var iCount =currentYear ; iCount>1988;iCount--)
// Comapares date with the current date , if entered date is less than today's date
// it returns false. i/p parameter: id of controls and current Year.
function funGCurrentDate(objcurDate,currentYear)
var curDate=document.getElementById(objcurDate).value;
var year = dt[2];
if(year < currentYear)
alert("Year cannot be less than current year");
if(year > currentYear)
if(year == currentYear)
if(month < (currentDate.getMonth()+1))
alert("Month cannot be less than current month");
if(day < currentDate.getDate() && month <= (currentDate.getMonth()+1))
alert("Date cannot be less than today's date");
//Display Error Message
function DisplayErrorMessage(result)
for (var iCount = 0 ; iCount<result.length;iCount++)
document.getElementById(result[iCount]).parentNode.previousSibling.style.color="Red";
document.getElementById("divError").style.display="block";
var objTd=getPrvSibling(document.getElementById(result[iCount]).parentNode);
objTd.style.color="Red";
//Takes event as argument.
function funOnlyNumbers(evt)
(evt)? evt:event;
if(navigator.appName == "Microsoft Internet Explorer")
var charCode = evt.keyCode;
var charCode = (evt.charCode)?evt.charCode:((evt.KeyCode)?evt.keyCode:((evt.which)?evt.which:0));
if(charCode >32 && (charCode <48 || charCode>57))
//Takes event argument.
function funNotNumbers(evt)
if(charCode >32 && (charCode <65 || charCode >90) && (charCode<97 || charCode>122))