﻿//all forms
arrUniUkBank = new Array()
arrUniUkBank ['2'] = true
arrUniUkBank ['26'] = true
arrUniUkBank ['11'] = true
arrUniUkBank ['20'] = true
arrUniUkBank ['29'] = true
arrUniUkBank ['30'] = true
arrUniUkBank ['35'] = true
arrUniUkBank ['36'] = true

arrUniUkGetStart = new Array()
arrUniUkGetStart ['2'] = true
arrUniUkGetStart ['21'] = true
arrUniUkGetStart ['11'] = true
arrUniUkGetStart ['26'] = true
arrUniUkGetStart ['29'] = true
arrUniUkGetStart ['30'] = true
arrUniUkGetStart ['35'] = true
arrUniUkGetStart ['36'] = true

arrUniUkGetFlat = new Array()
arrUniUkGetFlat ['25'] = true
arrUniUkGetFlat ['13'] = true
arrUniUkGetFlat ['14'] = true
arrUniUkGetFlat ['30'] = true
arrUniUkGetFlat ['35'] = true
arrUniUkGetFlat ['36'] = true


arrUniUkNIN = new Array()
arrUniUkNIN ['21'] = true
arrUniUkNIN ['26'] = true
arrUniUkNIN ['29'] = true
arrUniUkNIN ['30'] = true
arrUniUkNIN ['35'] = true
arrUniUkNIN ['36'] = true

arrUniUkBankAu = new Array ()
arrUniUkBankAu ['17'] = true
arrUniUkBankAu ['19'] = true
arrUniUkBankAu ['31'] = true
arrUniUkBankAu ['32'] = true
arrUniUkBankAu ['33'] = true
arrUniUkBankAu ['34'] = true


arrUniVisaF  = new Array ()
arrUniVisaF ['18'] = true
arrUniVisaF ['38'] = true
arrUniVisaF ['19'] = true
arrUniVisaF ['31'] = true
arrUniVisaF ['32'] = true
arrUniVisaF ['33'] = true
arrUniVisaF ['34'] = true

arrUniUKCmp   = new Array ()
arrUniUKCmp ['37'] = true
arrUniUKCmp ['17'] = true
arrUniUKCmp ['18'] = true
arrUniUKCmp ['19'] = true
arrUniUKCmp ['29'] = true
arrUniUKCmp ['30'] = true
arrUniUKCmp ['31'] = true
arrUniUKCmp ['32'] = true
arrUniUKCmp ['33'] = true
arrUniUKCmp ['34'] = true
arrUniUKCmp ['35'] = true
arrUniUKCmp ['36'] = true

arrUniUkComplPlus = new Array ()
arrUniUkComplPlus ['2'] = true
arrUniUkComplPlus ['11'] = true
arrUniUkComplPlus ['21'] = true
arrUniUkComplPlus ['26'] = true
arrUniUkComplPlus ['30'] = true
arrUniUkComplPlus ['35'] = true
arrUniUkComplPlus ['36'] = true

arrUniUkPlus = new Array ()
arrUniUkPlus ['2'] = true
arrUniUkPlus ['11'] = true
arrUniUkPlus ['21'] = true
arrUniUkPlus ['26'] = true
arrUniUkPlus ['29'] = true
arrUniUkPlus ['25'] = true
arrUniUkPlus ['30'] = true
arrUniUkPlus ['35'] = true
arrUniUkPlus ['36'] = true

arrIePackBank = new Array()
arrIePackBank ['31'] = true
arrIePackBank ['32'] = true
arrIePackBank ['33'] = true
arrIePackBank ['34'] = true
arrIePackBank ['17'] = true
arrIePackBank ['18'] = true
arrIePackBank ['19'] = true
arrIePackBank ['38'] = true
arrIePackBank ['37'] = true

arrUniBankGetStart = new Array()
arrUniBankGetStart ['26'] = true
arrUniBankGetStart ['101'] = true

arrUniCSCS = new Array()
arrUniCSCS['124'] = true
arrUniCSCS['126'] = true
arrUniCSCS['128'] = true
arrUniCSCS['129'] = true
arrUniCSCS['125'] = true
arrUniCSCS['127'] = true
var valEN, valENdep
valEN = 0;
valENdep = 0;
var valENuni;

