//// main functions Java script file ////

function path(abc)
  {

 document.frm.action=abc
 document.frm.submit()
  }
  
function reload_evbook(strurl)
{
	if (document.frm.member_number.value!='')	
	{
		document.frm.action=strurl;
		document.frm.submit();	
	}	
}


function isEmpty (str) {
	if ((str==null)||(str.length==0)) return true;
	else return(false);

}

function validnull(item3)
      {
         if (item3.length==0)
          {
            return false;
          }
         return true;
     }


function isInt (item) {
	var flag = true;

	if (isEmpty(item)) { flag=false; }
	else
	{	for (var i=0; i< item.length; i++) {
			if (isDigit(item.substring(i,i+1)) == false) {
				flag = false; break;
			}
		}
	}
	return(flag);
}

function isDigit(theNum) {
	var theMask = '0123456789';
	
	if (isEmpty(theNum)) return(false);
	else if (theMask.indexOf(theNum) == -1) return(false);
	
	return(true);
}

function FindCompanyAddress()
 {
	Pcode=document.frm.com_postcode.value
	company_country=document.frm.company_country.value
	//alert(country)

		if (Pcode!="" && company_country=="UK")
		{
			
			Company=document.frm.CompanyhouseNo.value
			path="FindAddress.asp?Pcode=" + Pcode + "&CompanyHouse=" + Company
			window.open(path,"FindAddress","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width=400,height=400")	
			window.name="postcode"	
		}
		else
		{
			if (company_country!="UK")
			alert("Only for UK address.")
			else
			alert("Please enter company postcode.")
		}


 }

function help()
{
	window.open("PostCodeHelp.htm","Help","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width=420,height=355")	
}

function FindAddress()
 {
	
	Pcode=document.frm.post_code.value
	country=document.frm.country.value
	//alert(country)
	if (Pcode!="" && country=="UK")
	{
		
		house=document.frm.houseNo.value
		path="FindAddress.asp?Pcode=" + Pcode + "&HouseID=" + house
		window.open(path,"FindAddress","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width=400,height=400")	
		window.name="postcode"	
	}
	else
	{
		if (country!="UK")
		alert("Only for UK address.")
		else
		alert("Please enter home postcode.")
	}

 }

function foc()
 {
 
 document.frm.Last_name.focus();
 
 }
/*function pcupper(object)
{

	document.all.item(object).value =  document.all.item(object).value.toUpperCase()
	/*switch(object)
	{
		case "post_code":
			document.all.item(object).value =  document.all.item(object).value.toUpperCase()
			break;
		case "com_postcode":
			document.frm.com_postcode.value = document.frm.com_postcode.value.toUpperCase()
			break;
	}*/
//}


countryflag=false
company_countryflag=false
Invoice_countryflag=false
function postcheck(obj)
{
	switch(obj)
	{
		case "country":
			if(document.frm.country.value != 'UK')
			{
				// by 'ZA_20030113 document.frm.houseNo.disabled=true
				if (countryflag==false)
					{
						alert("Postcode only mandatory for UK Applications")
						countryflag=true
					}
				//by 'ZA_20030121 document.frm.post_code.style.background  = "lightgrey"
				strmand = ''
			}
			else
			{
				countryflag=false
				//by 'ZA_20030121 document.frm.post_code.style.background  = "#a4b3f0"
				// by 'ZA_20030113 document.frm.houseNo.disabled=false
			}
			break;
		case "company_country":
			
			if(document.frm.company_country.value != 'UK')
			{
				// by 'ZA_20030113 document.frm.CompanyhouseNo.disabled=true
				if (company_countryflag==false)
				{	
					alert("Postcode only mandatory for UK Applications")
					company_countryflag=true
				}	
				// by 'ZA_20030121 document.frm.com_postcode.style.background = "lightgrey" 
				
				strmand = ''
			}
			else
			{
				
				company_countryflag=false
				// 'ZA document.frm.com_postcode.style.background = "#a4b3f0"
				// by 'ZA_20030113 document.frm.CompanyhouseNo.disabled=false
			}
			break;
		case "Invoice_country":
			
			if(document.frm.Invoice_country.value != 'UK')
			{
				// by 'ZA_20030113 document.frm.CompanyhouseNo.disabled=true
				if (Invoice_countryflag==false)
				{	
					alert("Postcode only mandatory for UK Applications")
					Invoice_countryflag=true
				}	
				// by 'ZA_20030121 document.frm.com_postcode.style.background = "lightgrey" 
				
				strmand = ''
			}
			else
			{
				
				Invoice_countryflag=false
				// 'ZA document.frm.com_postcode.style.background = "#a4b3f0"
				// by 'ZA_20030113 document.frm.CompanyhouseNo.disabled=false
			}
			break;	
	}
}
/*function changeup(obj)
{

	var Warr;
	upstr = ""
	//switch(obj)
	//{
		//case "Last_name":
				Warr = document.all.item(obj).value.split(" ")
			  //Warr = document.frm.Last_name.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.all.item(obj).value = upstr
		/*	 break;
		case "First_Name":
			 Warr = document.frm.First_Name.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.First_Name.value = upstr
			break;
		case "home_Address1":
			 Warr = document.frm.home_Address1.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.home_Address1.value = upstr
			break;
		case "home_Address2":
			 Warr = document.frm.home_Address2.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.home_Address2.value = upstr
			break;
		case "home_Address3":
			 Warr = document.frm.home_Address3.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.home_Address3.value = upstr
			break;
		case "home_Address4":
			 Warr = document.frm.home_Address4.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.home_Address4.value = upstr
			break;
		case "home_Address5":
			 Warr = document.frm.home_Address5.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.home_Address5.value = upstr
			break;			
		case "CompanyName":
			 Warr = document.frm.CompanyName.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.CompanyName.value = upstr
			break;
		case "Company_Address1":
			 Warr = document.frm.Company_Address1.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.Company_Address1.value = upstr
			break;
		case "Company_Address2":
			 Warr = document.frm.Company_Address2.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.Company_Address2.value = upstr
			break;
		case "Company_Address3":
			 Warr = document.frm.Company_Address3.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.Company_Address3.value = upstr
			break;
		case "Company_Address4":
			 Warr = document.frm.Company_Address4.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.Company_Address4.value = upstr
			break;
		case "Company_Address5":
			 Warr = document.frm.Company_Address5.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.Company_Address5.value = upstr
			break;			
		case "CardHolder":
			 Warr = document.frm.CardHolder.value.split(" ")
			 for (wcount in Warr)
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 document.frm.CardHolder.value = upstr
			break;
			*/
