function genDropDownMenu(myType, minValue, maxValue) {
	var output="";
	output+="<select size='1' name=\"" + myType + "\">\n";
	output+="<option>--Please select one--</option>\n";
	for (var i=minValue;i<=maxValue;i++) {
		output+="<option>"+i+"</option>";
	}
	output+="</select>";
	document.write(output);
}

function genSelectedDropDownMenu(myType, minValue, maxValue, mySelect) {
	//alert("here");
	var output="";
        output+="<select size='1' name=\"" + myType + "\">\n";
        output+="<option>--Please select one--</option>\n";
        for (var i=minValue;i<=maxValue;i++) {
		if (i==mySelect) {
			output+="<option selected>"+i+"</option>";
		}
		else {
                	output+="<option>"+i+"</option>";
		}
        }
        output+="</select>";
        document.write(output);
}

function deleteMe(myURL) {
	//alert(myURL);
	temp=confirm("Do you want to delete this entry?");
	if (temp==true) {
		window.open(myURL, "myWin", "height=100, width=100");
	}
}

function chkResearchManual() {
	//alert(arguments[0]);
	//For checking the required fields to be filled in for researchManualAddEntry.php
	obj=document.addEntry;
	if ((obj.section.selectedIndex == 0) && (!arguments[0])) {
		alert("Please select which section does this entry belong to.");
		obj.section.focus();
		return false;
	}
	if (obj.year.selectedIndex==0) {
		alert("Please select a year.");
		obj.year.focus();
		return false;
	}	
	if (obj.month.selectedIndex==0) {
		alert("Please select a month.");
		obj.month.focus();
		return false;
	}	
	if (obj.day.selectedIndex==0) {
		alert("Please select a day.");
		obj.day.focus();
		return false;
	}
	var temp=checkDate(obj.year.options[obj.year.selectedIndex].text, obj.month.options[obj.month.selectedIndex].text, obj.day.options[obj.day.selectedIndex].text);	
	if (temp==false) {
		return false;
	}
	if (obj.title.value=="") {
		alert("Please enter the title for this entry.");
		obj.title.focus();
		return false;
	}
	if (obj.description.value=="") {
		alert("Please enter a description for this entry.");
		obj.description.focus();
		return false;
	}
	return true;
}

function chkResearchManualUpload() {
	if (document.fileUpload.userfile.value=="") {
		alert("Please select a file to upload");
		return false;
	}
	return true;
}

function checkDate(year, month, day) {
	var myArrayYear=[2004,2008,2012,2016,2020,2024];
	var myArrayMonth=[2,4,6,9,11];
	var myArrayDay=[28,30,30,30,30];
	
	//for lipYear, 29th of Feb is allowed;
	for (var i=0;i<6;i++) {
		if ((myArrayYear[i]==year) && (month==2) && (day==29)) {
			return true;
		}
	}	

	for (i=0;i<5;i++) {
		if (myArrayMonth[i]==month) {
			if (day>myArrayDay[i]) {
				alert("Month "+ month + " cannot have " + day + " days");
				return false;
				break;
			}
		}
	}
	return true;

}

function chkUserAdd() {
	var obj=document.user;
	//the following fields are mandatory and have to be filled in
	if (obj.username.value=="") {
		alert("Please fill in Username.");
		obj.username.focus();
		return false;
	}
	if (obj.password.value=="") {
		alert("Please fill in Password.");
		obj.password.focus();
		return false;		
	}
	//check for expiry date's validity;
	if (obj.year.selectedIndex==0) {
                alert("Please select a year.");
                obj.year.focus();
                return false;
        }
        if (obj.month.selectedIndex==0) {
                alert("Please select a month.");
                obj.month.focus();
                return false;
        }
        if (obj.day.selectedIndex==0) {
                alert("Please select a day.");
                obj.day.focus();
                return false;
        }
	var temp=checkExpiry(obj.year.options[obj.year.selectedIndex].text, obj.month.options[obj.month.selectedIndex].text, obj.day.options[obj.day.selectedIndex].text);
	if (temp==false) {
		return false;
	}
	return true;

}