function CalcDiscount (theInd, theExept) {
total = window.document.getElementsByName("total")[0]
payment = initPayment ()
	for ( gr in  packGroups) {	
		 if (packGroups [gr][theInd] !=null && groupsType[gr]==0) {		 	
		 	CheckGroup (gr, theInd,theExept)
		 }
		 else if (packGroups [gr][theInd] !=null && groupsType[gr]==1) {
			 CalcGroupAllRec(gr, theInd)
		 }
	}
	ReduceNIN(theInd);
}
CalcGroupAllRec
function CalcGroupAllRec (gr, theInd) {
var disc = 0;
var packTmp;
var objsel = 0;
var objgroup = 0;
total = window.document.getElementsByName("total")[0];
current = window.document.getElementsByName('packet'+theInd)[0];
	for (packIs in  packGroups[gr]) {
		//alert(packIs)
		 disc = disc + packGroups[gr][packIs];
		 packTmp=window.document.getElementsByName('packet'+packIs)[0];
		 if (packTmp!=null) {
			 objgroup = objgroup+1;
			 if (packTmp.checked) {
				 objsel = objsel +1;
			 }
		 }
	}
	//alert(packGroups[gr].length);
	if (objgroup==objsel) {
		total.value = formatFloat(parseFloat(total.value) - disc);
	}
	else if (objgroup==(objsel+1) && !current.checked) {
		total.value = formatFloat(parseFloat(total.value) + disc);
	}
}
function ReduceNIN (theInd) {
	
	ninInd = 21;
	ninPack = window.document.getElementsByName('packet21')[0];
	if (ninPack==null) {
		return;
	}
	//arrCSCSpack = new Array(120,121,122)
	
	arrCSCS = new Array();
	//window.document.getElementsByName('packet120')[0],window.document.getElementsByName('packet121')[0],window.document.getElementsByName('packet122')[0]
	countCheck = 0;
	flagCSCScurrent = false;
	for (packIs in  packGroups[8]) {
		if(packIs!=21) {
			if (packIs==theInd) {
				flagCSCScurrent = true;
			}
			packTmp=window.document.getElementsByName('packet'+packIs)[0];
			if (packTmp==null) {
				return;
			}
			if (packTmp.checked) {
				countCheck = countCheck+1;
				if (countCheck==1) {
					checkCS=packIs;	
				}
				else {
					//return;
				}
			}
		}
	}
	
	if (countCheck==0&&!ninPack.checked) {
		return;
	}
	
	//if (arrCSCS[0]==null || arrCSCS[1]==null) {
	//	return;
	//}
	total = window.document.getElementsByName("total")[0]
	current = window.document.getElementsByName('packet'+theInd)[0];
	//wrong??
	if (theInd!=21 && !current.checked) {
		uncheckCS=theInd;
	}
	
	
	
	//if (arrCSCS[0]) 
	{
		//	checkCS = 120
		//	uncheckCS = 121
		}
		//else 
		{
		//	checkCS = 120
		//	uncheckCS = 121
		}
	countGr = 0;
	
	if (theInd==21 && countCheck>=1) {
		
		//&& (arrCSCS[0].checked != arrCSCS[1].checked)	
		for (packIs in  packGroups[1]) {
			tmpFld = window.document.getElementsByName('packet' + packIs)[0]			
			if (tmpFld!=null && tmpFld.checked) {
				countGr = countGr+1;
			}
		}
		
		if (current.checked && countGr==2) {//&& (arrCSCS[0].checked != arrCSCS[1].checked) 
			total.value = formatFloat(parseFloat(total.value) + packGroups[1][checkCS]+packGroups[1][ninInd]);
		}
		else if(current.checked && countGr>2) {//&& (arrCSCS[0].checked != arrCSCS[1].checked) 
			total.value = formatFloat(parseFloat(total.value) + packGroups[1][theInd]);
		}
		else if (!current.checked  && countGr==1) {//&& (arrCSCS[0].checked != arrCSCS[1].checked)
			total.value = formatFloat(parseFloat(total.value) - packGroups[1][checkCS] - packGroups[1][ninInd]);
		}
		else if (!current.checked  && countGr>1) {//&& (arrCSCS[0].checked != arrCSCS[1].checked)
			total.value = formatFloat(parseFloat(total.value) - packGroups[1][theInd]);
		}
	}
	else if (flagCSCScurrent && (ninPack.checked) && ((countCheck==1 && current.checked) || (countCheck==0 && !current.checked))) {//(theInd==120 || theInd==121)
		
		for (packIs in  packGroups[1]) {
			tmpFld = window.document.getElementsByName('packet' + packIs)[0]			
			if (tmpFld!=null && tmpFld.checked) {
				countGr = countGr+1;
			}
		}
				
		if (current.checked  && countGr==2) {//&&  (arrCSCS[0].checked != arrCSCS[1].checked)
			total.value = formatFloat(parseFloat(total.value) + packGroups[1][checkCS]+packGroups[1][ninInd]);
		}
		else if (current.checked  && countGr>2 && countCheck==1) {//&&  (arrCSCS[0].checked != arrCSCS[1].checked)
			total.value = formatFloat(parseFloat(total.value) + packGroups[1][checkCS]);
		}
		else if (!current.checked  && countGr==1) {//&&  (arrCSCS[0].checked == arrCSCS[1].checked)
			total.value = formatFloat(parseFloat(total.value) - packGroups[1][uncheckCS] - packGroups[1][ninInd]);
		}
		else if (!current.checked  && countGr>1) {//&&  (arrCSCS[0].checked == arrCSCS[1].checked)
			total.value = formatFloat(parseFloat(total.value) -  packGroups[1][uncheckCS]);
		}
	}
	else if (((!flagCSCScurrent && theInd!=21 && countCheck==1) || (flagCSCScurrent && countCheck>0)) && ninPack.checked ) {//theInd!=120 && theInd!=121
		//&& (arrCSCS[0].checked != arrCSCS[1].checked)
		
		//&& countCheck==1
		
		if (ninPack.checked) {
			packDisc=21;
		}
		else {
			packDisc=checkCS;
		}
		//else if (arrCSCS[0].checked) {
		//	packDisc=120
		//}
		//else {
		//	packDisc=121
		//}
		for (packIs in  packGroups[1]) {
			tmpFld = window.document.getElementsByName('packet' + packIs)[0]			
			if (tmpFld!=null && tmpFld.checked) {
				countGr = countGr+1;
			}
		}
		if (current.checked && countGr==3) {
			total.value = formatFloat(parseFloat(total.value) -  packGroups[1][packDisc]);
		}
		else if(!current.checked && countGr==2){
			total.value = formatFloat(parseFloat(total.value) +  packGroups[1][packDisc]);
		}
	}
	//|| ((theInd==120 || theInd==121) && ninPack.checked)
}