//	}
/*}

function pcupper(object)
{
//alert(object)
	document.all.item(object).value =  document.all.item(object).value.toUpperCase()
	/*switch(object)
	{
		case "post_code":
			document.all.item(object).value =  document.all.item(object).value.toUpperCase()
			break;
		case "com_postcode":
			document.frm.com_postcode.value = document.frm.com_postcode.value.toUpperCase()
			break;
	}
}*/


//// functions below first character of every word in upper ////



/*Noman make the change*/
function changeup(obj)
{

	var Warr;
	upstr = ""

if (document.all) 
{
   element = document.all[obj];   
}
else 
{

   element = document.getElementById(obj);

}


			Warr = element.value.split(" ")
			 for (wcount in Warr)
				
				upstr = mstr(wcount,chupp(Warr[wcount]),upstr)
			 element.value = upstr


}

function pcupper(object)
{
if (document.all) 
{
   element = document.all[object];   
}
else 
{

element = document.getElementById(object);

}

element.value=element.value.toUpperCase();

	//document.all.item(object).value =  document.all.item(object).value.toUpperCase()
}


function chupp(wchange)
{

	return(wchange.charAt(0).toUpperCase() + wchange.substr(1))	
}
function mstr(count,chstr,strmade)
{
	if(count == 0)
	{
		str = strmade + chstr
	}
	else
	{
		str = strmade + " " + chstr
	}
	return(str)
}
/////////////////////////////End Function/////////////////////

///Function to Check length of address line not greater than 35//
function AddressLine(AddLine)
{
	if (AddLine.value.length > 35)
	{
		alert("Address line can't be more then 35 characters.");
		AddLine.focus();
		return(false);
	}
	return(true);
}

///End Function////

function FirstToUpper(obj)
{
	var Warr;
	upstr = ""
	Warr = obj.value.split(" ")
	for (wcount in Warr)
		upstr = MakeStr(wcount,CharUp(Warr[wcount]),upstr)
	obj.value = upstr
}

function CharUp(wchange)
{
	return(wchange.charAt(0).toUpperCase() + wchange.substr(1))	
}

function MakeStr(count,sChanged,sConcatenated)
{
	if(count == 0)
		sReturn = sConcatenated + sChanged
	else
		sReturn = sConcatenated + " " + sChanged
	return(sReturn)
}



////////////////// end of change first character of every word of String ////////////////////

///////////////////// change string to upper case ///////////////////////

function ChangeToUpper(object)
{
	object.value = object.value.toUpperCase()
}

function changelow(obj)
{
	if (document.all.item(obj).value!= "" )
	document.all.item(obj).value = document.all.item(obj).value.toLowerCase()
}
/////////////// end of change string to upper case /////////////////////


//////////////// function for checking the valid fax numbers ///////////


function validFax(object,oCaption)
{
	if (object.value.length > 0)
	{
		var checkOK = "0123456789- \t\r\n\f";
		var checkStr = object.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
		var k = 0;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			{
				if (ch!=" ")
					k++; 
				break;
			}
	       
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
			allNum += ch;
		}
		if (!allValid)
		{
			alert("Please enter valid " + oCaption + " number.");
			object.focus();
			return (false);
		}
		if (k < 4)
		{
			alert("Please enter valid " + oCaption + " number.");
			object.focus();
			return (false);
		}
	}
	return(true);
}

///////////////// end of function checking valid fax numbers ////////////

