function getContVal(control,controlToPopulate,ItemArray,lang)
{
	var myEle ;
	var x ;
	 for (var q=controlToPopulate.options.length;q>=0;q--) 
  {controlToPopulate.options[q]=null;}

  if (ItemArray[control.selectedIndex - 1] >0)
  {
	if (lang==0)
	{
		myEle = document.createElement("option") ;
		myEle.value = "1" ;
		myEle.text = "Fixed Installment" ;
		controlToPopulate.options.add(myEle) ;	
		//myEle = document.createElement("option") ;
		//myEle.value = "2" ;
		//myEle.text = "Balloon Installment" ;
		//controlToPopulate.options.add(myEle) ;	
	}
	else
	{
		myEle = document.createElement("option") ;
		myEle.value = "1" ;
		myEle.text = "اقساط متساوية" ;
		controlToPopulate.options.add(myEle) ;	
		//myEle = document.createElement("option") ;
		//myEle.value = "2" ;
		//myEle.text = "دفعة اخيرى" ;
		//controlToPopulate.options.add(myEle) ;		
	}
	
  }
  else
  {
	if (lang==0)
	{
		myEle = document.createElement("option") ;
		myEle.value = "1" ;
		myEle.text = "Fixed Installment" ;
		controlToPopulate.options.add(myEle) ;	
		
	}
	else
	{
		myEle = document.createElement("option") ;
		myEle.value = "1" ;
		myEle.text = "اقساط متساوية" ;
		controlToPopulate.options.add(myEle) ;	
			
	}	
  }
    }

function selectChange(control, controlToPopulate, ItemArray, GroupArray,lang)
{
  var myEle ;
  var x ;
  // Empty the second drop down box of any choices
  
  for (var q=controlToPopulate.options.length;q>=0;q--) 
  {controlToPopulate.options[q]=null;}

  //ADD Default Choice - in case there are no values
 myEle = document.createElement("option") ;
 myEle.value = "0" ;
 if (lang==1) {
 myEle.text = "اختر مدة القرض"; }
	else { 
	myEle.text = "Select Loan Period" ;}
	controlToPopulate.options.add(myEle) ;

  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
 
  for ( x = 0 ; x < ItemArray.length  ; x++ )
    { 
      if ( GroupArray[x] == control.options[control.selectedIndex].value )
        {
          myEle = document.createElement("option") ;
          myEle.value = ItemArray[x] ;
          myEle.text = ItemArray[x] ;
          controlToPopulate.options.add(myEle) ;
        }
    }
}

function loadMin(control)
{
 if (control.selectedIndex != 0) 
  {	
	document.forms[0].tbAmount.value=MinAmountArr[control.selectedIndex -1];
  }
  else
  {
	document.forms[0].tbAmount.value=""
  }
}

function TestCalcType(control,lang)
{
 if (control.selectedIndex != 0) 
  {	
	if(CalcTypeArr[control.selectedIndex -1]==1)
		{
		    if (lang==1) {
			document.forms[0].tbDownPayment.value="لا داعى لدفعة مقدمة."}
			else document.forms[0].tbDownPayment.value="No required down payment." 
			document.getElementById('trDownPay1').style.display="none";
		}
	else
		{	
			if (lang==1) {document.forms[0].tbDownPayment.value="الدفعة المقدمة."}
			else document.forms[0].tbDownPayment.value="Down Payment."
			document.getElementById('trDownPay1').style.display="inline";
		}
  }
}
function Validate(sender, args)
  {	
	args.IsValid = true;
    var e = document.forms[0];
    
    var min = MinAmountArr[_mainSelect.selectedIndex - 1];
    var max = MaxAmountArr[_mainSelect.selectedIndex - 1];

    if(_mainSelect.selectedIndex != 0)
    {
		if (e.LoanPeriod.selectedIndex > 0)
			{	
				if(+e.tbAmount.value > 0)
				{	
				if (+e.tbAmount.value >= min && +e.tbAmount.value <= max)
					{	//no down payment req cos loan type = 1
						if(CalcTypeArr[_mainSelect.selectedIndex -1] == 1)
							{	
								args.IsValid = args.IsValid && true;
							}
					    else
					    {
							if(+e.tbDownPayment.value > 0)
							 {	
								if(+e.tbDownPayment.value >= DownPayArr[_mainSelect.selectedIndex - 1])
								{	
									if(+e.tbDownPayment.value <= +e.tbAmount.value)
									{
										args.IsValid = args.IsValid && true;
									}
									else
									{
									args.IsValid = args.IsValid && false;
									alert(PayAmtErrArr[8] + "=" + +e.tbAmount.value + " !");
									}
								}
								else
								{
									args.IsValid = args.IsValid && false;
									alert(PayAmtErrArr[7] + DownPayArr[_mainSelect.selectedIndex - 1] + " !");
								}
							 }
							 else
							 {
								args.IsValid = args.IsValid && false;
								alert(PayAmtErrArr[6]);
							 }
					    }
					}
				else
					{
					args.IsValid = args.IsValid && false;
					alert(PayAmtErrArr[3] + "[ " + min + " ," + max + " ] !");
					}
			}
		else
			{	
			args.IsValid = args.IsValid && false;
			alert(PayAmtErrArr[1]);
			}
		}
		else
		{
			args.IsValid = args.IsValid && false;
			alert(PayAmtErrArr[5]);
		}
	}
	else
	  {
		args.IsValid = args.IsValid && false;
		alert(PayAmtErrArr[4]);
	  }
	return;
  }
  