function CheckGroup (gr, theInd,theExept) {
selFld = window.document.getElementsByName('packet' + theInd)[0]
flagAdd = 0
flagRem = 0
flagAddNum = 0
total = window.document.getElementsByName("total")[0]
owedPayment = window.document.getElementsByName(usrCncy)[0]

flagOwed = false
if (owedPayment!=null && payment ==-2) {flagOwed = true}

	for (pack in  packGroups[gr]) {	
		tmpFld = window.document.getElementsByName('packet' + pack)[0]		
		if (tmpFld!=null && pack!=theInd) {		
			if (tmpFld.checked && selFld.checked) {
				if(theExept!=pack) {
					if(flagRem==0) {
						flagRem = pack
						if (total!=null) {
							total.value = formatFloat(parseFloat(total.value) - packGroups[gr][theInd])	
						}
						if (flagOwed) {
							owedPayment.value = formatFloat(parseFloat(owedPayment.value) - packGroups[gr][theInd])
						}
					}
					else {
						flagRem = 0
						break;
					}
				}
			}
			else if (tmpFld.checked && selFld.checked==false)
			{				
				if(theExept!=pack) {
					flagAddNum = flagAddNum + 1
					flagAdd = pack
				}
								
			}
		}
		
	}
	
	if (flagRem>0 ) {
			total.value = formatFloat(parseFloat(total.value) - parseFloat(packGroups[gr][flagRem]))
			if (flagOwed) {
				owedPayment.value = formatFloat(parseFloat(owedPayment.value) - parseFloat(packGroups[gr][flagRem]))
			}
	}
	else if (flagAdd!=0) {
		
		if (flagAddNum==1) {			
			if (total!=null) {total.value = formatFloat(parseFloat(total.value) + parseFloat(packGroups[gr][flagAdd])) }
			if (flagOwed) {
				owedPayment.value = formatFloat(parseFloat(owedPayment.value) + parseFloat(packGroups[gr][flagAdd]))
			}
		}		
		if (total!=null) {
			total.value = formatFloat(parseFloat(total.value) + parseFloat(packGroups[gr][theInd]))
		}
		if (flagOwed) {
			owedPayment.value = formatFloat(parseFloat(owedPayment.value) + parseFloat(packGroups[gr][theInd]))
		}
	}
	
}

function InitExtraNight (nightNm) {
	
	nightEl = window.document.getElementsByName(nightNm)[0]
	if (nightEl!=null) {
	payment = initPayment ()	
	indIs = getNPrice(nightEl.selectedIndex)
	cntIs = calcNCnt (nightEl.selectedIndex)	
	
			if ( nightEl.selectedIndex != 0 && payment ==-1 ) 
				{valENdep = cntIs*mainPrice[indIs]				
				}
			else if ( nightEl.selectedIndex != 0) {
			valENdep = cntIs*cmnPrice[indIs]
			}
			if (nightEl.selectedIndex != 0) {
			valEN = cntIs*cmnPrice[indIs]
			}
	}
}			
function CalcDiscountFilter (theInd, theExept) {
total = window.document.getElementsByName("total")[0]
payment = initPayment ()
	for ( gr in  packGroups) {	
		 if (packGroups [gr][theInd] !=null) {		 	
		 	FilterGroup (gr, theInd,theExept)
		 }
	}
}
function FilterGroup (gr, theInd,theExept) {
selFld = window.document.getElementsByName('packet' + theInd)[0]
flagAdd = 0
flagRem = 0
flagAddNum = 0
total = window.document.getElementsByName("total")[0]
owedPayment = window.document.getElementsByName(usrCncy)[0]

flagOwed = false
if (owedPayment!=null && payment ==-2) {flagOwed = true}

	for (pack in  packGroups[gr]) {	
		tmpFld = window.document.getElementsByName('packet' + pack)[0]		
		if (tmpFld!=null && pack!=theInd ) {		
			if (tmpFld.checked && selFld.checked) {
				if(theExept==pack) {
					if(flagRem==0) {
						flagRem = pack
						if (total!=null) {
							total.value = formatFloat(parseFloat(total.value) - packGroups[gr][theInd])	
						}
						if (flagOwed) {
							owedPayment.value = formatFloat(parseFloat(owedPayment.value) - packGroups[gr][theInd])
						}
					}
					else {
						flagRem = 0
						break;
					}
				}
			}
			else if (tmpFld.checked && selFld.checked==false)
			{				
				if(theExept==pack) {
					flagAddNum = flagAddNum + 1
					flagAdd = pack
				}
								
			}
		}
		
	}
	
	if (flagRem>0 ) {
			total.value = formatFloat(parseFloat(total.value) - parseFloat(packGroups[gr][flagRem]))
			if (flagOwed) {
				owedPayment.value = formatFloat(parseFloat(owedPayment.value) - parseFloat(packGroups[gr][flagRem]))
			}
	}
	else if (flagAdd!=0) {
		
		if (flagAddNum==1) {			
			if (total!=null) {total.value = formatFloat(parseFloat(total.value) + parseFloat(packGroups[gr][flagAdd])) }
			if (flagOwed) {
				owedPayment.value = formatFloat(parseFloat(owedPayment.value) + parseFloat(packGroups[gr][flagAdd]))
			}
		}		
		if (total!=null) {
			total.value = formatFloat(parseFloat(total.value) + parseFloat(packGroups[gr][theInd]))
		}
		if (flagOwed) {
			owedPayment.value = formatFloat(parseFloat(owedPayment.value) + parseFloat(packGroups[gr][theInd]))
		}
	}
	
}