//////////////// function checking valid email address /////////////////
function validEmail(oName, oCaption)
//function emailCheck (emailStr) 
{
emailStr = oName.value
//alert(emailStr)
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
     alert("Please enter valid " + oCaption + " address.")
     oName.focus();
	//alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("Please enter valid " + oCaption + " address.")
    oName.focus();
    //alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
			alert("Please enter valid " + oCaption + " address.")
			oName.focus();
	        //alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Please enter valid " + oCaption + " address.")
	oName.focus();
	//alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("Please enter valid " + oCaption + " address.")
   oName.focus();
   //alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert("Please enter valid " + oCaption + " address.")
   oName.focus();
   //alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
/*
function validEmail(oName, oCaption)
{
	var str=oName.value;
	var len=str.length
	var j=0
	var k=0
	pos=0
	flagDot=false
	if (len>0)
	{
		for(i = 0;i < len;++i)
	    {
			if(str.charAt(i) =="@") 
			{ 
				posat=i
	            j++;
	        }
	        if(str.charAt(i) ==".") 
	        {
				if (i-pos==1)
				{
					flagDot=true;
					break;
				}
				pos=i;
				k++;
			}
	             
		}
		if (j!=1 || posat==1 || posat==len)
	    {
			alert("Please enter valid " + oCaption + " address")
			oName.focus();
			return(false);
	    }
	    if (k==0 || pos==len || pos==1 || pos <= posat+1)
	    {
			//alert(k)
			alert("Please enter valid " + oCaption + " address")
			oName.focus();
			return(false);
		}
	    if (flagDot==true)
		{
			alert("Please enter valid " + oCaption + " address")
			oName.focus();
			return(false);
	     }
	}    
	return(true);
}

*/

//////////////// end of function chekcing valid email /////////////////

/////////////////// function checking valid Names ////////////////////

function validName(oName, oCaption)
{
	var str = oName.value;
	//function isBlank(str) {
	var len=str.length
	var i
	var j=0
	for(i = 0;i < len;++i)
    {
		if((str.charAt(i) !=" ") && (str.charAt(i) !="-") && (str.charAt(i) !="'") )
			j++;
	}
	if (j>=2)
    {
        //return(true);
    }
    else
	{
		alert("Please enter valid " + oCaption)
        oName.focus();
        return(false);
	}
        
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ'-.& \t\r\n\f";
	var checkStr = oName.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		  if (ch == checkOK.charAt(j))
		    break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}
	}
	if (!allValid)
	{
		alert("Please enter valid " + oCaption);
		oName.focus();
		return (false);
	}
	return(true)

}


/////////////////// end of function checking valid names //////////////

///////////// function checking post code entry ///////////

function checkPcode(oName, oCaption, sCountry)
{
	
	if ((oName.value.length) < 1 && (sCountry == 'UK'))
	{
		alert("Please enter " + oCaption);
		oName.focus();
		return (false);
	}
	return(true);
}

///////// end of function checking post code entry //////////

////////////// function checking general mandatory entries ///////////


function CheckEntry(str1, str2, oCaption, oName)
{
	if(str2 != "")
	{
		if ((str1.length < 1) && (str2.length > 0))
			{
				alert("Please enter " + oCaption);
				oName.focus();
				return (false);
			}
	}
	else
	{
		if(str1.length < 1)
		{
			alert("Please enter " + oCaption);
			oName.focus();
			return(false);
		}
	}
	return(true);
}


///////////// end of fucntion ///////////////

////////// function checking setting with Country selection //////////

var countryflag=false

function b4PCheck(oName)
{
	countryflag = oName.value
}
function countrySet(oName1, oName2, oName3)
{
	if(countryflag == 'UK' && oName1.value != 'UK')
	{
		alert("Postcode only mandatory for UK Applications")
		// by 'ZA_20030121 oName2.style.background = "#FFFFFF"
		if(oName3)
		{
			oName3.disabled = true;
		}
	}
	else
	{
		if(oName1.value == 'UK')
		{
		//by 'ZA	oName2.style.background  = "lightgrey"
			if(oName3)
			{	
				oName3.disabled=false
			}
		}
	}
	countryflag = oName1.value

}

/////////////// end of functions of Country Selection ////////////////
///////////// functions for the  credit card verification ///////////



var strmand = '*'
var Cards = new makeArray(5);
Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16");
var MasterCard = Cards[0];
Cards[1] = new CardType("VisaCard", "4", "13,16");
var VisaCard = Cards[1];
Cards[2] = new CardType("SwitchCard", "4903,4905,4911,4936,564182,633110,6333,6759", "16,18,19");
var SwitchCard = Cards[5];
var LuhnCheckSum = Cards[6] = new CardType();

/*************************************************************************\
Object CardType([String cardtype, String rules, String len, int year, 
                                        int month])
cardtype    : type of card, eg: MasterCard, Visa, etc.
rules       : rules of the cardnumber, eg: "4", "6011", "34,37".
len         : valid length of cardnumber, eg: "16,19", "13,16".
year        : year of expiry date.
month       : month of expiry date.
eg:
var VisaCard = new CardType("Visa", "4", "16");
var AmExCard = new CardType("AmEx", "34,37", "15");
\*************************************************************************/
function CardType() {
var n;
var argv = CardType.arguments;
var argc = CardType.arguments.length;

this.objname = "object CardType";

var tmpcardtype = (argc > 0) ? argv[0] : "CardObject";
var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9";
var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19";

this.setCardNumber = setCardNumber;  // set CardNumber method.
this.setCardType = setCardType;  // setCardType method.
this.setLen = setLen;  // setLen method.
this.setRules = setRules;  // setRules method.
this.setExpiryDate = setExpiryDate;  // setExpiryDate method.

this.setCardType(tmpcardtype);
this.setLen(tmplen);
this.setRules(tmprules);
if (argc > 4)
this.setExpiryDate(argv[3], argv[4]);

this.checkCardNumber = checkCardNumber;  // checkCardNumber method.
this.getExpiryDate = getExpiryDate;  // getExpiryDate method.
this.getCardType = getCardType;  // getCardType method.
this.isCardNumber = isCardNumber;  // isCardNumber method.
this.isExpiryDate = isExpiryDate;  // isExpiryDate method.
this.luhnCheck = luhnCheck;// luhnCheck method.
return this;
}

/*************************************************************************\
CardType setCardNumber(cardnumber)
return the CardType object.
\*************************************************************************/
function setCardNumber(cardnumber) {
this.cardnumber = cardnumber;
return this;
}

/*************************************************************************\
CardType setCardType(cardtype)
return the CardType object.
\*************************************************************************/
function setCardType(cardtype) {
this.cardtype = cardtype;
return this;
}

