//reloads the window if Nav4 resized
function MM_reloadPage(init) 
{  
  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 CountTextArea(areafield, countfield, maxLen)
{
	if (areafield.value.length > maxLen)
	{
		areafield.value = areafield.value.substring(0, maxLen);
		alertMesg = "You have exceeded the maximum number of characters. \n The character limit for this field is " + maxLen + ".";
		alert(alertMesg);
		countfield.value = 0;
	}
	else
	{
		countfield.value = maxLen - areafield.value.length;
	}
}

function addbookmark()
{
	var bookmarkurl="http://you.inq7.net/";
	var bookmarktitle="YOU";

	if (document.all) {
		window.external.AddFavorite(bookmarkurl,bookmarktitle)
	}
	else {
      alert("You are using Netscape. To bookmark our site, press Ctrl-D. Thank you!")
	}
}

function getdate()
{
	var isnMonths=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var isnDays= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
	today=new Date();
	hrs=today.getHours();
	min=today.getMinutes();
	sec=today.getSeconds();
	clckh=""+((hrs>12)?hrs-12:hrs);
	clckm=((min<10)?"0":"")+min;
	clcks=((sec<10)?"0":"")+sec;
	clck=(hrs>=12)?"p.m.":"a.m.";
	year=today.getYear(); 
	if(year<1000) 
	{
		year+=1900;
	}
	var curr_date = isnDays[today.getDay()]+", "+isnMonths[today.getMonth()]+" "+today.getDate()+", " + year;
	return(curr_date);
}

function vote_polls(f, poll_no)
{
	var answer = 0;
	if (f.radiobutton[0].checked == 1) 
	{ 
		answer = 1; 
	}
	else if (f.radiobutton[1].checked == 1) 
	{ 
		answer = 2; 
	}
	else if ((f.radiobutton[2]) && (f.radiobutton[2].checked == 1)) 
	{ 
		answer = 3; 
	}
	else if ((f.radiobutton[3]) && (f.radiobutton[3].checked == 1)) 
	{ 
		answer = 4; 
	}
	else if ((f.radiobutton[4]) && (f.radiobutton[4].checked == 1)) 
	{ 
		answer = 5; 
	}
	else 
	{ 
		answer = 0; 
	}

    if ((!f.email.value)) { //|| (f.email.value="your registered email")) {
        alert ("Your registered email address is required."); 
        return false;
    }

	if (answer == 0)
	{
		alert ("Please select an answer before voting in the polls!");
	}
	else
	{
		var winURL = "http://ruby.inq7.net/polls/gma7poll.php?vote=1&poll_no=" + poll_no + "&answer=" + answer + "&email=" + f.email.value; 
		var winName = "polls";
		var winFeatures = "height=300,width=320,resizable=yes";
		window.open(winURL,winName,winFeatures);
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function verify(f)
{
	var msg;
	var empty_fields = "";
	var errors = "";
	
	for (var i = 0; i < f.length; i++)
	{
		var e = f.elements[i];
		
		// only text areas will be checked... 
		// make sure to use default values for other types in your html code
		if ( ( (e.type == "text") || (e.type == "textarea") ) && !e.optional)
		{
			if ( (e.value == null) || (e.value == "") || isblank(e.value) || (e.value == e.default_val) )
			{
				// collect the blank fields in a string
				empty_fields += "\n     " + e.fieldname;
				continue;
			}
			
			if ( e.email )
			{
				if ( invalidemail(e.value) )
				{
					errors += " - The field \"" + e.fieldname + "\" is an invalid email address.";
					errors += "\n";
				}
				
				continue;
			}
			
 			if ( e.numeric || (e.min != null) || (e.max != null) )
			{
				// collect in a string erroneous inputs concerning numerical fields
				var v = parseFloat(e.value);
				if (isNaN(v) || 
				( (e.min != null) && (v < e.min) ) ||
				( (e.max != null) && (v > e.max) ) )
				{
					errors += " - The field \"" + e.fieldname + "\" must be a number";
					if (e.min != null)
				     		errors += " that is greater than " + e.min;
					if (e.max != null && e.min != null)
				     		errors += " and less than " + e.max;
					else if ( e.max != null)
				     		errors += " that is less than " + e.max;
					errors += ".\n";
				}
			}
		}
	}

	// everything's fine!
	if (!empty_fields && !errors) return true;

	msg = "_______________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_______________________________________\n\n";

	// output errors
	if (empty_fields)
	{
		msg += " - The following required field(s) are empty:"
	      		+ empty_fields + "\n";
		if (errors) 
	     		msg += "\n";
	}

	msg += errors;
	alert(msg);
	return false;
}

function PreloadImages(srcArray)
{
	if (!document.Preload_Image)
	{
		document.Preload_Image = new Array();
	}
	
	var imageArray = document.Preload_Image;
	var i = 0;
	var j = imageArray.length;
	for (i = 0; i < srcArray.length; i++)
	{
		imageArray[i] = new Image();
		imageArray[i].src = srcArray[i];
	}
}

function SwapImage(imagename, i)
{	
	if (!document.Orig_Image)
	{
		document.Orig_Image = new Array();
	}
	if (!document.Orig_Image[imagename])
	{
		document.Orig_Image[imagename] = new Image();
	}

	document.Orig_Image[imagename].src = document.images[imagename].src;
	
	document.images[imagename].src = document.Preload_Image[i].src;
}

function RestoreImage(imagename)
{
	if (!document.Orig_Image || !document.Orig_Image[imagename])
	{
		return false;
	}
	
	document.images[imagename].src = document.Orig_Image[imagename].src;
}

function select_Country(form, radio_num) {
  form.country[radio_num].checked = true;

  if (radio_num != 1)
  {
    form.province.options.selectedIndex = 0;
  }
  if (radio_num != 0)
  {
    form.state.options.selectedIndex = 0;
  }
  if (radio_num != 2)
  {
    form.others.options.selectedIndex = 0;
  }
}

function set_Others(form, radio_num, others_select) {
  var value = form.others[form.others.options.selectedIndex].value;
  form.country[radio_num].value = value;
}