function InitPlusPack(nightNm,flagIs) {

	nightEl = window.document.getElementsByName(nightNm)[0]
	if ( nightEl.selectedIndex == 2 ) {
		complEl = window.document.getElementsByName("packet1")[0]
		total = window.document.getElementsByName("total")[0]
		if (complEl.checked) {
			
			complEl.checked = false;
			MkTotal(complEl,"total");
			if (flagIs>=0) {OwedCommission(complEl);}
			GetMeeting(1,complEl)			
			plusEl = window.document.getElementsByName("packet3")[0]
			plusEl.checked = true
			MkTotal(plusEl,"total");
			if (flagIs>=0) {OwedCommission(plusEl);}
			GetMeeting(1,plusEl);
			nightEl.selectedIndex = 0
			{CalcNight(nightEl)}
		}
	}
	else if ( nightEl.selectedIndex == 7 ) {
		complEl = window.document.getElementsByName("packet1")[0]
		total = window.document.getElementsByName("total")[0]
		if (complEl.checked) {
			complEl.checked = false;
			MkTotal(complEl,"total");
			if (flagIs>=0) {OwedCommission(complEl);}
			GetMeeting(1,complEl)			
			plusEl = window.document.getElementsByName("packet14")[0]
			plusEl.checked = true
			MkTotal(plusEl,"total");
			if (flagIs>=0) {OwedCommission(plusEl);}
			GetMeeting(1,plusEl);
			nightEl.selectedIndex = 0
			{CalcNight(nightEl)}
		}
	}
	else if ( nightEl.selectedIndex == 8 ) {
		complEl = window.document.getElementsByName("packet1")[0]
		if (complEl.checked) {
			complEl.checked = false;
			MkTotal(complEl,"total");
			if (flagIs>=0) {OwedCommission(complEl);}
			GetMeeting(1,complEl)			
			plusEl = window.document.getElementsByName("packet15")[0]
			plusEl.checked = true
			MkTotal(plusEl,"total");
			if (flagIs>=0) {OwedCommission(plusEl);}
			GetMeeting(1,plusEl);
			nightEl.selectedIndex = 0
			CalcNight(nightEl)
		}
	}
}


function calcNumPack() {

	numPack = 0
	for ( i in  cmnPrice) {
			theEl = document.getElementsByName('packet' + (i))[0]
			if (theEl!=null) {
				if (theEl.checked) {numPack ++;}
			}
	}
	return numPack;
}

function getNumPack() {
numPack = 0
	for ( i in  arrUni) {
			theEl = document.getElementsByName('packet' + (i))[0]
			if (theEl!=null && i<7) {
				if (theEl.checked) {numPack ++;}
			}
	}
	return numPack;
}

function getNPrice (newVal) {	

typeC_fld = document.getElementsByName('typeC')[0]
	if (typeC_fld!=null) {		
		if (typeC_fld.value=='uk') {		
			if ( parseInt (newVal) <7 ) {
				//if (numPack>0) {
				return 15;
				//}
				//else {return 10;}
			}
			else if (parseInt (newVal) == 7) {
				//if (numPack>0) {return 8;}
				//else {return 11;}
				return 13;
			}
			else if (parseInt (newVal) == 14 || parseInt (newVal) == 8) {
				//if (numPack>0) {return 9;}
				//else {return 12;}
				return 14;
			}
		}
		else if (typeC_fld.value=='ie') {		
			if ( parseInt (newVal) <7 ) {
				//if (numPack>0) {
				return 32;
				//}
				//else {return 10;}
			}
			else if (parseInt (newVal) == 7) {
				//if (numPack>0) {return 8;}
				//else {return 11;}
				return 33;
			}
			else if (parseInt (newVal) == 14 || parseInt (newVal) == 8) {
				//if (numPack>0) {return 9;}
				//else {return 12;}
				return 34;
			}
		}
		
	
	}
}

function InitFld(curEl,fldName, newVal) {
	fldTotal = document.getElementsByName(fldName)[0]
	tmpNumPack = calcNumPack()
	if (fldTotal!=null) {
		if(curEl.checked) {			
			if(tmpNumPack==1) {		                      
				fldTotal.value = formatFloat(parseFloat (fldTotal.value) + parseFloat(newVal))
			}
		}
		else {
			if(tmpNumPack==0) {
				fldTotal.value = formatFloat(parseFloat (fldTotal.value) - parseFloat(newVal))
			}
			
		}
	}
/*	if (fldEl!=null) {
		if(fldEl.value==startVal||fldEl.value=='') {
			fldEl.value = newVal
		}
		else if(fldEl.value>=newVal&&numPack==-1)  {		
		
			//if(fldEl.value>=newVal) 
				{
					fldEl.value = formatFloat(fldEl.value) - formatFloat(newVal)					
				}
		}
	}
*/
}

function calcNCnt (newVal) {
	
	if ( parseInt (newVal) ==0 ) {
		return 0;
	}
	else if ( parseInt (newVal) <7 ) {
		return parseInt(newVal);	
	}
	else {
		return 1;
	}
}

function initPayment () {
var fldPay="payment__";
	payEl = document.getElementsByName('payment__')[0]
	if (payEl==null) {
		payEl = document.getElementsByName('payment')[0]
		fldPay = "payment";
	}
	if (payEl!=null) {
		payment = get_radio_value (document.getElementsByName(fldPay))
		if (payment=='') {			
			
			window.document.getElementsByName(fldPay)[0].checked = true
			flagPayment = window.document.getElementsByName(fldPay)[0].value
			payment = flagPayment
		}
		return payment;
	}
	
}