/*************************************************************************\
CardType setLen(len)
return the CardType object.
\*************************************************************************/
function setLen(len) {
// Create the len array.
if (len.length == 0 || len == null)
len = "13,14,15,16,19";

var tmplen = len;
n = 1;
while (tmplen.indexOf(",") != -1) {
tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);
n++;
}
this.len = new makeArray(n);
n = 0;
while (len.indexOf(",") != -1) {
var tmpstr = len.substring(0, len.indexOf(","));
this.len[n] = tmpstr;
len = len.substring(len.indexOf(",") + 1, len.length);
n++;
}
this.len[n] = len;
//alert("i am here in setlen function "+ this.len[n])
return this;
}

/*************************************************************************\
CardType setRules()
return the CardType object.
\*************************************************************************/
function setRules(rules) {
// Create the rules array.
if (rules.length == 0 || rules == null)
rules = "0,1,2,3,4,5,6,7,8,9";
  
var tmprules = rules;
n = 1;
while (tmprules.indexOf(",") != -1) {
tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);
n++;
}
this.rules = new makeArray(n);
n = 0;
while (rules.indexOf(",") != -1) {
var tmpstr = rules.substring(0, rules.indexOf(","));
this.rules[n] = tmpstr;
rules = rules.substring(rules.indexOf(",") + 1, rules.length);
n++;
}
this.rules[n] = rules;
return this;
}

/*************************************************************************\
CardType setExpiryDate(year, month)
return the CardType object.
\*************************************************************************/
function setExpiryDate(year, month) {
this.year = year;
this.month = month;
return this;
}

/*************************************************************************\
CheckCardNumber(form)
function called when users click the "check" button.
\*************************************************************************/
function CheckCardNumber(form) {
var str;
//var datearr = new Array();
str = document.frm.ExpiryMonth.value +"/"+ document.frm.ExpiryYear.value
//alert(str);
datearr = str.split("/");
//alert(datearr[2])
var tmpyear;
if (form.CardNumber.value.length == 0) {
alert("Please enter a Card Number.");
form.CardNumber.focus();
return false;
}
if (form.CardHolder.value.length == 0) {
alert("Please enter name as on card.");
form.CardHolder.focus();
return false;
}

//if (document.frm.CreditCard(2).checked && document.frm.SIN.value.length==0) 
//{
//	alert("Please enter switch issue number.")
//	document.frm.SIN.focus();
//	return false;
//}

if (datearr[1] > 96)
tmpyear = "19" + datearr[1];
else if (datearr[1] < 21)
tmpyear = "20" + datearr[1];
else {
alert("The expiry date is not valid.");
return false;
}
tmpyear=document.frm.ExpiryYear.value
tmpmonth = document.frm.ExpiryMonth.value
if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) {
alert("Credit card has already expired.");
return false;
}

//alert(tmpmonth)
// The following line doesn't work in IE3, you need to change it
// to something like "(new CardType())...".
// if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {

var ccheck
	a = document.all.item("CreditCard");
	for (i=0;i<=a.length-1;i++)
		{
			if (document.frm.CreditCard(i).checked)
			{
				card = form.CreditCard(i).value;
				if (document.frm.CreditCard(3).checked) 
				return(true);
				ccheck = true
			}
		}
	
	if(!ccheck)
	{
		alert("Please select any of the given cards type")
		return false;
	}
//alert(document.frm.CardNumber.value)
//card = form.CreditCard.value;
//alert(tmpmonth)
//alert(tmpmonth * 2)
//alert(card + ".checkCardNumber(\"" + form.CardNumber.value +"\", " + tmpyear + ", " + tmpmonth + ");")

var retval = eval(card + ".checkCardNumber(\"" + form.CardNumber.value +
"\", " + tmpyear + ", " + tmpmonth + ");");
cardname = "";
//alert(retval)
if (retval)

{

// comment this out if used on an order form
//alert("This card number appears to be valid.");
return(true)
}
else {
// The cardnumber has the valid luhn checksum, but we want to know which
// cardtype it belongs to.
for (var n = 0; n < Cards.size; n++) {
if (Cards[n].checkCardNumber(form.CardNumber.value, tmpyear, tmpmonth)) {
cardname = Cards[n].getCardType();
break;
   }
}
if (cardname.length > 0) {
alert("This looks like a " + cardname + " number, not a " + card + " number.");
}
else {
alert("Credit card number is not valid.");
return false;
      }
   }
}

/*************************************************************************\
boolean checkCardNumber([String cardnumber, int year, int month])
return true if cardnumber pass the luhncheck and the expiry date is
valid, else return false.
\*************************************************************************/
function checkCardNumber() {
var argv = checkCardNumber.arguments;
var argc = checkCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
var year = (argc > 1) ? argv[1] : this.year;
var month = (argc > 2) ? argv[2] : this.month;
//month = 03

//alert(month)

this.setCardNumber(cardnumber);
this.setExpiryDate(year, month);

if (!this.isCardNumber())
{
//	alert("this is false!!!")
	return false;
}
if (!this.isExpiryDate())
{
//	alert("this is just the test!!!!")
	return false;
}

return true;
}

/*************************************************************************\
String getExpiryDate()
return the expiry date.
\*************************************************************************/
function getExpiryDate() {
return this.month + "/" + this.year;
}

