﻿// JScript File

    function languageredirect()
    {
        var language=document.getElementById("language");
        var lang=language.options[language.selectedIndex].value;
        if (lang !="")
        {
            window.open(lang,"_blank");
        }
        else
        {
            return false;
        }
    }
    
    function setnav1()
    {
        var num=0;
        var item;
        if (num=="0")
        {
            item=document.getElementById("MainNav_Nav1_0")
        }
        else
        {
            item=document.getElementById("MainNav_Nav1_" + num);
        
        }
        if (item !=null)
        {
            item.style.backgroundImage = "url('/images/nav_bg_down.gif')";
        }
    }
    
    function setnav1home()
    {
        var item=document.getElementById("MainNav_Nav1_0");
        item.style.backgroundImage = "url('/images/nav_bg_down.gif')";
    }
    
    function makeprintfriendlyversion() 
    { /*Capture actual content on web page*/ 
        if (window.location.href.indexOf("Search.aspx") > -1)
        {
            return alert("Sorry...search results are not printable with this function.");
        }
        var PrinterFriendlyVersionHTML = document.getElementById("contentDiv").innerHTML; 
        /*Open a new window to write acutal content to*/ 
        var PFVwindow = window.open("","PFVwindow","width=725,height=700,resizable=no,scrollbars=yes,toolbar=no,menubar=no,statusbar=no,location=no,directories=no"); 
       /*write conent to new window*/         
        PFVwindow.document.open(); 
        PFVwindow.document.write("<html><head>"); 
        /*write printing and formating styles for page*/ 
       PFVwindow.document.write("<link type='text/css' rel='stylesheet' href='/css/print.css' />"); 

        PFVwindow.document.write("<style type='text/css'>@media print {input,.DoNotPrint,{visibility: hidden;display:none;}} .DoNotPrint{visibility: hidden;display:none;}</style>"); 
        PFVwindow.document.write("</head><body><form><input type='button' value='Print Page' onClick='window.print();' /><input type='button' value='Close Window' onClick='window.close();' /></form>"); 
        PFVwindow.document.write(PrinterFriendlyVersionHTML); 
        PFVwindow.document.write("</body></html>"); 
        PFVwindow.document.close(); 
        /*return 1 for success*/ 
        //return 1; 
    }
    
    function sendtoafriend()
    {
        var link="link=" + escape(window.location.href);
        var safwindow=window.open("/SendToAFriend.aspx?" + link,"SAFWindow","width=600,height=400,resizeable=no,scrollbars=no,menubar=no,statusbar=no,location=no");
        safwindow.focus();
    }


function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('Email address is mandatory.');
   return false;
}
if (addr == '') return true;
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('Email address contains invalid characters.');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('Email address must contain an @.');
   return false;
}
if (atPos == 0) {
   if (db) alert('Email address must not start with @.');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('Email address must contain only one @.');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('Email address must contain a period in the domain name.');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('Period must not immediately follow @ in email address.');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('Period must not immediately precede @ in email address.');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('Two periods must not be adjacent in email address.');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('Invalid primary domain in email address.');
   return false;
}
return true;
}     

function submitenter(myfield,e,btn)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   var btn=document.getElementById(btn);
   if (btn==null)
   {
        btn=document.getElementById('Subscribe_ShorelinesSubscribeImageButton');
   }
   btn.click();
   //myfield.form.submit();
   e.returnValue=false;
   return false;
   }
else
   return true;
}

        	
function getElement(f,n){
    for (x=0;x<f.length;x++)
    {
		if (f[x].name.indexOf(n) >-1)
		{
			return f[x];
			break;
		}
    }
}
        
	        
function validateAmount(amount){
	if(amount.value.match( /^[0-9]+(\.([0-9]+))?$/)){
		return true;
	}else{
		alert('You must enter a valid donation.');
		amount.focus();
		return false;
	}
}

function sendDonation(f)
{
    if (validateAmount(f.item_price_1))
    {
        f.action="https://checkout.google.com/cws/v2/Donations/553691776101463/checkoutForm";
        f.target="checkout";
        f.submit();
    }
    else
    {
        return false;
    }
}       
	        
	        


       

        