function CalcNight (theEl) {
	if (theEl!=null) {
	tmpVal = theEl.value
	if (tmpVal == '') {tmpVal = 0}

	indIs = getNPrice(tmpVal)

	payment=initPayment ()
	
	
	if (payment == -1) {newDep = calcNCnt (tmpVal) * mainPrice[indIs]}
	else {newDep = calcNCnt(tmpVal) * cmnPrice[indIs]}

	newVal = calcNCnt(tmpVal) * cmnPrice[indIs]
	
	fldTotal = window.document.getElementsByName('total')[0]
	if (fldTotal!=null) {
		
		if (fldTotal.value=='') {fldTotal.value='0'}
		if (valEN !=0) {		                      
		fldTotal.value = formatFloat(parseFloat (fldTotal.value ) - valEN)
		}		
		fldTotal.value = formatFloat(parseFloat (fldTotal.value) + newVal)
		
	}
	
	fldDeposit = document.getElementsByName(usrCncy)[0]
	
	if (fldDeposit!=null && payment != '0') {
		 commission = window.document.getElementsByName('commission')[0]
		 if (fldDeposit.value=='') {fldDeposit.value='0'}
		//if (valENdep !=0) 
			{
			fldDeposit.value = formatFloat(parseFloat (fldDeposit.value ) - valENdep)
			}
			fldDeposit.value = formatFloat(parseFloat (fldDeposit.value ) + newDep)
		 if (commission!=null) {
		 	if (commission.value=='') {commission.value='0'}
			 //if (valENdep !=0)
			 {
			 	commission.value = formatFloat(parseFloat (commission.value) - (valEN - valENdep))
			 }
			 commission.value = formatFloat(parseFloat (commission.value ) + (newVal - newDep))
		 }
	}


valEN = newVal
valENdep = newDep

}
}

function GetMeeting (meetNum, theEl) {
	tmpMeeting = window.document.getElementsByName('meeting' + meetNum)[0]
	if (tmpMeeting!=null && theEl!=null) {
		if (theEl.checked == true) {
			tmpMeeting.readOnly = false;
		}
		else {
			flag = 0
			flagEx = 0
			tmpMeeting.readOnly = true;
			for (i in arrUni) {
				if (document.getElementsByName('packet' + (i))[0]!=null && i!=7) {
					if ( meetNum!=(i) && document.getElementsByName('packet' + (i))[0].checked!=true && arrUni[i]) {
						flag =  flag + 1
						
						remEl = document.getElementsByName('packet' + (i))[0]
						remEl.checked = false
					}
					if(arrUni[i]){
						flagEx = flagEx +1
					}
				}
			}
			
			if (flag==(flagEx-1)) {tmpMeeting.value = ""}
		}
	}
}
function MkTotal(thisEl,fldTotal) {
	
	tmpNumP = calcNumPack()
	payment = initPayment ()
	
	
	theEl = window.document.getElementsByName(fldTotal)[0]
	if (theEl!=null) {
		idPacket = parseInt (thisEl.value)
		
		if (theEl.value=="") {
			sumTotal = 0;
		}
		else {
			sumTotal = formatFloat(theEl.value);
		}
		if (thisEl.checked == true) {
			numPack = numPack + 1
			tmpVal = formatFloat(parseFloat(sumTotal) + parseFloat (cmnPrice[idPacket]))
		}
		else {			
			numPack = numPack - 1
			tmpVal = formatFloat(parseFloat(sumTotal) - parseFloat (cmnPrice[idPacket]))
			
		}		
		theEl.value = formatFloat (tmpVal)
	}
	//bug ???
	if (numPack==-1) {numPack++;tmpNumP++;}
	
	
	nEl = window.document.getElementsByName("Extra_Night")[0]
	if (nEl != null) { nIs = nEl.selectedIndex}
	else {nIs = 0}	
	if (tmpNumP == 0 && numPack==1) {
		numPack = tmpNumP
		InitExtraNight("Extra_Night")	
		numPack = 1
		CalcNight(nEl)	
	}
	
	if (tmpNumP == 1 && numPack==0) {		
		numPack = tmpNumP
		InitExtraNight("Extra_Night")
		numPack = 0
		CalcNight(nEl)	
	}
	
}
function elShowHide(thisEl,theNm)
{
theEl = document.getElementById(theNm)
	if (thisEl.checked) {
	theEl.style.display='table-row-group'
	}
	else {
	theEl.style.display='none'
	}
}
function ShowHide(thisEl,shEl)
{
	if (thisEl.checked) {
	shEl.style.display='inline'
	}
	else {
	shEl.style.display='none'
	}
}