function checkExpiry(year, month, day) {
	//alert(year);	alert(month);	alert(day);
        var myArrayYear=[2004,2008,2012,2016,2020,2024];
        var myArrayMonth=[2,4,6,9,11];
        var myArrayDay=[28,30,30,30,30];
	
	if (arguments[3]!="userSearch") {
		//check for the date earlier than now();
		var now=new Date();
		now=new Date(now.getFullYear(), now.getMonth()+1, now.getDate());
		var myExpiry=new Date(year,month,day);
		//alert(now.getTime());
		//alert(myExpiry.getTime());
		if ((now.getTime()-myExpiry.getTime()) >= 0) {
			alert("The expiry date cannot be earlier than today.");
			return false;	
		}
	}

        //for leapYear, 29th of Feb is allowed;
        for (var i=0;i<6;i++) {
                if ((myArrayYear[i]==year) && (month==2) && (day==29)) {
                        return true;
                }
        }

        for (i=0;i<5;i++) {
                if (myArrayMonth[i]==month) {
                        if (day>myArrayDay[i]) {
                                alert("Month "+ month + " cannot have " + day + " days");
                                return false;
                                break;
                        }
                }
        }
        return true;
}

function chkUserSearch() {
	var obj=document.search;
	if ((obj.before.checked==true) || (obj.after.checked==true)) {
		//check for expiry date's validity;
        	if (obj.year.selectedIndex==0) {
                	alert("Please select a year.");
                	obj.year.focus();
                	return false;
        	}
        	if (obj.month.selectedIndex==0) {
                	alert("Please select a month.");
                	obj.month.focus();
                	return false;
        	}
        	if (obj.day.selectedIndex==0) {
                	alert("Please select a day.");
                	obj.day.focus();
                	return false;
        	}
		var temp=checkExpiry(obj.year.options[obj.year.selectedIndex].text, obj.month.options[obj.month.selectedIndex].text, obj.day.options[obj.day.selectedIndex].text,"userSearch");
	}
	return temp;
}

function myToogle(toChange) {
	var obj=document.search;
	if ((toChange=="before") && (obj.before.checked==true)) {
		obj.after.checked=false;
	}
	else if ((toChange=="after") && (obj.after.checked==true)) {
		obj.before.checked=false;
	}
}

function showDesc(id, table) {
  url="showDesc.php?id="+id+"&table="+table;
  window.open(url, "desc", "height=280, width=450, scrollbars=yes,resizable=yes");
}

function promptMe(day) {
  msg="You subscription will expire after " + day + " days.\n";
  msg=msg+ "Please contact us if you want to renew your subscription.";
  alert(msg);
}

function displayDate() {
	now=new Date();
	month=now.getMonth()+1;
	switch(month) {
    case 1:
      month="January"
      break;
    case 2:
      month="February"
      break;
    case 3:
      month="March"
      break;
    case 4:
      month="April"
      break;
    case 5:
      month="May"
      break;
    case 6:
      month="June"
      break;
    case 7:
      month="July"
      break;
    case 8:
      month="August"
      break;
    case 9:
      month="September"
      break;
    case 10:
      month="October"
      break; 
    case 11:
      month="November"
      break;
    case 12:
      month="December"
      break; 
	}
	go="Today: " + now.getDate() + " " + month + ", " + now.getFullYear();
	document.write(go);
}