/*************************************************************************\
String getCardType()
return the cardtype.
\*************************************************************************/
function getCardType() {
return this.cardtype;
}
/*************************************************************************\
boolean isCardNumber([String cardnumber])
return true if cardnumber pass the luhncheck and the rules, else return
false.
\*************************************************************************/
function isCardNumber() {
var argv = isCardNumber.arguments;
var argc = isCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
	
if (!this.luhnCheck())
{
	return false;
}
//alert("i am here in "+this.len.size)
for (var n = 0; n < this.len.size; n++)
if (cardnumber.toString().length == this.len[n]) {
for (var m = 0; m < this.rules.size; m++) {
var headdigit = cardnumber.substring(0, this.rules[m].toString().length);
if (headdigit == this.rules[m])
{
//	alert("i am here in this rulessss")
	return true;
}
}
//	alert("i am here in this rules false")
return false;
}
//	alert("i am here in this rules false false")
return false;
}

/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate() {
var argv = isExpiryDate.arguments;
var argc = isExpiryDate.arguments.length;

year = argc > 0 ? argv[0] : this.year;
month = argc > 1 ? argv[1] : this.month;


if (!isNum(year+""))
return false;
if (!isNum(month+""))
return false;

today = new Date();
expiry = new Date(year, month);
if (today.getTime() > expiry.getTime())
return false;
else
return true;
}

/*************************************************************************\
boolean luhnCheck([String CardNumber])
return true if CardNumber pass the luhn check else return false.
Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
\*************************************************************************/
function luhnCheck() {
var argv = luhnCheck.arguments;
var argc = luhnCheck.arguments.length;

var CardNumber = argc > 0 ? argv[0] : this.cardnumber;

if (! isNum(CardNumber)) {
return false;
  }

var no_digit = CardNumber.length;
var oddoeven = no_digit & 1;
var sum = 0;

for (var count = 0; count < no_digit; count++) {
var digit = parseInt(CardNumber.charAt(count));
if (!((count & 1) ^ oddoeven)) {
digit *= 2;
if (digit > 9)
digit -= 9;
}
sum += digit;
}
if (sum % 10 == 0)
return true;
else
return false;
}
/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
return false;

return true;
}

/*************************************************************************\
ArrayObject makeArray(int size)
return the array object in the size specified.
\*************************************************************************/
function makeArray(size) {
this.size = size;
return this;
}





/////////////////// end of credit card functions ////////////////////

////////////////////// function use for AFD ////////////////////////

/*
function FindAddress(oCountry, oPcode, oHouse, oCaption)
{
	if (oPcode.value != "" && oCountry.value == "UK")
	{		
		path="FindAddress.asp?Pcode=" + oPcode.value + "&HouseID=" + oHouse.value
		window.open(path,"FindAddress","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width=400,height=400")
		window.name="postcode"	
	}
	else
	{
		if (oCountry.value != "UK")
			alert("Only for UK address.")
		else
		{
			alert("Please enter " + oCaption)
			oPcode.focus()
		}
	}
}
*/
//////////////////////// end of function ///////////////////////////

//////////////////////// General functions /////////////////////////

function isBetween (val, lo, hi) {
	if ((val < lo) || (val > hi)) { return(false); }
	else { return(true); }
}


function isEmpty (str) {
	if ((str==null)||(str.length==0)) return true;
	else return(false);

}

function validnull(item3)
      {
         if (item3.length==0)
          {
            return false;
          }
         return true;
     }


function isInt (item) {
	var flag = true;

	if (isEmpty(item)) { flag=false; }
	else
	{	for (var i=0; i< item.length; i++) {
			if (isDigit(item.substring(i,i+1)) == false) {
				flag = false; break;
			}
		}
	}
	return(flag);
}

function isDigit(theNum) {
	var theMask = '0123456789';
	
	if (isEmpty(theNum)) return(false);
	else if (theMask.indexOf(theNum) == -1) return(false);
	
	return(true);
}


function CheckDay()
{
	
	var  item=document.frm.day.value;

	if ((document.frm.day.value=="None") || (document.frm.month.value=="None") || (document.frm.year.value=="None"))
	{
		
		
		if ((document.frm.day.value=="None") && (document.frm.month.value=="None") && (document.frm.year.value=="None"))
		{
		//	alert("All valid");
			//return(true);
		}
		else
		{
			alert("Please enter valid date of birth")	
			document.frm.day.focus();
			return(false);
		}

	}
	
	else
	{
		if (!isDate(item)) 
		{
			alert("Please enter valid date of birth")
			document.frm.day.focus();
			return(false);
		}
	}


}

function isDate (item) 
{
	var maxDays
	var now=new Date()
	var year=now.getYear()
			
	m=document.frm.month.value
	y=document.frm.year.value
			
	if (!validnull(item)) {return true;}
	
	if (isInt(y)==false) { return(false); }
	
	else 
		if (y.length < 4 || y.length > 4 || y > year ) { return(false); }
	
		else 
			
			if (m=="April" || m=="June" || m=="September" || m=="November") maxDays = 30;
		
			else 
			
				if (m=="February") 
				
				{	if (y % 4 > 0) maxDays = 28;
				
					else 
				
						if (y % 100 == 0 && y % 400 > 0) maxDays = 28;           	
         			else
           			maxDays = 29;
				}
			
			if (isBetween(item, 1, maxDays) == false) {  return(false); }
			else { return(true); 
		}
}


