/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

				Page Header

File Name		:	country.js
Scope of program	:	To form interdependant combobox for country,state
				& region.
Created On		:	22-03-2005.
Modified On		:	25-03-2005
Reason of Modification	:	since sequence no is used as value instead of id
				the index were converted to string.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/



function change_st(tmp_str_frm,tmp_int_selSt,tmp_int_selReg,tmp_str_cmbxs)
{
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	 Name		: change_st()
	 Purpose	: Dynamic interdependant comboboxes for country/state &
	 		  region
	 Inputs		: tmp_str_frm  	 -> form name
			  tmp_int_selSt  -> state to be displayed as selected
			  tmp_int_selreg -> region to be displayed as selected
			  tmp_str_cmbxs  -> comma separated names of comboboxes
	 Outputs	: change the data to be displayed depending on value
	 		  selected in country combo box
	 Calls		:  addNew()
	 		   emptyDD()
	 Called By	:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

   /* get the form object */
   eval("thisDoc = document."+tmp_str_frm);

   tmp_arr_cmbxs = tmp_str_cmbxs.split("~");

   tmp_str_frmCtry  = tmp_arr_cmbxs[0];
   tmp_str_frmSt    = tmp_arr_cmbxs[1];
   tmp_str_frmReg   = tmp_arr_cmbxs[2];

   /* get the selected option */
   eval("tmp_int_ctry = thisDoc."+tmp_str_frmCtry+"[thisDoc."+tmp_str_frmCtry+".selectedIndex].value");

 eval("tmp_int_ko = thisDoc.carregion");

   /* if country list exists for selected language */
   if( tmp_int_ctry == "238799s86aa" )
   {
		alert( tmp_int_ko );

// eerst de provincie vullen

        emptyDD(tmp_str_frmSt,thisDoc)
	tmp_str_stIds = "tmp_arr_stIDs[\""+tmp_int_ctry+"\"]";
	tmp_str_sts   = "tmp_arr_sts[\""+tmp_int_ctry+"\"]";

	eval("tmp_str_stIds = "+tmp_str_stIds);
	eval("tmp_str_sts = "+tmp_str_sts);

    /* empty the state combobox  */
    emptyDD(tmp_str_frmSt,thisDoc)


	/* corresponding states do not exist */
	if( tmp_str_stIds == 0 )
	{
	      /* add Other option */
	      addNew(tmp_str_frmSt,0,tmp_str_other,thisDoc,0)

	}
	else
	{
	     /* remove the preceeding ~ */
	     tmp_str_stIds   = tmp_str_stIds.substring(1,tmp_str_stIds.length);
	     tmp_str_sts     = tmp_str_sts.substring(1,tmp_str_sts.length);

	     /* convert into array by splitting on basis on ~ */
	     tmp_arr_stID2 = tmp_str_stIds.split("~");
	     tmp_str_sts2  = tmp_str_sts.split("~");

	     //alert(tmp_str_sts2);

	 //   eval("thisDoc = document."+tmp_str_frm.);

	     tmp_int_idx = 0;

	     /* fill the state combobox   */
	     for(k=0;k<tmp_arr_stID2.length ; k++)
	     {

	     	//alert(tmp_arr_stID2[k]);

	     	/* retrieve seq no */
	     	tmp_str_seqID =	tmp_arr_stID2[k];

			tmp_arr_seqID = tmp_str_seqID.split("s");

			tmp_str_seqID = tmp_arr_seqID[1];

			if( tmp_int_selSt == tmp_str_seqID )
			{
			    tmp_int_idx = k;
	 		}

	 		//alert(tmp_arr_stID2[k]);
//	 		alert(tmp_str_sts2[k]);

		/* add option to combobox */
	 	addNew(tmp_str_frmSt,tmp_arr_stID2[k],tmp_str_sts2[k],thisDoc,k)

	     }

	     /* display the selected state as selected */
	     thisDoc[tmp_str_frmSt].options[tmp_int_idx].selected = true;
	}




	     for(k=0;k<3; k++)
	     {
        addNew(tmp_str_frmReg,'k',"kreta" ,thisDoc,k)
	     }

   }
   else
   if( tmp_int_ctry != "" )
   {
	/* retrieve the corresponding states for selected country */
	tmp_str_stIds = "tmp_arr_stIDs[\""+tmp_int_ctry+"\"]";
	tmp_str_sts   = "tmp_arr_sts[\""+tmp_int_ctry+"\"]";

	eval("tmp_str_stIds = "+tmp_str_stIds);
	eval("tmp_str_sts = "+tmp_str_sts);

    /* empty the state combobox  */
    emptyDD(tmp_str_frmSt,thisDoc)


	/* corresponding states do not exist */
	if( tmp_str_stIds == 0 )
	{
	      /* add Other option */
	      addNew(tmp_str_frmSt,0,tmp_str_other,thisDoc,0)

	}
	else
	{
	     /* remove the preceeding ~ */
	     tmp_str_stIds   = tmp_str_stIds.substring(1,tmp_str_stIds.length);
	     tmp_str_sts     = tmp_str_sts.substring(1,tmp_str_sts.length);

	     /* convert into array by splitting on basis on ~ */
	     tmp_arr_stID2 = tmp_str_stIds.split("~");
	     tmp_str_sts2  = tmp_str_sts.split("~");

	     //alert(tmp_str_sts2);

	 //   eval("thisDoc = document."+tmp_str_frm.);

	     tmp_int_idx = 0;

	     /* fill the state combobox   */
	     for(k=0;k<tmp_arr_stID2.length ; k++)
	     {

	     	//alert(tmp_arr_stID2[k]);

	     	/* retrieve seq no */
	     	tmp_str_seqID =	tmp_arr_stID2[k];

			tmp_arr_seqID = tmp_str_seqID.split("s");

			tmp_str_seqID = tmp_arr_seqID[1];

			if( tmp_int_selSt == tmp_str_seqID )
			{
			    tmp_int_idx = k;
	 		}

	 		//alert(tmp_arr_stID2[k]);
//	 		alert(tmp_str_sts2[k]);

		/* add option to combobox */
	 	addNew(tmp_str_frmSt,tmp_arr_stID2[k],tmp_str_sts2[k],thisDoc,k)

	     }

	     /* display the selected state as selected */
	     thisDoc[tmp_str_frmSt].options[tmp_int_idx].selected = true;
	}

	/* change the options in Region DD */
//alert(tmp_int_selReg);
	change_reg(tmp_str_frm,tmp_int_selReg,tmp_str_cmbxs);
   }

}


