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

				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)
{
//	alert(tmp_int_selSt);
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	 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	:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

//   alert("Hello");
   /* 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");

	//alert(tmp_int_ctry);
   /* if country list exists for selected language */
   if( tmp_int_ctry != "" )
   {
	/* retrieve the corresponding states for selected country */
/* if( !tmp_arr_stIDs ) alert("äa"); */
	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_notAvail,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("~");

	 //   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;
	 	}

		/* 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 */
	change_reg(tmp_str_frm,tmp_int_selReg,tmp_str_cmbxs);
   }else{
    	emptyDD(tmp_str_frmSt,thisDoc);
    	addNew(tmp_str_frmSt,"",tmp_str_select,thisDoc,0);

   }
}


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");

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

   /* if country list exists for selected language */
   if( tmp_int_st != 0 )
   {
	/* 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;
	    }

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

       /* display the selected region as selected */
       thisDoc[tmp_str_frmReg].options[tmp_int_idx].selected = true;

   }
   else
   {
      if(tmp_int_st == ""){
        emptyDD(tmp_str_frmReg,thisDoc)
        addNew(tmp_str_frmReg,"",tmp_str_select,thisDoc,0);
      }else{
	 /* add Other option to region DD */
	 addNew(tmp_str_frmReg,0,tmp_str_notAvail,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;
	}
}




/***** Peter . Lemmen  2006 ***********************
 *
 *
 *
 *
 *
 *
 *
 **************************************************/



function createRequestObject()
{
 var req;

 if(window.XMLHttpRequest) {
	req = new XMLHttpRequest();
 } else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP" );
 } else {
 	alert('problem creating ' );
 }

 return req;
}

var pmgContextPool = new Array();
var http = createRequestObject();


function handleResponse()
{
 if( http.readyState == 4 && http.status == 200 ) {
  var response = http.responseText;


  if( response ) {

    document.frmAdvDtl.frmState.options.length=0;

    options=response.split("|");
    for( var i = 0; i < options.length-1; i++ )
    {
        staten = options[i].split("~");
    	document.frmAdvDtl.frmState.options[i] = new Option(staten[0],staten[1]);
    }

  }
 }

}

function post_exec( inpu , site )
{

if( http ) {
  http.abort;
  http.open('post',site );
  http.setRequestHeader('Content-Type','application/x-www-form-urlencoder');
  http.send('act='+act );
  }

}

function get_exec( inpu , site )
{
if( http ) {
  http.open('get',''+site+'?act='+inpu );
  http.onreadystatechange=handleResponse;
  http.send(null);
  }
}

function pmg_change_reg(tmp_str_frm,tmp_int_selSt,tmp_int_selReg,tmp_str_cmbxs)
{
//	alert(tmp_int_selSt);
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	 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	:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

   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");
  	 get_exec( tmp_int_ctry , '../include/inc_common/pmg_getstates.php' );
}
function pmg_change_st(tmp_str_frm,tmp_int_selSt,tmp_int_selReg,tmp_str_cmbxs)
{
//	alert(tmp_int_selSt);
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	 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	:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

   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");
  	 get_exec( tmp_int_ctry , '../include/inc_common/pmg_getstates.php' );
}
