/*
 FILE: scripts/mainbodycontents.js

 ABSTRACT:
 
 This JavaScript is taken from http://javascript.internet.com and modified a bit to meet our requirements
 Here We can find Client Side validation Scripts (e.g. for email validation etc.

 DOCUMENTS:
 A reference to the applicable design documents.
 applicable to includes/mainbodycontents.inc.asp

 AUTHOR:
 Ranjan Shrestha

 CREATION DATE:
 2003/02/13

 NOTES:
 


 HISTORY:
 0001 - Feb 2003 - Ranjan Shrestha - Creation
 0001 - Feb 2003 - Ranjan Shrestha - Little bit modifications
 0001 - Apr 2003 - Ranjan Shrestha - Added Default starting date.
 0008 - Apr 2003 - Ranjan Shrestha = Modified scripts for populating End date(removed error)
*/
<!-- Begin
function EmailCheck (emailStr) {
if(emailStr != ""){ //this part is edited, so as to ignored validation if the email address is empty
	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	var emailPat=/^(.+)@(.+)$/;

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	var quotedUser="(\"[^\"]*\")";

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	var atom=validChars + '+';

	var word="(" + atom + "|" + quotedUser + ")";

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
	return false;
	   }
	}

	if (user.match(userPat)==null) {

	alert("The username doesn't seem to be valid.");
	return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}

	if (len<2) {
	alert("This address is missing a hostname!");
	return false;
	}
	return true;
	}
}


/////////////////////////////////////////////////
//================================================
//================================================
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

<!-- Original:  Ben McFarlin (mcfarlin@netscape.net) -->
<!-- Web Site:  http://sites.netscape.net/mcfarlin -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function populate(objForm,selectIndex) {
timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text, objForm.month.options[objForm.month.selectedIndex].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();
for (var i = 0; i < objForm.day.length; i++) {
objForm.day.options[0] = null;
}
for (var i = 0; i < daysInMonth; i++) {
objForm.day.options[i] = new Option(i+1);
}
document.FORM1.day.options[0].selected = true;
}

// extra script added
	var currentDate = new Date();
	
	
	function populateN(objForm) {
	timeA = new Date(currentDate.getYear(), currentDate.getMonth(),1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	for (var i = 0; i < objForm.day.length; i++) {
	objForm.day.options[0] = null;
	}
	for (var i = 0; i < daysInMonth; i++) {
	objForm.day.options[i] = new Option(i+1);
	}
	document.FORM1.day.options[0].selected = true;
	}
// end of extra script
function getYears() {

// You can easily customize what years can be used
var years = new Array(1997,1998,1999,2000,2001,2005)

for (var i = 0; i < document.FORM1.year.length; i++) {
document.FORM1.year.options[0] = null;
}
timeC = new Date();
currYear = timeC.getFullYear();
for (var i = 0; i < years.length; i++) {
document.FORM1.year.options[i] = new Option(years[i]);
}
document.FORM1.year.options[2].selected=true;
}
window.onLoad = getYears;

//////////////////////////////////////////////
function Epopulate(objForm,selectIndex) {


if((objForm.EYear.options[objForm.EYear.selectedIndex].text !="") && (objForm.EMonth.options[objForm.EMonth.selectedIndex].value != "")){
		timeA = new Date(objForm.EYear.options[objForm.EYear.selectedIndex].text, objForm.EMonth.options[objForm.EMonth.selectedIndex].value,1);
		timeDifference = timeA - 86400000;
		timeB = new Date(timeDifference);
		var daysInMonth = timeB.getDate();
		for (var i = 0; i < objForm.day.length; i++) {
		objForm.EDay.options[0] = null;
		}
		for (var i = 0; i < daysInMonth; i++) {
		objForm.EDay.options[i] = new Option(i+1);
		}
		document.FORM1.EDay.options[0].selected = true;
		}
	else {
		objForm.EDay.value=0;
	}

}
function EgetYears() {

// You can easily customize what years can be used
var years = new Array(1997,1998,1999,2000,2001,2005)

for (var i = 0; i < document.FORM1.EYear.length; i++) {
document.FORM1.EYear.options[0] = null;
}
timeC = new Date();
currYear = timeC.getFullYear();
for (var i = 0; i < years.length; i++) {
document.FORM1.EYear.options[i] = new Option(years[i]);
}
document.FORM1.EYear.options[2].selected=true;
}
window.onLoad = EgetYears;
//  End -->


function FORM1_onsubmit() {
if(FORM1.txtUrl.value =="http://" || FORM1.txtUrl.value ==""){
	alert("URL shouldn't be left empty !!");
	FORM1.txtUrl.value ="";
	FORM1.txtUrl.focus();
	FORM1.txtUrl.value ="http://"
	
	return false;
	}
	
// checking and removing "'" from each input field, which prevents update query for updating

FORM1.txtTitle.value = (FORM1.txtTitle.value).replace("'","^");	

FORM1.txtUrl.value = (FORM1.txtUrl.value).replace("'","^");	   

FORM1.txtCType.value = (FORM1.txtCType.value).replace("'","^");	   

FORM1.txtDescription.value = (FORM1.txtDescription.value).replace("'","^");	   

FORM1.txtFullName.value = (FORM1.txtFullName.value).replace("'","^");	   

FORM1.txtAddress.value = (FORM1.txtAddress.value).replace("'","^");	   

FORM1.txtZip.value = (FORM1.txtZip.value).replace("'","^");	   

FORM1.txtEmail.value = (FORM1.txtEmail.value).replace("'","^");


return EmailCheck(document.FORM1.txtEmail.value);
}


function optGame_onclick() {
	if(document.all){
		LayerGame.style.visibility ="visible";
		LayerCompetition.style.visibility="hidden";
		GameCompetitionType.innerText ="Spil type :";
		Description.innerText ="Beskriv spillet :";
	}
	if(!document.all && document.getElementById){
		document.getElementById("LayerGame").style.visibility="visible";
		document.getElementById("LayerCompetition").style.visibility="hidden";
		document.getElementById("GameCompetitionType").innerHTML ="Spil type :";
		document.getElementById("Description").innerHTML ="Beskriv spillet :";
	}
}

function optCompetition_onclick() {
	if(document.all){
		LayerCompetition.style.visibility="visible";
		LayerGame.style.visibility ="hidden";
		Description.innerText="Betingelser :";
		GameCompetitionType.innerText  ="Prĉmie(r) :";
	}
	if(!document.all && document.getElementById){
		document.getElementById("LayerGame").style.visibility="hidden";
		document.getElementById("LayerCompetition").style.visibility="visible";
		document.getElementById("GameCompetitionType").innerHTML ="Betingelser :";
		document.getElementById("Description").innerHTML ="Prĉmie(r) :";
	}
}

function chkEndDate_onclick() {
if (FORM1.chkEndDate.checked ==true) {
	FORM1.EDay.disabled=true;
	FORM1.EMonth.disabled=true;
	FORM1.EYear.disabled=true;
	}
else {
	FORM1.EDay.disabled=false;
	FORM1.EMonth.disabled=false;
	FORM1.EYear.disabled=false;
	}
}