function chkTechAlerts() {
	//alert(arguments[0]);
	//For checking the required fields to be filled in for techAlertsAddEntry.php
	obj=document.addEntry;
	
	if (obj.year.selectedIndex==0) {
		alert("Please select a year.");
		obj.year.focus();
		return false;
	}	
	if (obj.month.selectedIndex==0) {
		alert("Please select a month.");
		obj.month.focus();
		return false;
	}	
	if (obj.day.selectedIndex==0) {
		alert("Please select a day.");
		obj.day.focus();
		return false;
	}
	if (obj.hour.selectedIndex==0) {
		alert("Please select an hour.");
		obj.hour.focus();
		return false;
	}
	if (obj.minute.selectedIndex==0) {
		alert("Please select a minute.");
		obj.minute.focus();
		return false;
	}
	var temp=checkDate(obj.year.options[obj.year.selectedIndex].text, obj.month.options[obj.month.selectedIndex].text, obj.day.options[obj.day.selectedIndex].text);	
	if (temp==false) {
		return false;
	}
	if (obj.title.value=="") {
		alert("Please enter the title for this entry.");
		obj.title.focus();
		return false;
	}
	if (obj.description.value=="") {
		alert("Please enter a description for this entry.");
		obj.description.focus();
		return false;
	}
	return true;
}

function displayNav() {
  
  var output='<table border="0" cellpadding="0" cellspacing="0" width="170">\
                    <tr>\
                      <td><img border="0" src="../image/menu_title.gif" width="171" height="30"></td>\
                    </tr>\
					<table border="0" cellpadding="2" cellspacing="0" width="167">\
                        <tr>\
     <td width="157" align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../index.php">Home</a></b></font></td>\
                          <td width="6"><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                        </tr>\
                        <tr>\
     <td align="right" colspan="2"><p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></p></td>\
                        </tr>\
                        <tr>\
<td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../profile/index.html">Company Profile</a></b></font></td>\
                          <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                        </tr>\
                        <tr>\
<td align="right" colspan="2"><p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td>\
                        </tr>\
                        <tr>\
<td align="right"><b><font size="2" face="Verdana" color="#808080"><a href="../asset/index.html"><strong>Asset Management</strong></a>\
</font></b></td>\
                          <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                        </tr>\
                        <tr>\
   <td align="right" colspan="2"><p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td>\
                        </tr>\
                        <tr>\
       <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../research/index.html"><strong>Research Advisory</strong></a>\
	   </b></font></td>\
                          <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                        </tr>\
                        <tr>\
   <td align="right" colspan="2"><p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td>\
                        </tr>\
                        <tr>\
        <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../user/userLogin.php"><strong>Tempus Library</strong></a>\
		</b></font></td>\
                          <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                        </tr>\
                        <tr>\
             <td align="right" colspan="2"><p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td>\
                        </tr>\
                        <tr>\
   <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../contact/index.html">Contact Us</a></b></font></td>\
                          <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                        </tr>\
                        <tr>\
<td align="right" colspan="2"><p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td>\
                        </tr>\
                    </table>';
  
  
  var output2='<table border="0" cellpadding="0" cellspacing="0" width="170">\
                    <tr>\
                      <td><img border="0" src="../image/menu_title.gif" width="171" height="30"></td>\
                    </tr>\
                    <tr>\
                      <td height="25" align="right">\
                        <table border="0" cellpadding="2" cellspacing="0" width="167">\
                          <tr>\
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../index.php">Home</a></b></font></td>\
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                          </tr>\
                          <tr>\
                            <td align="right" colspan="2">\
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></p>\
                            </td>\
                          </tr>\
                          <tr>\
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../profile/index.html">Company \
                              Profile</a></b></font></td>\
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                          </tr>\
                          <tr>\
                            <td align="right" colspan="2">\
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td>\
                          </tr>\
                          <tr>\
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../approach/index.html">Our Approach</a></b></font></td>\
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td>\
                          </tr>\
                          <tr>\
                            <td align="right" colspan="2">\
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td>\
                          </tr>\
                          <tr>\
                            <td align="right"><b><font size="2" face="Verdana" color="#808080"><a href="../services/index.html">Our Services</a></font></b></td> \
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td> \
                          </tr> \
                          <tr> \
                            <td align="right" colspan="2"> \
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td> \
                          </tr> \
                          <tr> \
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../subscription/index.html">Subscription</a></b></font></td> \
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td> \
                          </tr> \
                          <tr> \
                            <td align="right" colspan="2"> \
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td> \
                          </tr> \
                          <tr> \
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../user/userLogin.php">Research Library\
                              </a></b></font></td> \
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td> \
                          </tr> \
                          <tr> \
                            <td align="right" colspan="2"> \
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td> \
                          </tr> \
                          <tr> \
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../user/userLogin.php?goto=keyIndices">Key Indices\
                              </a></b></font></td> \
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td> \
                          </tr> \
                          <tr> \
                            <td align="right" colspan="2"> \
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td> \
                          </tr> \
                          <tr> \
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../user/userLogin.php?goto=stocks">Key Stocks\
                              </a></b></font></td> \
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td> \
                          </tr> \
                          <tr> \
                            <td align="right" colspan="2"> \
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td> \
                          </tr> \
                          <tr> \
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../links/index.html">Important  \
                              Links</a></b></font></td> \
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td> \
                          </tr> \
                          <tr> \
                            <td align="right" colspan="2"> \
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td> \
                          </tr> \
                          <tr> \
                            <td align="right"><font size="2" face="Verdana" color="#808080"><b><a href="../contact/index.html">Contact  \
                              Us</a></b></font></td> \
                            <td><img border="0" src="../image/btn_square.gif" width="6" height="6"></td> \
                          </tr> \
                          <tr> \
                            <td align="right" colspan="2"> \
                              <p align="left"><img border="0" src="../image/btn_line.gif" width="167" height="1"></td> \
                          </tr> \
                        </table> \
                      </td> \
                    </tr> \
                  </table>';
  document.write(output);
}

