
function preprocessMainForm(frmobj)
{
	
	 //lstPredefined
   //rbtnKey
   //rbtnPre
   //txtkeyword1
   //txtkeyword2
   //ddandor
   var langcode=document.getElementById('lang').value;
   
   if(document.getElementById('rbtnPre').checked)
   {
   	 	if (document.getElementById('lstPredefined').options.selectedIndex==-1)
   	 	{
   	 		alert(g_str_error_01)
   	 		return false;
   	 	}
   }else if(document.getElementById('rbtnKey').checked)
   {
   	 	if 
   	 	(trimAll(document.getElementById('txtkeyword1').value)=='')
   	 	{
   	 		alert(g_str_error_02)
   	 		return false;
   	 	}

   	 	
   	 	var key1=trimAll(document.getElementById('txtkeyword1').value)
   	 	var key2=trimAll(document.getElementById('txtkeyword2').value)
   	 	
   	 	if((key1.length<3)&&(langcode=='ENG'))
   	 	{
   	 		alert(g_str_error_03)
   	 		return false;
   	 	}else if((key1.length<2)&&(langcode=='CHI'))
   	 	{
   	 		alert(g_str_error_03)
   	 		return false;
   	 	}
   	 	
   	 	if((key2!=null)&&(key2.length>0)&&(key2.length<3)&&(langcode=='ENG'))
   	 	{
   	 		alert(g_str_error_03)
   	 		return false;
   	 	}else if((key2!=null)&&(key2.length>0)&&(key2.length<2)&&(langcode=='CHI'))
   	 	{
   	 		alert(g_str_error_03)
   	 		return false;
   	 	}
   	 	
   }
   
	
	
	
	return true;
}
function checked_predefine_key()
{
	if(document.getElementById('rbtnPre')!=null)
	{
		
		if ((document.getElementById('rbtnKey').checked==true))
  	{
  		
  		document.getElementById('lstPredefined').disabled=true
  		
  		
   		document.getElementById('txtkeyword1').disabled=false
   		
   		
   		document.getElementById('txtkeyword2').disabled=false
   		
   		
   		document.getElementById('ddandor').disabled=false
   		
   		if(navigator.appName != "Netscape")
			{
   		document.getElementById('lstPredefined').style.backgroundColor = "#E0E0E0";
   		document.getElementById('txtkeyword1').style.backgroundColor = "#FFFFFF";
   		document.getElementById('txtkeyword2').style.backgroundColor = "#FFFFFF";
   		document.getElementById('ddandor').style.backgroundColor = "#FFFFFF";
   		}
   		
  	}else 
  		if((document.getElementById('rbtnPre').checked==true))
	   {
	   	document.getElementById('lstPredefined').disabled=false
	   	 
	   	 
	   	document.getElementById('txtkeyword1').disabled=true
	   	 
	   	 
	   	document.getElementById('txtkeyword2').disabled=true
	   	
	   	
	   	document.getElementById('ddandor').disabled=true
	   	
	   	
	   	
	   	if(navigator.appName != "Netscape")
			{
	   		document.getElementById('txtkeyword1').style.backgroundColor = "#E0E0E0";
	   		document.getElementById('txtkeyword2').style.backgroundColor = "#E0E0E0";
	   		document.getElementById('lstPredefined').style.backgroundColor = "#FFFFFF";
	   		document.getElementById('ddandor').style.backgroundColor = "#E0E0E0";
	  	}
	  }
  }
}

function setheadlinecat()
{
	document.getElementById('lstHeadlineCat').value=document.getElementById('lstPredefined').options[document.getElementById('lstPredefined').selectedIndex].text;
}

function focuslstbox()
{
  //if(document.getElementById('lstPredefined')!=null)
  //{
		//	document.getElementById('lstPredefined').focus();
	//}
}