//Date Funtion Start
// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/"; 
// If you are using any Java validation on the back side you will want to use the / because 
// Java date validations do not recognize the dash as a valid date separator.
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
if(navigator.appName == "Netscape") {
if (navigator.appVersion < "5") {
isNav4 = true;
isNav5 = false;
}
else
if (navigator.appVersion > "4") {
isNav4 = false;
isNav5 = true;
   }
}
else {
isIE4 = true;
}
function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
vDateType = dateType;
// vDateName = object name
// vDateValue = value in the field being checked
// e = event
// dateCheck 
// True  = Verify that the vDateValue is a valid date
// False = Format values being entered into vDateValue only
// vDateType
// 1 = mm/dd/yyyy
// 2 = yyyy/mm/dd
// 3 = dd/mm/yyyy
//Enter a tilde sign for the first number and you can check the variable information.
if (vDateValue == "~") {
alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
vDateName.value = "";
vDateName.focus();
return true;
}

var whichCode = (window.Event) ? e.which : e.keyCode;

// Check to see if a seperator is already present.
// bypass the date if a seperator is present and the length greater than 8
if (vDateValue.length > 8 && isNav4) {
if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
return true;
}
//Eliminate all the ASCII codes that are not valid
var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
if (alphaCheck.indexOf(vDateValue) >= 1) {
if (isNav4) {
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
else {
vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
return false;
   }
}
if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
return false;
else {
//Create numeric string values for 0123456789/
//The codes provided include both keyboard and keypad values
var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
if (strCheck.indexOf(whichCode) != -1) {
if (isNav4) {
if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
if (vDateValue.length == 6 && dateCheck) {
var mDay = vDateName.value.substr(2,2);
var mMonth = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
//Turn a two digit year into a 4 digit year
if (mYear.length == 2 && vYearType == 4) {
var mToday = new Date();
//If the year is greater than 30 years from now use 19, otherwise use 20
var checkYear = mToday.getFullYear() + 30; 
var mCheckYear = '20' + mYear;
if (mCheckYear >= checkYear)
mYear = '19' + mYear;
else
mYear = '20' + mYear;
}
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (!dateValid(vDateValueCheck)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
return true;
}
else {
// Reformat the date for validation and set date type to a 1
if (vDateValue.length >= 8  && dateCheck) {
if (vDateType == 1) // mmddyyyy
{
var mDay = vDateName.value.substr(2,2);
var mMonth = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
}
if (vDateType == 2) // yyyymmdd
{
var mYear = vDateName.value.substr(0,4)
var mMonth = vDateName.value.substr(4,2);
var mDay = vDateName.value.substr(6,2);
vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
}
if (vDateType == 3) // ddmmyyyy
{
var mMonth = vDateName.value.substr(2,2);
var mDay = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
}
//Create a temporary variable for storing the DateType and change
//the DateType to a 1 for validation.
var vDateTypeTemp = vDateType;
vDateType = 1;
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (!dateValid(vDateValueCheck)) {
alert("Invalid Date\nPlease Re-Enter");
vDateType = vDateTypeTemp;
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
vDateType = vDateTypeTemp;
return true;
}
else {
if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
         }
      }
   }
}
else {
// Non isNav Check
if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
return true;
}
// Reformat date to format that can be validated. mm/dd/yyyy
if (vDateValue.length >= 8 && dateCheck) {
// Additional date formats can be entered here and parsed out to
// a valid date format that the validation routine will recognize.
if (vDateType == 1) // mm/dd/yyyy
{
var mMonth = vDateName.value.substr(0,2);
var mDay = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vDateType == 2) // yyyy/mm/dd
{
var mYear = vDateName.value.substr(0,4)
var mMonth = vDateName.value.substr(5,2);
var mDay = vDateName.value.substr(8,2);
}
if (vDateType == 3) // dd/mm/yyyy
{
var mDay = vDateName.value.substr(0,2);
var mMonth = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vYearLength == 4) {
if (mYear.length < 4) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
return true;
   }
}
// Create temp. variable for storing the current vDateType
var vDateTypeTemp = vDateType;
// Change vDateType to a 1 for standard date format for validation
// Type will be changed back when validation is completed.
vDateType = 1;
// Store reformatted date to new variable for validation.
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (mYear.length == 2 && vYearType == 4 && dateCheck) {
//Turn a two digit year into a 4 digit year
var mToday = new Date();
//If the year is greater than 30 years from now use 19, otherwise use 20
var checkYear = mToday.getFullYear() + 30; 
var mCheckYear = '20' + mYear;
if (mCheckYear >= checkYear)
mYear = '19' + mYear;
else
mYear = '20' + mYear;
vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
// Store the new value back to the field.  This function will
// not work with date type of 2 since the year is entered first.
if (vDateTypeTemp == 1) // mm/dd/yyyy
vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
if (vDateTypeTemp == 3) // dd/mm/yyyy
vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
} 
if (!dateValid(vDateValueCheck)) {
alert("Invalid Date\nPlease Re-Enter");
vDateType = vDateTypeTemp;
vDateName.value = "";
vDateName.focus();
return true;
}
vDateType = vDateTypeTemp;
return true;
}
else {
if (vDateType == 1) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
if (vDateType == 2) {
if (vDateValue.length == 4) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 7) {
vDateName.value = vDateValue+strSeperator;
   }
} 
if (vDateType == 3) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
return true;
   }
}
if (vDateValue.length == 10&& dateCheck) {
if (!dateValid(vDateName)) {
// Un-comment the next line of code for debugging the dateValid() function error messages
//alert(err);  
alert("Invalid Date\nPlease Re-Enter");
vDateName.focus();
vDateName.select();
   }
}
return false;
}
else {
// If the value is not in the string return the string minus the last
// key entered.
if (isNav4) {
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
else
{
vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
return false;
         }
      }
   }
}
function dateValid(objName) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
// var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
//strDate = datefield.value;
strDate = objName;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
//Adjustment for short years entered
if (strYear.length == 2) {
strYear = '20' + strYear;
}
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
   }
}
else {
if (intday > 28) {
err = 10;
return false;
      }
   }
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}
//End Date Function