function openMe(url) {
  window.open(url, "myWin", "height=600, width=590, scrollbars=yes, resizable=yes, toolbar=yes");
}

function checkSubscription() {
  obj=document.subscribe;
  
  if (obj.subscription[1].checked==true) {
    if ((obj.asiaChartline.checked==false) && (obj.countryReports.checked==false) && (obj.trendScreens.checked==false) && (obj.specialReports.checked==false)) {
      alert("Please at least select one category in the subscription types");
      return false; 
    }
  }
  if (obj.firstname.value=="") {
    alert("Please let us know your first name.");
    obj.firstname.focus();
    return false; 
  } 
  if (obj.lastname.value=="") {
    alert("Please let us know your last name.");
    obj.lastname.focus();
    return false; 
  }
  if (obj.email.value=="") {
    alert("Please let us know your email address.");
    obj.email.focus();
    return false; 
  }
  if (obj.phone.value=="") {
    alert("Please let us know your phone number.");
    obj.phone.focus();
    return false; 
  }
  //alert("Thank you for your subscription.");
  return true;
  
  
}

function checkSubscriptionDetails() {
  if (document.subscriptionDetails.added.value=="yes") {
    alert("User already created, cannot add again");
    return false;
  }
  if (document.subscriptionDetails.username.value=="") {
    alert("You need to enter an username in order to create this user");
    return false;
  }
  
  //work on TODAY
  var today=new Date();
  tempFlag=0;
  if (document.subscriptionDetails.status[1].checked==true) {
    tempFlag=1;
    document.subscriptionDetails.year.value=today.getFullYear();
    document.subscriptionDetails.month.value=today.getMonth()+2;
    tempMonth=today.getMonth()+2;
    if (tempMonth==13) {
      tempMonth=1;
    }
    else if (tempMonth==14) {
      tempMonth=2; 
    }
  }
  else if (document.subscriptionDetails.status[2].checked==true){
    tempFlag=1;
    document.subscriptionDetails.year.value=today.getFullYear()+1;
    document.subscriptionDetails.month.value=today.getMonth()+1;
    tempMonth=today.getMonth()+1;
  }
  if (tempFlag==1) {
    var tempDate=today.getDate();
    if ((tempMonth==2) && (tempDate>28)) {
      tempDate=28;
    }
    else if (((tempMonth==2)||(tempMonth==4)||(tempMonth==6)||(tempMonth==9)||(tempMonth==11))&&(tempDate>30)) {
      tempDate=30;
    }
    document.subscriptionDetails.day.value=tempDate;
  }
  if (document.subscriptionDetails.status[0].checked) {
	  alert("Please select either trial or direct subscription.");
	  return false;	  
  }
  
  
  return true;
}

