function pollresults(pollid)
{
	var newwin=window.open("pollresults.asp?pollid=" + pollid,"pollresults", "width=800,height=600,location=0,menubar=0,personalbar=0,status=0,scrollbars=0,resizable=0,titlebar=0")
}
function removehref(id)
{
	document.getElementById(id).href=""
	//document.write('<a class="title red">RSS<img class="rss" src="graphics/feed-icon-16x16.gif" alt="RSS Feed" title="RSS Feed" /></a>')
}
function send2friendpage(page){
	var newwin=window.open(page + "?url=" + escape(document.location.href),"send2friend", "width=500,height=300,location=0,menubar=0,personalbar=0,status=0,scrollbars=0,resizable=0,titlebar=0")
}
function send2friendrequiredfield()
{
	var themessage = "You are required to complete the following fields: ";
	if (document.getElementById("friendsname").value=="")
	{
	themessage = themessage + " - Friend's Name";
	}
	if (document.getElementById("friendsemail").value=="")
	{
	themessage = themessage + " - Friend's Email";
	}
	if (document.getElementById("myname").value=="")
	{
	themessage = themessage + " - Your Name";
	}
	if (document.getElementById("myemail").value=="")
	{
	themessage = themessage + " - Your Email";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields: ")
	{
	return true;
	}
	else
	{
	alert(themessage);
	return false;
	}
}
function validatesend2friendform(action,form)
{
	if(send2friendrequiredfield() && emailCheck(document.getElementById('friendsemail').value,1) && emailCheck(document.getElementById('myemail').value,1))
	{
	document.getElementById(form).action=action
	document.getElementById(form).submit()
	}
	else
	{
	return false;
	}
}
function CreateBookmarkLink() {
	title=document.title
	url=document.location.href
	if (window.sidebar)
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if(window.external)
	{ // IE Favorite
		window.external.AddFavorite(url, title); 
	}
	else if(window.opera && window.print)
	{ // Opera Hotlist
		return true; 
	}
}
function checkNumber(e) {
var keycode
var numcheck

if(window.event) // IE
{
keycode = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keycode = e.which
}
if (keycode>=48 && keycode<=57 || keycode>=96 && keycode<=105 || keycode==8 || keycode==46 || keycode>=37 && keycode<=40) {
	return true;
  }
  else{
  return false
  }
}
function checkPrice(e,textx) {
var keycode
var keychar
var numcheck
textx=textx + "xxx"
if(window.event) // IE
{
keycode = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keycode = e.which
}
if (keycode>=48 && keycode<=57 || keycode>=96 && keycode<=105 || keycode==8 || keycode==46 || keycode==110 || keycode==190 || keycode>=37 && keycode<=40) {
	return true;
}
else{
	return false;
}   
}
function checkPriceproper(e,textx) {
var keycode
var keychar
var numcheck
textx=textx + "xxx"
if(window.event) // IE
{
keycode = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keycode = e.which
}
if (keycode>=48 && keycode<=57 || keycode>=96 && keycode<=105 || keycode==8 || keycode==46 || keycode>=37 && keycode<=40) {
	return true;
}
else{
	if (keycode==110 || keycode==190){
		if(textx.match(".")==null){
	  //  keychar = String.fromCharCode(keycode)
		return true;
		}
		else{
		return false;
		}
	}
	else{
		return false;
	}
}   
}
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(arpa|root|aero|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|travel|xxx)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).
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;
   }
}

