
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


/*
function isInteger(value) {
  return (parseInt(value) == value);
}
*/

var numDays = {
                '1': 31, '2': 28, '3': 31, '4': 30, '5': 31, '6': 30, 
                '7': 31, '8': 31, '9': 30, '10': 31, '11': 30, '12': 31
              }; 

function setDays(oMonthSel, oDaysSel, oYearSel)
{ 
	var nDays, oDaysSelLgth, opt, i = 1; 
	nDays = numDays[oMonthSel[oMonthSel.selectedIndex].value]; 
	if (nDays == 28 && oYearSel[oYearSel.selectedIndex].value % 4 == 0) 
		++nDays; 
	oDaysSelLgth = oDaysSel.length; 
	if (nDays != oDaysSelLgth)
	{ 
		if (nDays < oDaysSelLgth) 
			oDaysSel.length = nDays; 
		else for (i; i < nDays - oDaysSelLgth + 1; i++)
		{ 
			opt = new Option(oDaysSelLgth + i, oDaysSelLgth + i); 
			oDaysSel.options[oDaysSel.length] = opt;
		} 
	} 
} 

function isInteger(myString) {
    var isInteger = new Boolean()
    isInteger=true
    var myChar=""
    var myInt=0

    if (myString!="" && typeof(myString)=="string") {
        for (i=0;i<myString.length;i++) {
            myChar=myString.charAt(i)
            myInt=parseInt(myChar)

            if (isNaN(myInt)) {
                isInteger=false;
            }
        }

    } else {
        isInteger=false;
    }

    return isInteger;
}


function profileFormValidator(theForm){

	if( theForm.name.value =="" || isSpaces(theForm.name.value) ){
	alert("Please type name");
	theForm.name.focus();
	return false;	
	}
	
	if( theForm.profession.value =="" || isSpaces(theForm.profession.value) ){
	alert("Please type profession");
	theForm.profession.focus();
	return false;	
	}

	if( theForm.postalAddress.value =="" || isSpaces(theForm.postalAddress.value) ){
	alert("Please type Postal Address");
	theForm.postalAddress.focus();
	return false;	
	}  

	if( theForm.city.value =="" || isSpaces(theForm.city.value) ){
	alert("Please type city");
	theForm.city.focus();
	return false;	
	}  
	
	if(theForm.country.options.selectedIndex==0){
	alert("Please select a country");
	theForm.country.focus();
	return false;	
	}  
	
	if( !validEmail(theForm.email))
		return false;

	if(theForm.category.options.selectedIndex==0){
	alert("Please select a category");
	theForm.category.focus();
	return false;	
	}  	

	if( theForm.telephoneNumber.value =="" || isSpaces(theForm.telephoneNumber.value) ){
	alert("Please type Telephone Number");
	theForm.telephoneNumber.focus();
	return false;	
	}  	

	if( theForm.description.value =="" || isSpaces(theForm.description.value) ){
	alert("Please type description");
	theForm.description.focus();
	return false;	
	}  


//  theForm.submit();
}

function complaintFormValidator(theForm){

	if( theForm.name.value =="" || isSpaces(theForm.name.value) ){
	alert("Please type name");
	theForm.name.focus();
	return false;	
	}
	if( !validEmail(theForm.email))
		return false;
		
	if( theForm.contactNumber.value =="" || isSpaces(theForm.contactNumber.value) ){
	alert("Please type Contact Number");
	theForm.contactNumber.focus();
	return false;	
	}

	if( theForm.description.value =="" || isSpaces(theForm.description.value) ){
	alert("Please type your problem");
	theForm.description.focus();
	return false;	
	}

	complaintPopUp();		
//  theForm.submit();
}

function requestFormValidator(theForm)
{
	if( theForm.name.value =="" || isSpaces(theForm.name.value) )
	{
		alert("Please type name");
		theForm.name.focus();
		return false;	
	}
	if( theForm.profession.value =="" || isSpaces(theForm.profession.value) ){
	alert("Please type profession");
	theForm.profession.focus();
	return false;	
	}

	if( theForm.age.value =="" || isSpaces(theForm.age.value) ){
	alert("Please type age");
	theForm.age.focus();
	return false;	
	}

	if(!(isInteger(theForm.age.value)))
	{
	alert("Please type an integer value for age");
	theForm.age.focus();
	return false;	
	
	}

	if( theForm.postalAddress.value =="" || isSpaces(theForm.postalAddress.value) ){
	alert("Please type Postal Address");
	theForm.postalAddress.focus();
	return false;	
	}  

	if( theForm.contactNumber.value =="" || isSpaces(theForm.contactNumber.value) ){
	alert("Please type Contact Number");
	theForm.contactNumber.focus();
	return false;	
	}  
	
	if( !validEmail(theForm.email))
		return false;
	requestPopUp();
}