function changeSubsType() {
  //back=true;
	obj=document.subscribe;
	if (obj.subscription[0].checked==true) {
		obj.asiaChartline.checked=false;
		obj.asiaChartline.disabled=true;
		obj.countryReports.checked=false;
		obj.countryReports.disabled=true;
		obj.trendScreens.checked=false;
		obj.trendScreens.disabled=true;
		obj.specialReports.checked=false;
		obj.specialReports.disabled=true;
	}	
	else {
		obj.asiaChartline.disabled=false;
		obj.countryReports.disabled=false;
		obj.trendScreens.disabled=false;
		obj.specialReports.disabled=false;
	}
}

//added 20040802
function chkKeyIndex() {
	//alert(arguments[0]);
	//For checking the required fields to be filled in for techAlertsAddEntry.php
	obj=document.addEntry;
	
	if (obj.year.selectedIndex==0) {
		alert("Please select a year.");
		obj.year.focus();
		return false;
	}	
	if (obj.month.selectedIndex==0) {
		alert("Please select a month.");
		obj.month.focus();
		return false;
	}	
	if (obj.day.selectedIndex==0) {
		alert("Please select a day.");
		obj.day.focus();
		return false;
	}
	if (obj.hour.selectedIndex==0) {
		alert("Please select an hour.");
		obj.hour.focus();
		return false;
	}
	if (obj.minute.selectedIndex==0) {
		alert("Please select a minute.");
		obj.minute.focus();
		return false;
	}
	var temp=checkDate(obj.year.options[obj.year.selectedIndex].text, obj.month.options[obj.month.selectedIndex].text, obj.day.options[obj.day.selectedIndex].text);	
	if (temp==false) {
		return false;
	}
	if (obj.title.value=="") {
		alert("Please enter the title for this entry.");
		obj.title.focus();
		return false;
	}
	if (obj.description.value=="") {
		alert("Please enter a description for this entry.");
		obj.description.focus();
		return false;
	}
	if (obj.userfile.value=="") {
  	alert("Please upload a file for this entry.");
		obj.userfile.focus();
		return false;
	}
	return true;
}

function chkKeyIndexModify() {
	//alert(arguments[0]);
	//For checking the required fields to be filled in for techAlertsAddEntry.php
	obj=document.addEntry;
	
	if (obj.year.selectedIndex==0) {
		alert("Please select a year.");
		obj.year.focus();
		return false;
	}	
	if (obj.month.selectedIndex==0) {
		alert("Please select a month.");
		obj.month.focus();
		return false;
	}	
	if (obj.day.selectedIndex==0) {
		alert("Please select a day.");
		obj.day.focus();
		return false;
	}
	if (obj.hour.selectedIndex==0) {
		alert("Please select an hour.");
		obj.hour.focus();
		return false;
	}
	if (obj.minute.selectedIndex==0) {
		alert("Please select a minute.");
		obj.minute.focus();
		return false;
	}
	var temp=checkDate(obj.year.options[obj.year.selectedIndex].text, obj.month.options[obj.month.selectedIndex].text, obj.day.options[obj.day.selectedIndex].text);	
	if (temp==false) {
		return false;
	}
	if (obj.title.value=="") {
		alert("Please enter the title for this entry.");
		obj.title.focus();
		return false;
	}
	if (obj.description.value=="") {
		alert("Please enter a description for this entry.");
		obj.description.focus();
		return false;
	}
	
	return true;
}

function checkAddMarket(obj) {
  //alert("here");
  //return false;
  if (obj.stockCode.value=="") {
    alert("Please enter the stock code for this entry.");
		obj.stockCode.focus();
		return false;   
  }
  if (obj.stockName.value=="") {
    alert("Please enter the stock name for this entry.");
		obj.stockCode.focus();
		return false;   
  }  
  
  if (obj.userfile.value=="") {
    alert("Please upload a file for this entry.");
		obj.userfile.focus();
		return false;   
  } 
  
  return true;
}