function validateDateRangeToday(d1_prefix, d1_desc, frmobj)
{
	var arrd1 = new Array(3);
	var arrd2 = new Array(3);
	var d2_prefix = "txt_today";

	p_DateSelectBox1_d = frmobj[d1_prefix + "_d"];
	p_DateSelectBox1_m = frmobj[d1_prefix + "_m"];
	p_DateSelectBox1_y = frmobj[d1_prefix + "_y"];

	arrd1[0] = parseInt(p_DateSelectBox1_d.options[p_DateSelectBox1_d.selectedIndex].value, 10);
	arrd1[1] = parseInt(p_DateSelectBox1_m.options[p_DateSelectBox1_m.selectedIndex].value, 10);
	arrd1[2] = parseInt(p_DateSelectBox1_y.options[p_DateSelectBox1_y.selectedIndex].value, 10);

	arrd2[0] = parseInt(frmobj[d2_prefix + "_d"].value, 10);
	arrd2[1] = parseInt(frmobj[d2_prefix + "_m"].value, 10);
	arrd2[2] = parseInt(frmobj[d2_prefix + "_y"].value, 10);

	if (compareArray(arrd2, arrd1) < 0) {
		alert(g_str_error_06 + d1_desc + g_str_error_07);
		return false;
	}
	return true;
}

function validateDateRangeEqual(d1_prefix, d2_prefix, frmobj)
{
	var arrd1 = new Array(3);
	var arrd2 = new Array(3);

	p_DateSelectBox1_d = frmobj[d1_prefix + "_d"];
	p_DateSelectBox1_m = frmobj[d1_prefix + "_m"];
	p_DateSelectBox1_y = frmobj[d1_prefix + "_y"];

	arrd1[0] = parseInt(p_DateSelectBox1_d.options[p_DateSelectBox1_d.selectedIndex].value, 10);
	arrd1[1] = parseInt(p_DateSelectBox1_m.options[p_DateSelectBox1_m.selectedIndex].value, 10);
	arrd1[2] = parseInt(p_DateSelectBox1_y.options[p_DateSelectBox1_y.selectedIndex].value, 10);

	p_DateSelectBox2_d = frmobj[d2_prefix + "_d"];
	p_DateSelectBox2_m = frmobj[d2_prefix + "_m"];
	p_DateSelectBox2_y = frmobj[d2_prefix + "_y"];

	arrd2[0] = parseInt(p_DateSelectBox2_d.options[p_DateSelectBox2_d.selectedIndex].value, 10);
	arrd2[1] = parseInt(p_DateSelectBox2_m.options[p_DateSelectBox2_m.selectedIndex].value, 10);
	arrd2[2] = parseInt(p_DateSelectBox2_y.options[p_DateSelectBox2_y.selectedIndex].value, 10);

	if (compareArray(arrd2, arrd1) < 0) {
		alert(g_str_error_05);
		return false;
	}
	return true;
}

function compareArray(arrd1, arrd2)
{
	if ( arrd1[2] > arrd2[2] ) return 1;
	else if ( arrd1[2] < arrd2[2] ) return -1;

	if ( arrd1[1] > arrd2[1] ) return 1;
	else if ( arrd1[1] < arrd2[1] ) return -1;

	if ( arrd1[0] > arrd2[0] ) return 1;
	else if ( arrd1[0] < arrd2[0] ) return -1;
	else return 0;
}

function validateDate(d_prefix, d_desc, frmobj)
{
	var arrdate = new Array(3);

	p_DateSelectBox_d = frmobj[d_prefix + "_d"];
	p_DateSelectBox_m = frmobj[d_prefix + "_m"];
	p_DateSelectBox_y = frmobj[d_prefix + "_y"];

	arrdate[0] = parseInt(p_DateSelectBox_d.options[p_DateSelectBox_d.selectedIndex].value, 10);
	arrdate[1] = parseInt(p_DateSelectBox_m.options[p_DateSelectBox_m.selectedIndex].value, 10);
	arrdate[2] = parseInt(p_DateSelectBox_y.options[p_DateSelectBox_y.selectedIndex].value, 10);

	if (!isDateFormat(arrdate[0], arrdate[1], arrdate[2])) {
		alert( g_str_error_02 + d_desc + g_str_error_03);
		return false;
	}
	return true;
}

