
//====================================================================================================
//	File Name		:	functions.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Javascript Utility functions
//	Author			:	Nirmal Patel
//	Creation Date	:	05-May-2003
//	Copyright		:	Copyrights © 2003 Dot Infosys
//	Email			:	info@dotinfosys.com
//	History			:
//						Date						Author						Remark
//						05-May-2003					Nirmal Patel				Initial Release
//
//====================================================================================================

//====================================================================================================
//	Function Name	:	popupWindowURL
//	Purpose			:	Whenever you wanna open a link into a new window just call this function
//								you need to pass some arguemnts as described below.
//	Parameters		:	
//								url  = url to be open in the new window
//								winname = winname is the window name for the reference of that window
//								w is the width
//								h is the height
//								menu is the parameter, if you want menubar to be enabled on the window
//								resize if you wanna resize the window
//								scroll i fyou needed
//								x and y are the co-ordinates where you wld like to show the window on the screen
//	Return			:	true or false
//	Author			:	Nirmal Patel
//	Creation Date	:	05-May-2003
//----------------------------------------------------------------------------------------------------

function popupWindowURL(url, winname,  w, h, menu, resize, scroll, x, y) {
	
	if (winname == null) winname = "newWindow";
	if (w == null) w = 600;
	if (h == null) h = 600;
	if (resize == null) resize = 1;
	
	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";
	if (menu) menutype = "menubar";
	if (resize) resizetype = "resizable";
	if (scroll) scrolltype = "scrollbars";
	
	if (x == null || y == null) {
		cwin=window.open(url,winname,"status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);
	}
	else {
		cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);
	}
	if (!cwin.opener) cwin.opener=self;
	cwin.focus();
	
	return true;
}

function formatNumber(pnumber,decimals) 
{  
	if (isNaN(pnumber)) { return 0};  
	if (pnumber=='') { return 0};  
	
	var IsNegative=(parseInt(pnumber)<0); 
	if(IsNegative)pnumber=-pnumber; 
	
	var snum = new String(pnumber);  
	var sec = snum.split('.');  
	var whole = parseInt(sec[0]);  
	var result = '';  
	if(sec.length > 1){  
		var dec = new String(sec[1]);  
		dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimals-1)); 
		Math.round(dec); 
		dec = parseInt(dec)/10; 

		if(IsNegative) 
		{ 
		  var x = 0-dec; 
		      x = Math.round(x); 
		  dec = - x; 
		} 
		else 
		{ 
		      dec = Math.round(dec); 
		} 

		/* 
		 * If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
		 * then we need to add 1 to the 'whole' and set the dec to 0. 
		 */ 
		if(dec==Math.pow(10, parseInt(decimals)))
		{ 
		  whole+=1; 
		  dec="0"; 
		} 

	    dec = String(whole) + "." + String(dec);  
	    var dot = dec.indexOf('.');  
	    if(dot == -1){  
	      dec += '.';  
	      dot = dec.indexOf('.');  
	    } 
		var l=parseInt(dot)+parseInt(decimals); 
	    while(dec.length <= l) { dec += '0'; }  
    	result = dec;
  } else{  
    var dot;  
    var dec = new String(whole);  
    dec += '.';  
    dot = dec.indexOf('.');  
	var l=parseInt(dot)+parseInt(decimals); 
    while(dec.length <= l) { dec += '0'; }  
    result = dec;  
  }  
  if(IsNegative)result="-"+result; 
  return result;  
}

//====================================================================================================
//	Function Name	:	change_state_list
//	Purpose			:	Provide the functionality for record selection
//	Return			:	None
//	Author			:	Dinesh Sailor
//	Creation Date	:	18-July-2003
//----------------------------------------------------------------------------------------------------
function change_state_list(frm,lstcountry,stateSel,state_combo_name,state_text)
{
	cat = lstcountry.options[lstcountry.selectedIndex].value;
	with(frm)
	{
		for(i=0; i<arrState.length; i++)
		{
			if(arrState[i][0] == cat)	break;
		}
	
		if(i!=arrState.length)
		{
			state_combo_name.disabled=false;
			state_text.disabled=true;
			state_combo_name.length = 1;
			for(j=1; j<arrState[i].length; j+=3)
			{
				state_combo_name.length++;
				state_combo_name[state_combo_name.length-1].value = arrState[i][j];
				state_combo_name[state_combo_name.length-1].text = arrState[i][j+1];
				if(stateSel == arrState[i][j])
				{
					state_combo_name[state_combo_name.length-1].selected = true;
				}
			}
	
		}
		else
		{
			state_combo_name.length = 1;
			state_combo_name.disabled=true;
			state_text.disabled=false;
		}
		
	}
}