// See if "user" is valid 
if (user.match(userPat)==null) {

// user is not valid
alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
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;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */
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;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
alert("This address is missing a hostname!");
return false;
}
// If we've gotten this far, everything's valid!
return true;
}
function rollover(buttonid,image){
document.getElementById(buttonid).src=image
}
function clearfield(fieldid)
{
	if (document.getElementById(fieldid).value==document.getElementById(fieldid).defaultValue)
	{
	document.getElementById(fieldid).value=""
	}
}
function unclearfield(fieldid,email)
{
	if (email)
	{
		if (document.getElementById(fieldid).value==""||document.getElementById(fieldid).value==document.getElementById(fieldid).defaultValue)
		{
		document.getElementById(fieldid).value=document.getElementById(fieldid).defaultValue
		}
		else
		{
		emailCheck(document.getElementById(fieldid).value)
		}
	}
	else
	{
		if (document.getElementById(fieldid).value=="")
		{
		document.getElementById(fieldid).value=document.getElementById(fieldid).defaultValue
		}
	}
}
function regrequiredfield() {
var themessage="";
if (document.getElementById("fname").value=="") {
themessage = themessage + " - First Name";
}
if (document.getElementById("lname").value=="") {
themessage = themessage + " - Last Name";
}
if (document.getElementById("usernamereg").value=="") {
themessage = themessage + " -  Username";
}
if (document.getElementById("email").value=="") {
themessage = themessage + " -  E-mail Address";
}
if (document.getElementById("passwordreg").value=="") {
themessage = themessage + " -  Password";
}
if (document.getElementById("passwordreg2").value=="") {
themessage = themessage + " -  Re-enter Password";
}
//alert if fields are empty and cancel form submit
if (themessage=="") {
return true;
}
else {
alert("You are required to complete the following fields: " + themessage);
return false;
   }
}
function lengthcheck(fieldlabel,usernamefield,usermin,usermax){
username=document.getElementById(usernamefield).value
if (username.length>=usermin && username.length<=usermax){
return true;
}
else{
alert(fieldlabel + " must be " + usermin + "-" + usermax + " characters long.")
return false;
}
}
function fieldmatch(fieldlabel,field1,field2){
field1=document.getElementById(field1).value
field2=document.getElementById(field2).value
if (field1==field2){
return true;
}
else{
alert(fieldlabel + " fields must be identical.")
return false;
}
}
function validateregform(action,form){
if(regrequiredfield() && emailCheck(document.getElementById('email').value) && lengthcheck("Username","usernamereg",8,20) && lengthcheck("Password","passwordreg",8,20) && fieldmatch("Password","passwordreg","passwordreg2")){
document.getElementById(form).action=action
document.getElementById(form).submit()
}
else{
return false;
}
}
function validateeditform(action,form){
if(editrequiredfield() && emailCheck(document.getElementById('email').value) && lengthcheck("Username","username",8,20)){
document.getElementById(form).action=action
document.getElementById(form).submit()
}
else{
return false;
}
}
function editrequiredfield() {
var themessage = "You are required to complete the following fields: ";
if (document.getElementById("fname").value=="") {
themessage = themessage + " - First Name";
}
if (document.getElementById("lname").value=="") {
themessage = themessage + " - Last Name";
}
if (document.getElementById("username").value=="") {
themessage = themessage + " -  User Name";
}
if (document.getElementById("email").value=="") {
themessage = themessage + " -  E-mail Address";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
return true;
}
else {
alert(themessage);
return false;
   }
}
function send2friendrequiredfield() {
var themessage = "You are required to complete the following fields: ";
if (document.getElementById("friendsname").value=="") {
themessage = themessage + " - Friend's Name";
}
if (document.getElementById("friendsemail").value=="") {
themessage = themessage + " - Friend's Email";
}
if (document.getElementById("myname").value=="") {
themessage = themessage + " - Your Name";
}
if (document.getElementById("myemail").value=="") {
themessage = themessage + " - Your Email";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
return true;
}
else {
alert(themessage);
return false;
   }
}
function validatesend2friendform()
{
	if(send2friendrequiredfield() && emailCheck(document.getElementById('friendsemail').value) && emailCheck(document.getElementById('myemail').value))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validatenewsletterform()
{
	if(newsletterrequiredfield() && emailCheck(document.getElementById('email').value))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function newsletterrequiredfield() {
var themessage = "You are required to complete the following fields: ";
if (document.getElementById("fname").value=="") {
themessage = themessage + " - First Name";
}
if (document.getElementById("lname").value=="") {
themessage = themessage + " - Last Name";
}
if (document.getElementById("email").value=="") {
themessage = themessage + " - Email Address";
}
if (document.getElementById("hdyhau").value=="") {
themessage = themessage + " - How did you hear about us?";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
return true;
}
else {
alert(themessage);
return false;
   }
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate() + expiredays)
document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			{
				return unescape(document.cookie.substring(c_start,c_end))
			}
		} 
	}
	return ""
}
function externalLinks()
{
	if(!document.getElementsByTagName)
	{
		return;
	}
	var anchors=document.getElementsByTagName("a");
	for(var i=0;i<anchors.length;i++)
	{
		var anchor=anchors[i];
		if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		{
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window)" : "opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
		}
	}
}
function init()
{
	externalLinks();
}