function isDateFormat(dd,mm,yyyy){
	// chk if standard date format, dd/mm/yyyy
	var febday, maxdd;
	febday = 28
	maxdd = 0
		
	if ((!isPosInteger(dd))||(!isPosInteger(mm))||(!isPosInteger(yyyy))) {
		return false;
	}
	if (yyyy ==0)
		return false;
	else {
		if ((yyyy % 4)==0) 
		{
			febday = 29 ;
		}
			
		if ((mm >= 13) || (mm <= 0))
		{		return false;
		}
		else {
			if (mm == 1)  
				maxdd = 31
			else if (mm == 2)  
				maxdd = febday
			else if (mm == 3)  
				maxdd = 31
			else if (mm == 4)  
				maxdd = 30
			else if (mm == 5)  
				maxdd = 31
			else if (mm == 6)  
				maxdd = 30
			else if (mm == 7)  
				maxdd = 31
			else if (mm == 8)  
				maxdd = 31
			else if (mm == 9)  
				maxdd = 30
			else if (mm == 10)  
				maxdd = 31
			else if (mm == 11)  
				maxdd = 30
			else if (mm == 12)  
				maxdd = 31
			if ((dd > maxdd) || (dd == 0)) return false;
		}
	}
	return true;
}

function isPosInteger( strVal ) {
	if(!(isInteger(strVal))) return false;
	else if(strVal<0) return false;
	else return true;
}

function isInteger( strVal ) {
	var bNum = isNumeric(strVal);
	if(bNum) {
		if(parseInt(strVal,10) != strVal) return false;
	}
	return bNum;
}

function isNumeric( strVal ) {
	if(isNaN( strVal * 1)) return false;
	else return true;
}

function getRadioButtonSelectedValue ( radioButton )
{
	var p_strButtonValue = "";
	for (p_intCounter = 0; p_intCounter < radioButton.length; p_intCounter ++ )
	{
		if (radioButton[p_intCounter].checked)
		{
			p_strButtonValue = radioButton[p_intCounter].value;
		}
	}
	return p_strButtonValue;
}

function monthDiff(d1_prefix, d2_prefix, frmobj)
{
	var arrd1 = new Array(3);
	var arrd2 = new Array(3);

	p_DateSelectBox1_d = frmobj[d1_prefix + "_d"];
	p_DateSelectBox1_m = frmobj[d1_prefix + "_m"];
	p_DateSelectBox1_y = frmobj[d1_prefix + "_y"];

	arrd1[0] = parseInt(p_DateSelectBox1_d.options[p_DateSelectBox1_d.selectedIndex].value, 10);
	arrd1[1] = parseInt(p_DateSelectBox1_m.options[p_DateSelectBox1_m.selectedIndex].value, 10);
	arrd1[2] = parseInt(p_DateSelectBox1_y.options[p_DateSelectBox1_y.selectedIndex].value, 10);

	p_DateSelectBox2_d = frmobj[d2_prefix + "_d"];
	p_DateSelectBox2_m = frmobj[d2_prefix + "_m"];
	p_DateSelectBox2_y = frmobj[d2_prefix + "_y"];

	arrd2[0] = parseInt(p_DateSelectBox2_d.options[p_DateSelectBox2_d.selectedIndex].value, 10);
	arrd2[1] = parseInt(p_DateSelectBox2_m.options[p_DateSelectBox2_m.selectedIndex].value, 10);
	arrd2[2] = parseInt(p_DateSelectBox2_y.options[p_DateSelectBox2_y.selectedIndex].value, 10);

	var monthCount1 = arrd1[1] + arrd1[2] * 12;
	var monthCount2 = arrd2[1] + arrd2[2] * 12;
	
	return (monthCount2 - monthCount1);
}

