/*
** common utility
** beta version
** created Chaiyanet
*/

function IsDefined(sValue)
{
	return (typeof(window[sValue]) == "undefined")?  false: true;
}
		
/*
** email util
*/
/* email address validator */
function ValidateEmailAddress(EmailAddress)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;     
	return (filter.test(EmailAddress))? true : false;

}

/*
** string util
*/
/* get array of string with delimited */
function StringArrayFromDelimiter(Delimiter, ArrayValue)
{
	var delim = Delimiter;
	var sValue = ArrayValue;
	var outValue = new Array();
	var isDelimiter = false;
	
	if(delim.length > 0)
	{
		if(sValue.length > 0)
		{
			outValue = ArrayValue.split(",");
			return outValue;		        
		}
	}
}

/* Remove whitespace from a string value */
function TrimSpaceFromString(field)
{
	field.value = (field.value).replace(/^\s*|\s*$/g,'');
}
/*
** form util
*/

function FormFieldNotNull(FieldType, FieldName)
{
	var fType = FieldType;
	var fName = FieldName;
	var entedValue = ""
	var flag = false
	
	switch (fType.toLowerCase())
	{
		case "textbox": 
			entedValue = eval("document.getElementById('"+ fName+ "').value");
			if(entedValue.length > 0 )
			{
				flag = true;
			}
		break;
	}
	
	return flag; 
}


/*
** window
*/
function NewWinPopWithID(ControlID,ControlID2,Page,WinOption)
{
	var winName = ""; //document.getElementById(Field1).value;	
	var url = Page + "?Control1="+ ControlID + "&Control2=" + ControlID2;
	
	var height = 380;
	var width = 370;
	var wintop = (screen.availHeight - height) / 2;
	var winleft = (screen.availWidth - width) / 2;
	var options = "dependent=yes,width=" + width + ",height=" + height + ",left=" + winleft + ",top=" + wintop + ",titlebar=yes";
	
	// IE          
	if (window.showModalDialog) 
	{   		
		retVal = window.open(url,"observer",options);
	} 
	// Firefox
	else 
	{
		if(options.length < 0)
		{
			options = "height=90,width=250,resizable=yes,modal=yes";
		}	
		retVal = window.open(Page + "?Control1="+ ControlID + "&Control2= " + ControlID2 + " &ControlVal=" + winName,"Popup Window",options);
		retVal.focus();            
	}                   
}

function ReverseString()
{
         //var originalString = document.getElementById('txtReverse').value;
         //var reversedString = Reverse(originalString);
        var queryStr = window.location.search.substring(1);         
        var ctlArray = queryStr.split("&"); 
        
		var ctl1 = ctrlArray[0];
		var ctl2 = ctrlArray[1];		
        var control = ctl1.split("=");
		var control2 = ctl2.split("=");
		 		 
         // IE
         if (window.showModalDialog)
         {              
              window.returnValue = "HelloText";
              window.close();
         }
         // to handle in Firefox
         else
         {
              if ((window.opener != null) && (!window.opener.closed)) 
              {               
                // Access the control.        
                window.opener.document.getElementById(ctr1[1]).value = document.getElementById("txtFname").value;
				window.opener.document.getElementById(ctr2[1]).value = document.getElementById("txtLname").value;
              }
              window.close();
         }
}