function calculate(carriageid)
{
	var total
	var desc
	total=0
	desc="E-BOOKS - "
	ebookids=""
	discount=true
	var firstitemadded="x"
	for (i=1;i<=document.getElementById("totalebooks").value;i++)
	{
		ebookid="ebookid" + i
		ebooktitle="ebooktitle" + i
		ebookprice="ebookprice" + i
		ebooktick="ebooktick" + i
		dbid=document.getElementById(ebookid).value
		if (document.getElementById(ebooktick).checked==true&&document.getElementById(ebooktick).disabled==false)
		{
			total=total + (document.getElementById(ebookprice).value*1)
			tocart=document.getElementById(ebooktitle).value
			if (firstitemadded=="x")
			{
				desc=desc + tocart
				ebookids=ebookids + dbid
				firstitemadded="y"
				//alert(tocart)
			}
			else
			{
				desc=desc + ", " + tocart
				ebookids=ebookids + "," + dbid
			}
		}
		else
		{
			discount=false
		}
	}
	total=Number(total)
	if (discount==true)
	{
		total=total*1
	}
	total=roundOff(total)
	if (total<=0)
	{
		total=0
	}
	document.getElementById("cost").value=total
	document.getElementById("cost2").value=total
	document.getElementById("desc").value=desc
	document.getElementById("ids").value=ebookids
}
function checkall(checkbox)
{
	checked=document.getElementById(checkbox).checked
	for (i=1;i<=document.getElementById("totalebooks").value-1;i++)
	{
		ebooktick="ebooktick" + i
		document.getElementById(ebooktick).checked=checked
	}
}
function disableall(checkbox)
{
	checked=document.getElementById(checkbox).checked
	for (i=1;i<=document.getElementById("totalebooks").value-1;i++)
	{
		ebooktick="ebooktick" + i
		if (checked==true)
		{
			document.getElementById(ebooktick).disabled=true
		}
		else
		{
			document.getElementById(ebooktick).disabled=false
		}
	}
}
function checkallcheck()
{
	checked=true
	for (i=1;i<=document.getElementById("totalebooks").value-1;i++)
	{
		ebooktick="ebooktick" + i
		if (document.getElementById(ebooktick).checked==false)
		{
			checked=false
		}
	}
	if (checked==true)
	{
		for (i=1;i<=document.getElementById("totalebooks").value-1;i++)
		{
			ebooktick="ebooktick" + i
			document.getElementById(ebooktick).disabled=true
		}			
		document.getElementById("ebooktick11").checked=checked
	}
	else
	{
		for (i=1;i<=document.getElementById("totalebooks").value-1;i++)
		{
			ebooktick="ebooktick" + i
			document.getElementById(ebooktick).disabled=false
		}			
		document.getElementById("ebooktick11").checked=checked
	}
}
function roundOff(value)
{
	if (value == 0)
	{
		return "0";
		exit;
	}
	precision = 2;
	value = "" + value //convert value to string
	precision = parseInt(precision);
	var whole = "" + Math.round(value * Math.pow(10, precision));
	var decPoint = whole.length - precision;
	if(decPoint != 0)
	{
		result = whole.substring(0, decPoint);
		result += ".";
		result += whole.substring(decPoint, whole.length);
	}
	else
	{
		result = whole;
	}
	return result;
}

function validatefreeebook()
{
	if(freeebookrequiredfield() && emailCheck(document.getElementById('e').value,1))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function freeebookrequiredfield()
{
	var themessage = "You are required to complete the following fields: ";
	if (document.getElementById("n").value=="")
	{
	themessage = themessage + " - Name";
	}
	if (document.getElementById("e").value=="")
	{
	themessage = themessage + " - Email address";
	}
	if (document.getElementById("hdyhau").value=="")
	{
	themessage = themessage + " - How did you hear about us?";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields: ")
	{
	return true;
	}
	else
	{
	alert(themessage);
	return false;
	}
}

function togglecheckbox(cbid)
{
	if (document.getElementById(cbid).checked==true)
	{
		document.getElementById(cbid).checked=false
	}
	else
	{
		document.getElementById(cbid).checked=true
	}
}