function referFormValidator(theForm)
{
	if( theForm.visitorName.value =="" || isSpaces(theForm.visitorName.value) )
	{
		alert("Please type your name");
		theForm.visitorName.focus();
		return false;	
	}
	
	if( !validEmail(theForm.visitorEmail))
		return false;
	
	if( theForm.visitorContactNumber.value =="" || isSpaces(theForm.visitorContactNumber.value) )
	{
		alert("Please type your contact number");
		theForm.visitorContactNumber.focus();
		return false;	
	}

	if( theForm.friendName.value =="" || isSpaces(theForm.friendName.value) )
	{
		alert("Please type your friend's name");
		theForm.friendName.focus();
		return false;	
	}
	
	if( !validEmail(theForm.friendEmail))
		return false;
	
	if( theForm.friendContactNumber.value =="" || isSpaces(theForm.friendContactNumber.value) )
	{
		alert("Please type your friend's contact number");
		theForm.friendContactNumber.focus();
		return false;	
	}

	if( theForm.achievement.value =="" || isSpaces(theForm.achievement.value) )
	{
		alert("Please type your friend's achievement");
		theForm.achievement.focus();
		return false;	
	}
	
	referPopUp();
}

function reqEmailFormValidator(theForm)
{
	valid = true;
	if( theForm.visitorName.value =="" || isSpaces(theForm.visitorName.value) )
	{
		alert("Please type your name");
		theForm.visitorName.focus();
		return false;	
	}
	
	if( !validEmail(theForm.visitorEmail))
		return false;
	
	if( theForm.visitorContactNumber.value =="" || isSpaces(theForm.visitorContactNumber.value) )
	{
		alert("Please type your contact number");
		theForm.visitorContactNumber.focus();
		return false;	
	}

	if( theForm.visitorUsername.value =="" || isSpaces(theForm.visitorUsername.value) )
	{
		alert("Please type the username you want for your account");
		theForm.visitorUsername.focus();
		return false;	
	}

	if (theForm.visitorPassword.value == "")
	{
		alert("Please type a password for this account (6-8 characters)");
		theForm.visitorPassword.focus();
		return false;
	}
	
	theForm.submit();
	//reqEmailPopUp();
	//return true;
}

function contactFormValidator(theForm)
{
	valid = true;
	if( theForm.fullname.value =="" || isSpaces(theForm.fullname.value) )
	{
		alert("Please type your name");
		theForm.fullname.focus();
		return false;	
	}
	
	if( !validEmail(theForm.email))
		return false;

	if( theForm.mesg.value =="" || isSpaces(theForm.mesg.value) )
	{
		alert("Please type your message");
		theForm.mesg.focus();
		return false;	
	}
	
	theForm.submit();
	//reqEmailPopUp();
	//return true;
}

function isInt(){
if (event.keyCode < 45 || event.keyCode > 57)
 event.returnValue = false;
}

function validEmail(formField){
  var result = true;
  
  if(formField.value == "")
  {
    alert("Please type \"Email Address\"");
    formField.focus();
    result = false;
  }
  
  if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )  {
    alert("Please type a complete email address in the form: yourname@yourdomain.com");
    formField.focus();
    result = false;
  }
  return result;
}


function isSpChar1(str){
	for (i=0; i <  str.length; i++) 
	{
		var ch = str.substring(i,i+1)
	if ( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && (ch  != "_" )) {
     //		alert("Special characters are not allowed")
     		return false;
     	}
	}
	return true;
}

function isSpChar(str){
	for (i=0; i <  str.length; i++) 
	{
		var ch = str.substring(i,i+1)
		if ( ch == " " ) 	{
     		alert("No Spaces allowed")
    		return false
    	}
	if ( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && (ch  != "_" )) {
     		alert("Special characters are not allowed")
     		return false
     	}
	}
	return true;
}



function searchFormValidtor(theForm){
	 /*if( theForm.searchString.value =="" || isSpaces(theForm.searchString.value) ){
	  alert("Please type search keywords");
	  theForm.searchString.focus();
	  }
	  else{
      theForm.searchString.value = "";
	  theForm.submit();
	  }
	  return false;*/
	  theForm.submit();
}

function votePopUp(id)
{
	var newWindow=window.open("poll_results.jsp?pollId="+id, "rate", "resizable=no statusbar=no scrollbars=no HEIGHT=200 WIDTH=500 titlebar=no toolbar=no"); 
	newWindow.focus();
}

function resultPopUp(id)
{
	//funCall = "showPollResult("+id+")";
	setTimeout("",2000);
	var newWindow=window.open("poll_results1.jsp?pollId="+id, "rate", "resizable=no,statusbar=no,scrollbars=no,HEIGHT=200,WIDTH=500,titlebar=no,toolbar=no"); 
	newWindow.focus();
}

function showPollResult(id){
	//alert("POllId : "+id);
	var newWindow=window.open("poll_results1.jsp?pollId="+id, "rate", "resizable=no,statusbar=no,scrollbars=no,HEIGHT=200,WIDTH=500,titlebar=no,toolbar=no"); 
	newWindow.focus();
}