function OnDetailChange(NewValue)
{
//	alert(document.frm.ExHomePostCode)	
	//if (NewValue!='' || NewValue=='UK')
	//{
	//	document.frm.submit.disabled=false;
	//	document.frm.reset.disabled=false;
	//	return(false)
	//}
	if (document.frm.ExHomePostCode)
	{
	if (document.frm.postcode.value==document.frm.ExHomePostCode.value && document.frm.HomeAddress1.value==document.frm.ExHomeAddress1.value && document.frm.HomeAddress2.value==document.frm.ExHomeAddress2.value && document.frm.HomeAddress3.value==document.frm.ExHomeAddress3.value && document.frm.HomeAddress4.value==document.frm.ExHomeAddress4.value && document.frm.country.value=='UK' && document.frm.HomeTel.value==document.frm.ExHomeTel.value && document.frm.HomeEmail.value==document.frm.ExHomeEmail.value && document.frm.ReHomeEmail.value==document.frm.ExHomeEmail.value )
	{
		//document.frm.submit.disabled=true;
		//document.frm.reset.disabled=true;
		//return(false)
	//	document.frm.submit.disabled=false;
	//	document.frm.reset.disabled=false;
		return(false)
	}
	else
	{	
	//	document.frm.submit.disabled=false;
	//	document.frm.reset.disabled=false;
		return(false)
	}
	}
}

function OnDetailChangeBranch(NewValue)
{
	
	if (document.frm.hBranch1.value==document.frm.Branch1.value && document.frm.Branch2.value==document.frm.hBranch2.value)
	{
	//	document.frm.submit.disabled=true;
	//	document.frm.reset.disabled=true;
		return(false)
	}
	else
	{
	//	document.frm.submit.disabled=false;
	//	document.frm.reset.disabled=false;
		return(false)
	}
	
	
}

function OnDetailChangeCompany(NewValue)
{

	if (NewValue.value!='' || NewValue.value=='UK')
	{
	//	document.frm.submit.disabled=false;
	//	document.frm.reset.disabled=false;
		return(false)
	}
	
	if (document.frm.postcode.value=='' && document.frm.Address1.value=='' && document.frm.Address2.value=='' && document.frm.Address3.value=='' && document.frm.Address4.value=='' && document.frm.country.value=='UK' && document.frm.Tel.value=='' && document.frm.Fax.value=='' && document.frm.Email.value=='' && document.frm.ReEmail.value=='' )
	{
		//document.frm.submit.disabled=true;
	//	document.frm.reset.disabled=true;
		return(false)
	}
	
}


function OnPreferChange()
{
	document.frm.submit.disabled=false;
	document.frm.reset.disabled=false;
	return(false)
}

function OnExDetailChange(NewValue,OldValue)
{

	
	if (NewValue.value!=OldValue.value)
	{
		document.frm.submit.disabled=false;
		document.frm.reset.disabled=false;
	}
	
	
	
}

function OnDisChange()
{
	document.frm.submit.disabled=true;
	document.frm.reset.disabled=true;

}

function SelectComp()

{
	var a = document.all.item("CompanyId");
	var flag
	flag = false
	
	for (i=0;i<=a.length-1;i++)
		{
			
			if (document.frm.CompanyId(i).checked)
				flag=true
				
				
		}
		
		
		if (flag==false)
			{ 
				alert("Please select company")
				return(false);
			}
		
}

function SelectCourse()
{
	var a = document.all.item("course");
	var flag
	flag = false
	
	if (a.checked)
	{
			flag=true
	}
	
for (i=0;i<=a.length-1;i++)
		{
			
			if (document.frm.course(i).checked)
				flag=true
				
				
		}
		
		
		if (flag==false)
			{ 
				alert("Please select course(s)")
				return(false);
			}
		
}
function RedirectUrl(url)
{
	document.frm.action=url;
	document.frm.submit();
}


function pop()
{
	//alert(url)
	window.open('companylist.asp','SelectCompany',"fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width=480,height=480")	
}
function popup(url,Del,name,madd)
{


	if (Del=='')
	{
		alert('Please mention delegate(s).')
		
	}
	else
	{
		url = url + "?MemDel=" + Del + "&" + "Address=" + madd

		window.open(url,name,"fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width=480,height=480")	
	}	

}
function fclose()
{
	window.opener.location.reload();
	window.close();
}

function EmailConfirm(Email,ReEmail)
{
	if (Email.value != ReEmail.value)
	{
		alert("Re-Type Email do not match.")
		ReEmail.focus();
		return(false)
	}
	else
	{
		return(true)
	}
}

function PassConfirm(Pass,RePass)
{
	if (Pass.value != RePass.value)
	{
		alert("Re-Type Password do not match.")
		RePass.focus();
		return(false)
	}
	else
	{
		return(true)
	}
}