function UniSelectCheck (theInd) {
var remEl
//uniselect fields!!!
numPack=calcNumPack()
//if (theInd == 11 || theInd == 2 || theInd == 20) { arrIs = arrUniUkBank}
//else 
if (theInd == 17 || theInd == 37) { arrIs = arrUniUkBankAu}
else if (theInd == 18 || theInd == 38) { arrIs = arrUniVisaF}
else if (theInd == 19) { arrIs = arrUniUKCmp}
else if (theInd == 26 || theInd == 101) { arrIs = arrUniBankGetStart }
else if (theInd == 21) { arrIs = arrUniUkNIN}
else if (theInd == 26) { arrIs = arrUniUkGetStart}
else if (theInd == 25 || theInd == 13 || theInd == 14) { arrIs = arrUniUkGetFlat}
else if (theInd == 29) { arrIs = arrUniUkComplPlus}
else if (theInd == 30||theInd == 35||theInd == 36) { arrIs = arrUniUkPlus}
else if (theInd == 31 || theInd == 32 || theInd == 33 || theInd == 34 || theInd == 34) { arrIs = arrIePackBank}
else if (arrUniCSCS[theInd]==true) {arrIs = arrUniCSCS}
else {arrIs = new Array()}


theEl = document.getElementsByName('packet' + theInd)[0]
//existcom = document.getElementsByName('commission')[0]
owedCncy = document.getElementsByName(usrCncy)[0]
flag = false
if (theEl!=null) {

    if (theEl.checked) 
    { 
		for (i in arrIs) 
		{
			if (document.getElementsByName('packet' + (i) )[0]!=null && i!=7) 
			{
				if ( theInd!=(i) && document.getElementsByName('packet' + (i))[0].checked && arrIs[i]) 
				{
					flag =  true
					remEl = document.getElementsByName('packet' + (i))[0]
					
					remEl.checked = false	
					
					if (numPack>1) {CalcDiscount (i,theInd)}
					fldTotal = document.getElementsByName('commission')[0]
					MkTotal (remEl,'total')					
					if (owedCncy!=null) { OwedCommission(remEl) }
					
				}
			}
		}
   }
  
}

}
//ClearPacks("packbank",this)
arrGroupPacks = new Array()
arrGroupPacks ['packbank'] =  new Array()
arrGroupPacks ['packbank'] = Array('11','96','97')
arrGroupPacks ['packbankplus'] =  new Array()
arrGroupPacks ['packbankplus'] = Array('2','98','99')
arrGroupPacks ['packgetstart'] =  new Array()
arrGroupPacks ['packgetstart'] = Array('26','100','101')

function ClearMainPack (packGroup,fldGroupName,curEl) {
	fldGroup = window.document.getElementsByName(fldGroupName)[0]
	flagUnselect = true;	
	
	if (fldGroup.checked && (!curEl.checked) ) {
		for ( indPack in  arrGroupPacks[packGroup]) {		
		indPackName = arrGroupPacks[packGroup][indPack]
		selFld = window.document.getElementsByName('packet' + indPackName)[0]		
		if (selFld!=null) {	
			if(selFld.checked) {
				flagUnselect = false
			}
		}
	}
	if (flagUnselect) {fldGroup.checked=false}
}
}

function CalcAgentDiscount(isPack,exeptPack) {
	countChecked = 0
	curCheck = window.document.getElementsByName('packet' + isPack)[0].checked
	theExept = 0
	flagNIN = false;
	for ( gr in  packGroups) {
		for (pack in  packGroups[gr]) {
			tmpFld = window.document.getElementsByName('packet' + pack)[0]
                        if (tmpFld!=null) {
                                if(isPack==exeptPack) {
                                        if (tmpFld.checked && tmpFld.value!=exeptPack) {
                                                countChecked = countChecked + 1
                                                if(theExept==0) {
                                                        theExept = pack
                                                }
                                        }
                                }
                                else {
                                        if (tmpFld.value==exeptPack) {
                                                flagNIN = true
                                        }
                                        else if (tmpFld.checked){
                                                countChecked = countChecked + 1
                                        }
                                }
                }
		}
	}
	
	if(isPack==exeptPack && countChecked>=1) {		
		CalcDiscountFilter(isPack,theExept);
	}
	else if (isPack!=21 && flagNIN && ((countChecked==1 && curCheck) || (countChecked==0 && !curCheck))) {
		
		CalcDiscountFilter(isPack,exeptPack);
	}
}

function ClearPacks (packGroup,fldGroup,flagOpt) {
if (fldGroup!=null) {
	var fldPay="payment__";
	payEl = document.getElementsByName('payment__')[0]
	if (payEl==null) {
		payEl = document.getElementsByName('payment')[0]
		fldPay = "payment";
	}
	if (payEl==null) {return;}
	payment = get_radio_value (document.getElementsByName(payEl));
	flagPayment = false
	if(payment!=null) {
		flagPayment = true;
	}
	if (!fldGroup.checked) {
		for ( indPack in  arrGroupPacks[packGroup]) {
		
		indPackName = arrGroupPacks[packGroup][indPack]
		selFld = window.document.getElementsByName('packet' + indPackName)[0]		
		if (selFld!=null) {			
			if (selFld.checked) {			
				selFld.checked = false
				MkTotal(selFld,"total");
				if(flagOpt==1)
					{
					CalcDiscount(indPackName,0);					
					}
				else if(flagOpt==2) {
					CalcAgentDiscount(indPackName,21)
				}
				if(flagPayment) {
					OwedCommission(selFld);
				}
			}
		}
		
	}
	}
	else {
	flagSetup = false;
		for ( indPack in  arrGroupPacks[packGroup]) {		
			indPackName = arrGroupPacks[packGroup][indPack]
			selFld = window.document.getElementsByName('packet' + indPackName)[0]	
			if (selFld!=null) {
				if (selFld.checked) {flagSetup=true}
				
			}
		}
		if (!flagSetup) {
			indPackName = arrGroupPacks[packGroup][0]
			selFld = window.document.getElementsByName('packet' + indPackName)[0]	
			if (selFld!=null) {	
				selFld.checked = true;
				MkTotal(selFld,"total");
				
				if(flagOpt==1)
					{
					CalcDiscount(indPackName,0);					
					}
				else if(flagOpt==2) {
					CalcAgentDiscount(indPackName,21)
				}
				if(flagPayment) {
					OwedCommission(selFld);
				}
			}
		}
	}
	
	
  }
}


function formatFloat (num) {
num = num*100
num = Math.round (num)
num = num/100
return num;
}