function change_reg(tmp_str_frm,tmp_int_selReg,tmp_str_cmbxs)
{
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	 Name		: change_reg
	 Purpose	: Dynamic interdependant comboboxes for state & region
	 Inputs		: tmp_str_frm  	 -> form name
			  tmp_int_selSt  -> state to be displayed as selected
			  tmp_int_selreg -> region to be displayed as selected
			  tmp_str_cmbxs  -> comma separated names of comboboxes
	 Outputs	: change the data to be displayed depending on value
	 		  selected in region combo box
	 Calls		: addNew()
	 		  emptyDD()
	 Called By	:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
   tmp_arr_cmbxs = tmp_str_cmbxs.split("~");

   tmp_str_frmCtry  = tmp_arr_cmbxs[0];
   tmp_str_frmSt    = tmp_arr_cmbxs[1];
   tmp_str_frmReg   = tmp_arr_cmbxs[2];

   /* get the form object */
   eval("thisDoc = document."+tmp_str_frm);

   /* get the selected option */
   eval("tmp_int_st = thisDoc."+tmp_str_frmSt+"[thisDoc."+tmp_str_frmSt+".selectedIndex].value");

   //alert(tmp_int_st);

   if(tmp_str_frmReg != ""){
   	/* empty the state combobox  */
   	emptyDD(tmp_str_frmReg,thisDoc)
   }

   /* if country list exists for selected language */
   if( tmp_int_st != 0 && tmp_int_st != -1)
   {
	/* retrieve the corresponding states for selected state */
	tmp_str_regIds = "tmp_arr_regIDs[\""+tmp_int_st+"\"]";
	tmp_str_reg   =  "tmp_arr_regs[\""+tmp_int_st+"\"]";

	//alert("reg ids "+tmp_str_regIds+" len "+tmp_arr_regIDs.length);

	eval("tmp_str_regIds = "+tmp_str_regIds);
	eval("tmp_str_reg = "+tmp_str_reg);

	/* remove the preceeding ~ */
	tmp_str_regIds   = tmp_str_regIds.substring(1,tmp_str_regIds.length);
	tmp_str_reg      = tmp_str_reg.substring(1,tmp_str_reg.length);

	/* convert into array by splitting on basis on ~ */
	tmp_arr_regID2 = tmp_str_regIds.split("~");
	tmp_str_reg2  = tmp_str_reg.split("~");

	tmp_int_idx = 0;

	/* fill the region combobox   */
        for(k=0;k<tmp_arr_regID2.length ; k++)
        {
	    //alert(tmp_arr_regID2[k]);
	    /* retrieve seq no */
	    tmp_str_seqID = tmp_arr_regID2[k];
	    tmp_arr_seqID = tmp_str_seqID.split("s");
	    tmp_str_seqID = tmp_arr_seqID[1];

	    if( tmp_int_selReg == tmp_str_seqID )
	    {
		tmp_int_idx = k;
	    }

	    if(tmp_str_frmReg != ""){
	    	/* add option to region combobox */
	    	addNew(tmp_str_frmReg,tmp_arr_regID2[k],tmp_str_reg2[k],thisDoc,k);
	    }
	}

       if(tmp_str_frmReg != ""){
       	/* display the selected region as selected */
       	thisDoc[tmp_str_frmReg].options[tmp_int_idx].selected = true;
       }

   }
   else
   {
	if(tmp_str_frmReg != ""){	
	      /* add All option to region DD */
	      addNew(tmp_str_frmReg,'-1s-1',tmp_str_all,thisDoc,0)
   	}
   }
}


function addNew(tmp_str_name,tmp_str_val,tmp_str_txt,thisDoc,tmp_int_idx)
{
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	 Name		: addNew
	 Purpose	: add new <option> for select
	 Inputs		: thisDoc 	 -> form object
	 		  tmp_int_idx	 -> index at which option must be added
			  tmp_str_val	 -> value of option
			  tmp_str_txt	 -> text of option
	 Outputs	: fills the combo box with given value
	 Calls		: None
	 Called By	:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
	/* add "new " option */
	elmt = new Option();
	elmt.value = tmp_str_val;
	elmt.text  = tmp_str_txt;

	thisDoc[tmp_str_name].options[tmp_int_idx] = elmt;
	thisDoc[tmp_str_name].options[tmp_int_idx].selected = true;
}


function emptyDD(tmp_str_name,thisDoc)
{
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	 Name		: emptyDD()
	 Purpose	: empty the combobox
	 Inputs		: thisDoc 	 -> form object
			  tmp_str_name	 -> combobox name
	 Outputs	: empties the combo box
	 Calls		: None
	 Called By	:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
//	alert(tmp_str_name);

	/* get the currrent no of options  */
	tmp_int_pLen = thisDoc[tmp_str_name].length;

	/* empty the  drop down */
	for(i=tmp_int_pLen;i>=0;i--)
	{
		thisDoc[tmp_str_name].options[i] = null;
	}
}