function SelectAll()
{

	if (document.frm.chkbox.value == undefined)
	{
		
		var a = document.all.item("chkbox");
		
			if (a!=null)
				{
				//	alert(document.frm.chkbox.value);
					if (document.frm.chkboxAll.checked)
					{	
						for (i=0;i<=a.length-1;i++)
							{ 
								document.frm.chkbox(i).checked=true
								document.frm.payment.disabled = false
							}
		
					}
					else
					{
						for (i=0;i<=a.length-1;i++)
						{ 
							document.frm.chkbox(i).checked = false
							document.frm.payment.disabled = true
						}
		
					
					}
				}
				var TotalAmount
				var RateId
				var RateCode
					RateId = 0
					TotalAmount =0
					Amount=0
					if (a!=null)
					{
					
					for (i=0;i<=a.length-1;i++)
						{ 
							if (document.frm.chkbox(i).checked)
							{
								str = document.frm.chkbox(i).value
								
								pos = str.indexOf('@')
								Amount = str.substr(pos + 1,str.length)
							//	alert(TotalAmount * 1)
							Amount=Amount.replace(',','')
							//	alert(Amount)
								TotalAmount = (TotalAmount * 1) + (Amount * 1)
								
								
								RateCode = str.substr(0,pos)
								if (RateId=="0")
								{
									RateId = RateCode + "@" + Amount
								}
								else
								{	
								RateId = RateId + "," + RateCode + "@" + Amount
								}
							}
						}
						
						
					}
				//	alert(TotalAmount *1)
					
					//document.frm.amount.value =  formatCurrency(TotalAmount) *1
					document.frm.amount.value =  TotalAmount * 100
					document.frm.rate.value = RateId
					//alert(formatCurrency(TotalAmount) *1)			
		}
		else
		{
			
			if (document.frm.chkboxAll.checked)	
			{
				document.frm.payment.disabled = false
				document.frm.chkbox.checked=true
				str = document.frm.chkbox.value
				pos = str.indexOf('@')
				Amount = str.substr(pos + 1,str.length)
				TotalAmount = Amount * 1
				RateCode = str.substr(0,pos)
				RateId = RateCode + "@" + Amount
				document.frm.amount.value = formatCurrency(TotalAmount) *1
				document.frm.rate.value = RateId
			}
			else
			{
				document.frm.chkbox.checked=false
				document.frm.payment.disabled = true
			}	
			
		}	
	
}



function UnSelectAll()
{
	
	if (document.frm.chkbox.value == undefined)
	{
	var a = document.all.item("chkbox");
	if (a!=null)
		{
			if (document.frm.chkboxAll.checked)
			{	
				for (i=0;i<=a.length-1;i++)
				{ 
					if (!document.frm.chkbox(i).checked)
					{
						document.frm.chkboxAll.checked=false
						
					}
					
				}
				
			}
			else
			{
				inflag = false
				for (i=0;i<=a.length-1;i++)
					{ 
						if (document.frm.chkbox(i).checked)
						{
							document.frm.payment.disabled = false
							inflag=true
						}
					}
					
				if (inflag==false)
				document.frm.payment.disabled = true
					
			}	
		}


		var TotalAmount
		var RateId
		var RateCode
			RateId = 0
			TotalAmount =0
			if (a!=null)
			{
			for (i=0;i<=a.length-1;i++)
				{ 
					if (document.frm.chkbox(i).checked)
					{
						str = document.frm.chkbox(i).value
						pos = str.indexOf('@')
						Amount = str.substr(pos + 1,str.length)
						Amount=Amount.replace(',','')
					//	alert(Amount)

						TotalAmount = (TotalAmount * 1) + (Amount * 1)
						
						//alert(TotalAmount)
						RateCode = str.substr(0,pos)
						if (RateId=="0")
						{
							RateId = RateCode + "@" + Amount
						}
						else
						{	
						RateId = RateId + "," + RateCode + "@" + Amount
						}
										
					}
						
				}
			}	
			
				
			//document.frm.amount.value = formatCurrency(TotalAmount) * 1
			document.frm.amount.value = TotalAmount * 100
			document.frm.rate.value = RateId
			
			
	}
	else
	{
		
		if (document.frm.chkboxAll.checked)
		{
			if (!document.frm.chkbox.checked)
			{
				document.frm.chkboxAll.checked=false
				document.frm.payment.disabled = true
			}
		}
		if (document.frm.chkbox.checked)
			{
				document.frm.chkboxAll.checked=true
				document.frm.payment.disabled = false
				str = document.frm.chkbox.value
				pos = str.indexOf('@')
				Amount = str.substr(pos + 1,str.length)
				TotalAmount = Amount * 1
				RateCode = str.substr(0,pos)
				RateId = RateCode + "@" + Amount
				document.frm.amount.value = formatCurrency(TotalAmount) *1
				document.frm.rate.value = RateId
			}
				
	}
	

}

function SelectAllAttrib()
{

var a = document.all.item("chkbox");

	if (a!=null)
	{
		if (document.frm.chkboxAll.checked)
		{	
			for (i=0;i<=a.length-1;i++)
				{ 
					document.frm.chkbox(i).checked=true
				}
		}

		else
		{
			for (i=0;i<=a.length-1;i++)
			{ 
				document.frm.chkbox(i).checked=false
			}
		}
	}


}

function UnSelectAllAttrib()
{
var a = document.all.item("chkbox");
if (a!=null)
{
	if (document.frm.chkboxAll.checked)
	{	
		for (i=0;i<=a.length-1;i++)
		{ 
			if (!document.frm.chkbox(i).checked)
				document.frm.chkboxAll.checked=false
		}
	}
}

}


function Validate()
{
var a = document.all.item("chkbox");
flag = false
if (a!=null)
{
	
		for (i=0;i<=a.length-1;i++)
		{ 
			if (document.frm.chkbox(i).checked)
				flag = true	
		}
	
}
else
{
	if (document.frm.chkbox.checked)
	flag = true
}

if (document.frm.chkbox.checked)
	flag = true
	
if (flag == false)
{
	alert("Please check atleast one rate id.")
	return(false)
}

}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + cents);
}

/////////////////////// end of general functions ///////////////////
//////////////////////////////////////////////////////////////////////