//agents
function initPriceArr (priceIs) {
if (parseFloat(priceIs)>=0) {
return priceIs;
}
else {
return 0;
}
}
function PacketTotal(fldExt,fldTotal,fldPacket) {
total = formatFloat(15 * parseFloat(document.getElementsByName(fldExt)[0].value)) 
pack = formatFloat(parseFloat(document.getElementsByName(fldPacket)[0].value))

newval_owed = formatFloat(total + mainPrice[pack-1])
newval_client = formatFloat(total + cmnPrice[pack-1])

if (total > 0 && pack>0 && pack< numPackets)
		{document.getElementsByName(fldTotal)[0].value = newval_client
	
		
		document.getElementsByName(usrCncy)[0].value = formatFloat(parseFloat(document.getElementsByName(usrCncy)[0].value) + newval_owed)
		
		
}
else if (pack>0) {
document.getElementsByName(fldTotal)[0].value = cmnPrice[pack-1]
document.getElementsByName(usrCncy)[0].value = mainPrice[pack-1] + eval(usrCncy+'_Owed')

}
else {
	document.getElementsByName(fldTotal)[0].value = ""
	 
}
}

function RecalculateSums () {
var fldPay="payment__";
	payEl = document.getElementsByName('payment__')[0]
	if (payEl==null) {
		payEl = document.getElementsByName('payment')[0]
		fldPay = "payment";
	}
	if (payEl==null) {return;}
payment = get_radio_value (document.getElementsByName(fldPay))

comEl = window.document.getElementsByName('commission')[0]
owedPayment = window.document.getElementsByName(usrCncy)[0]
extraNight  = window.document.getElementsByName('extra_night' )[0]
	if (comEl!=null && (comEl.value != '' || comEl.value != '0') && flagPayment ==0) {
		comEl.value = '0'
		document.getElementsByName(usrCncy)[0].value = '0'
		//bug!!!
	}
	if (payment == -1) 
	{
		for ( i in  mainPrice)
		 {
		 	 if (window.document.getElementsByName('packet' +i)[0]!=null && (i!='8')) {
		 		theEl = window.document.getElementsByName('packet' + i)[0].checked
				if (theEl)
				{
					if (flagPayment!=0)
					{
		  				if (comEl!=null) { comEl.value=formatFloat(parseFloat(comEl.value) - (parseFloat(cmnPrice[i]) - parseFloat(cmnPrice[i])))}
						owedPayment.value = parseFloat(owedPayment.value) - parseFloat(cmnPrice[i])
					}
					if (comEl!=null) { comEl.value=formatFloat(parseFloat(comEl.value) + (parseFloat(cmnPrice[i]) - parseFloat(mainPrice[i])))}		  
					owedPayment.value = formatFloat(parseFloat(owedPayment.value) + parseFloat(mainPrice[i]))
					
				}
			}
			
		}
		
		//bugs???
				if (extraNight != null && extraNight.value != '') {
				//&& flagPayment!=0
				tstVal = extraNight.value
				if(tstVal=='') {tstVal=0}
				indIs = getNPrice(tstVal)
				
				newDep = calcNCnt (tstVal) * mainPrice[indIs]					
				newVal = calcNCnt(tstVal) * cmnPrice[indIs]

				
				InitExtraNight("extra_night")			
				if(owedPayment!=null) {				
					if(owedPayment.value==''){owedPayment.value=0}
					if(flagPayment!=0||owedPayment.value>0)
					{					
						owedPayment.value = formatFloat(parseFloat(owedPayment.value) - valEN)
					}
						owedPayment.value = formatFloat(formatFloat(parseFloat(owedPayment.value) + newDep))
				}
				
				if (comEl!=null) {
					if(flagPayment!=0||owedPayment.value>0){
					//	comEl.value = formatFloat(parseFloat(comEl.value) -(valEN-valENdep))
					}
						comEl.value = formatFloat(parseFloat(comEl.value) + (newVal - newDep))
					}
				
				valENdep = newDep
				valEN = newVal		
				
			}
		
	}
	else if (payment == -2){
	
		if(owedPayment != null) {
			owedPayment.value = window.document.getElementsByName('total')[0].value
		}
		if (comEl!=null) {comEl.value = '0' }		
		
		if (extraNight != null) {				
				tstVal = extraNight.value
				if(tstVal=='') {tstVal=0}				
				indIs = getNPrice(tstVal)
				valEN = calcNCnt(tstVal) * cmnPrice[indIs]
				valENdep = valEN			
						
		}
		
	}
	else if (payment == 0) {
	if (comEl!=null) { comEl.value = 0 }
	//owedPayment.value = formatFloat(parseFloat(document.getElementsByName(usrCncy)[0].value))
			owedPayment.value = 0
	
			if (extraNight != null) {				
				tstVal = extraNight.value
				if(tstVal=='') {tstVal=0}				
				indIs = getNPrice(tstVal)							
				valEN = calcNCnt(tstVal) * cmnPrice[indIs]
				valENdep =valEN
		}
	
	}
	


flagPayment = payment

}