function changeVote(vote,pollId){
	/*voteLink = document.getElementById("voteLink");
	voteLink.href="maincontroller?requestId=6&pageId=1&vote="+vote+"&pollId="+pollId;*/
	voteLink = document.links["voteLink"];
	if(voteLink!=null){
		voteLink.href="maincontroller?requestId=6&pageId=1&vote="+vote+"&pollId="+pollId;
	}
	
}

function openCategories(id)
{
	document.forms[0].submit();
}

function referPopUp()
{
	var newWindow=window.open("referred_to_friend.jsp", "rate", "resizable=no statusbar=no scrollbars=no HEIGHT=100 WIDTH=500 titlebar=no toolbar=no"); 
	newWindow.focus();
}

function reqEmailPopUp()
{
	var newWindow=window.open("reqEmailDone.jsp", "rate", "resizable=no statusbar=no scrollbars=no HEIGHT=100 WIDTH=500 titlebar=no toolbar=no"); 
	newWindow.focus();
}

function requestPopUp()
{
	var newWindow=window.open("requested.jsp", "rate", "resizable=no,statusbar=no,scrollbars=no,HEIGHT=100,WIDTH=500,titlebar=no,toolbar=no"); 
	newWindow.focus();
}


function complaintPopUp()
{
	var newWindow=window.open("complaint_submitted.jsp", "rate", "resizable=no statusbar=no scrollbars=no HEIGHT=100 WIDTH=500 titlebar=no toolbar=no"); 
	newWindow.focus();
}

function advancedSearch()
{
	var newWindow=window.open("advanced_search.jsp", "rate", "resizable=no statusbar=no scrollbars=yes HEIGHT=250 WIDTH=500 titlebar=no toolbar=no"); 
	newWindow.focus();
}



function calcCharLeft(f, max)
{
	clipped = false;
	maxLength = max;
	
	if (f.value.length > maxLength) 
	{
		f.value = f.value.substring(0,maxLength);
		clipped = true;
	}
	return clipped;

}


function isEAddressAddr(EAddress){
  var result = false
  var theStr = new String(EAddress)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}


function FormValidator(theForm)
{

  if (theForm.EAddress.value == "")
  {
    alert("Please type \"EAddress\"");
    theForm.EAddress.focus();
    return (false);
  }

  if (!isEAddressAddr(theForm.EAddress.value))
  {
    alert("Please type a complete email address in the form: yourname@yourdomain.com");
    theForm.EAddress.focus();
    return (false);
  }
   
  if (theForm.EAddress.value.length < 3)
  {
    alert("Please type at least 3 characters in the \"EAddress\" field.");
    theForm.EAddress.focus();
    return (false);
  }
  return (true);
}



function validRequired(formField,fieldLabel)
{
  var result = true;
  
  if (formField.value == "")
  {
    alert('Please type"' + fieldLabel +'" field.');
    formField.focus();
    result = false;
  }
  
  return result;
}





function validCharacters(formField,fieldLabel,required) 
{
	var str = formField.value
	var slen = str.length
	for (i=0; i < slen; i++) 
	{
		var ch = str.substring(i,i+1)
		if ( ch == "" ) 
		{
    		alert ( "No Spaces are Permitted")
			formField.focus()
     		return false
    	}
		
		if ( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && ch != " ") 
		{
     		alert("Special characters are not allowed")
     		formField.focus()
     		return false
     	}
	}
	
	return true;
}




/**
*  main page form validator
**/

/**
-*/





/*******************/
function isEmailAddr(Email)
{
  var result = false;
  var theStr = new String(Email);
  var indexspace = theStr.indexOf(" ");
   if( indexspace >=0){
	return result;
	}
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
  result = true;
  }
  return result;
}

 function isSpaces(str){
  var spChar = " ";
  	for (i=0; i <  str.length; i++) 	{
		 var ch = str.substring(i,i+1)
		 if ( ch != " " ){
		   return false;	
		 }
     }
 	return true;	
 }






function emailAddValidator(theForm){
	 var maxNo = theForm.maxNo.value
	 var isFilled = false;	
	 for( var i= 0; i<maxNo; i++){
			 if( theForm.names[i].value !=""  || theForm.emails[i].value !="" ){
			   if( theForm.names[i].value == "" || isSpaces(theForm.names[i].value) ) {
			     alert("Please type first name");
			     theForm.names[i].focus();
			     return false;	
				}
			   if (!validEmail(theForm.emails[i]))
			 	 return false;
	  }// emd if  
	}// end for
	for( var i= 0; i<maxNo; i++)
	   if( theForm.names[i].value !=""  ){
	     isFilled = true;
		 break;
		 }
	 if( !isFilled){
	  alert("Please type atleast one value");
	  return false;
	 }
	 theForm.submit();
}

/* Refer to Friends Validation Ends Here*/