function PacketCommission(fldSel,fldCmn) {
var fldPay="payment__";
	payEl = document.getElementsByName('payment__')[0]
	if (payEl==null) {
		payEl = document.getElementsByName('payment')[0]
		fldPay = "payment";
	}
	if (payEl==null) {return;}
	payment = get_radio_value (document.getElementsByName(fldPay))	
	if (payment == -1) 
	{
		newval = mainPrice [fldSel.value]
	}
	else
	{
		newval = cmnPrice[fldSel.value]
	}
	
	if (fldCmn.value == "") {
		fldCmn.value = "0"
	}

	cmn = formatFloat(parseFloat(cmnPrice [fldSel.value]) - parseFloat(newval))
	
	if (cmn > 0 && fldSel.checked == true ) {
		
		fldCmn.value = formatFloat(parseFloat(fldCmn.value) + cmn)
	}
	else if (cmn > 0) {
		fldCmn.value = formatFloat(parseFloat(fldCmn.value) - cmn)
	}
		
	if (fldCmn.value == "") {
	fldCmn.value = "0"
	}
		
}

function OwedCommission(fldSel) {
var fldPay="payment__";
	payEl = document.getElementsByName('payment__')[0]
	if (payEl==null) {
		payEl = document.getElementsByName('payment')[0]
		fldPay = "payment";
	}
	if (payEl==null) {return;}
owedFld = document.getElementsByName(usrCncy)[0]
if (owedFld!=null) {
		newVal = 0
		if (owedFld.value == '') {
		owedFld.value = '0'
		}
		owedFld = true
payment = get_radio_value (document.getElementsByName(fldPay))

if (payment!=null && payment != 0) {
	existcom = document.getElementsByName('commission')[0]
	
	
	if (payment == -1) 
	{
		newVal = mainPrice [fldSel.value] 
		
	}
	else 
	{
		newVal = cmnPrice[fldSel.value]
	}
	
	
	if (fldSel.checked == true) {
		newVal = parseFloat(document.getElementsByName(usrCncy)[0].value) + newVal
	}
	else {
		newVal = parseFloat(document.getElementsByName(usrCncy)[0].value) - newVal
	}

	if (existcom!=null) {
		PacketCommission(fldSel,existcom) 
		
	}
	
	tmpVal = newVal*100
	tmpVal = Math.round (tmpVal)
	newVal = tmpVal/100

	document.getElementsByName(usrCncy)[0].value = newVal
	
	}
}
}

function removeOneDivByGroup(divName , divInd, trueVal, idGroup) {
arrGr_1 = new Array()
arrGr_1 ['21'] = getCheckState("packet21");
arrGr_1 ['26'] = getCheckState("packet26");
arrGr_1 ['101'] = getCheckState("packet101");


arrGr_2 = new Array()
arrGr_2 ['23'] = getCheckState("packet23");
arrGr_2 ['112'] = getCheckState("packet112");
arrGr_2 ['113'] = getCheckState("packet113");
arrGr_2 ['114'] = getCheckState("packet114");
arrGr_2 ['140'] = getCheckState("packet140");
arrGr_2 ['115'] = getCheckState("packet115");
arrGr_2 ['116'] = getCheckState("packet116");
arrGr_2 ['118'] = getCheckState("packet118");
arrGr_2 ['117'] = getCheckState("packet117");


arrGr_3 = new Array()
/*arrGr_3 ['112'] = getCheckState("packet112");
arrGr_3 ['114'] = getCheckState("packet114");
arrGr_3 ['115'] = getCheckState("packet115");
arrGr_3 ['116'] = getCheckState("packet116");
arrGr_3 ['118'] = getCheckState("packet118");
arrGr_3 ['120'] = getCheckState("packet120");
arrGr_3 ['121'] = getCheckState("packet121");
arrGr_3 ['140'] = getCheckState("packet140");*/
arrGr_3 ['23'] = getCheckState("packet23");
arrGr_3 ['112'] = getCheckState("packet112");
arrGr_3 ['113'] = getCheckState("packet113");
arrGr_3 ['114'] = getCheckState("packet114");
arrGr_3 ['140'] = getCheckState("packet140");
arrGr_3 ['115'] = getCheckState("packet115");
arrGr_3 ['116'] = getCheckState("packet116");
arrGr_3 ['118'] = getCheckState("packet118");
arrGr_3 ['117'] = getCheckState("packet117");

arrGr_4 = new Array()
arrGr_4 ['23'] = getCheckState("packet23");
arrGr_4 ['112'] = getCheckState("packet112");
arrGr_4 ['113'] = getCheckState("packet113");
arrGr_4 ['114'] = getCheckState("packet114");

flagShow = false
arrGr = eval("arrGr_"+idGroup)
	for ( i_element in  arrGr) {		
		if (arrGr[i_element]==trueVal) {
			flagShow = true
			break;
		}
	}
	
		if (flagShow) {			
			document.getElementById(divName.toLowerCase()+divInd).style.display = '';			
		}
		else {
			document.getElementById(divName.toLowerCase()+divInd).style.display = 'none';
		}
		
}
function getCheckState (name) {
	return (document.getElementsByName(name)[0]!=null)?document.getElementsByName(name)[0].checked:false;
}
function showCisFields () {
	//arrCisDiv = new Array(23,113,117,120,121,140);
        arrCisDiv = new Array(23,112,113,114,140,115,116,117,118);
	flagShow=false;
	for ( i_element in  arrCisDiv) {
		if (document.getElementsByName("packet"+arrCisDiv[i_element])[0]!=null && document.getElementsByName("packet"+arrCisDiv[i_element])[0].checked) {
			flagShow = true;
			break;
		}
	}
	return flagShow;
}
function SubmitButtonCSCS () {
        payment_tmp = document.getElementById('payment0');
        location_tmp = document.getElementsByName('cscstest_where__')[0];
        if (payment_tmp !=null && location_tmp!=null) {
                if (payment_tmp.checked && location_tmp.value!='1' && location_tmp.value!='') {
                        
                        return false;
                }
        }
        return true;
}
