var nextpic = 10;
var lastpic = "0";

function ano() {
    //  alert(lastpic)

    document.getElementById("butt_ano").disabled = "disabled";
    document.getElementById("butt_ano").value = "Running...";
    document.getElementById("pic_" + lastpic).style.display = "none";
    document.getElementById("pic_" + nextpic).style.display = "";
    document.getElementById("bg_" + nextpic).style.backgroundColor = '#ffffcc';
    document.getElementById("bg_" + lastpic).style.backgroundColor = 'white';
    //document.getElementById("spn_popuptitle").innerHTML = document.getElementById("tdate_" + nextpic).value;

    lastpic = nextpic;
    nextpic -= 1;
    // alert(nextpic)
    // alert(nextpic)
    if (nextpic == -1) {
        //done exit
        // alert("d")
        nextpic = 9;
        document.getElementById("butt_ano").disabled = "";
        document.getElementById("butt_ano").value = "Animate";
        return false;

    }
    window.setTimeout("ano()", 1500);
}
function MurderChildren(node) {
    if (node == null) return;
    if (!node.childNodes) return;
    while (node.childNodes.length >= 1) {
        node.removeChild(node.firstChild);
    }
}

function getObj(name) {
    if (document.getElementById) {
        return document.getElementById(name);
    }
    else if (document.all) {
        return document.all[name];
    }
    else if (document.layers) {
        return document.layers[name];
    }
}
function deletewindow() {
    grayOut(false);
   
    if (getObj("weather_48") == null) return;
    MurderChildren(getObj("weather_48"));
    document.body.removeChild(getObj("weather_48"));
}
function showonecloud(v) {

    if (document.getElementById("butt_ano").disabled) {
        alert("Please wait for Animation  to finish");
        return;
    }
    document.getElementById("pic_" + lastpic).style.display = "none";
    document.getElementById("pic_" + v).style.display = "";
    document.getElementById("bg_" + v).style.backgroundColor = '#ffffcc';
    document.getElementById("bg_" + lastpic).style.backgroundColor = 'white';
    lastpic = v;


}
function loadclouds() {
    grayOut(true);
    createwindow();
    document.getElementById("spn_popuptitle").innerHTML = "<B>Cloud activity for the  last 36 hours</b>";
    var weather_images = document.getElementById("weather_images").value;
    var weather_images_dates = document.getElementById("weather_images_dates").value;
    
    htm_main = "<table width=700 height=420  cellpadding=0 cellspacing=0 id=bgimage>"
    sp = weather_images.split(",")
    spdate = weather_images_dates.split(",")
    htm_main += "<tr><td valign=top id='td1' background='images/underlay.jpg' style=' width:600; height:420' >"
    //   alert(sp.length)
    for (i = 0; i <= sp.length; i++) {
        var hide = ""
        if (i > 0) {
            hide = "style='display:none'"
        } else {

         //   document.getElementById("spn_popuptitle").innerHTML = spdate[i]
        }
        htm_main += "<input type=hidden value='" + spdate[i] + "' id='tdate_" + i + "' /><img " + hide + "   id='pic_" + i + "' src='clouds.asp?ref=" + sp[i] + "' width=600 height=420>"
    }
    htm_main += "</td>"
    htm_main += "<td valign='top'  width=100 align=right><table width=100>"
    for (i = 0; i <= sp.length - 1; i++) {
        var hide = ""
        if (i > 0) {
            htm_main += "<tr><td  id='bg_" + i + "' style=' border-bottom:solid 1px gray; cursor:pointer;' onclick=\"showonecloud('" + i + "');\"><font size=2 color=navy>" + spdate[i] + "</font></td></tr>"
        } else {

            htm_main += "<tr><td id='bg_" + i + "' style='background-color:#ffffcc; border-bottom:solid 1px black ;cursor:pointer;' onclick=\"showonecloud('" + i + "');\"><font size=2 color=navy>" + spdate[i] + "</font></td></tr>"
        }


    }

    htm_main += "</table></td>"
    htm_main += "</tr><tr><td><input type='button' onclick='ano()' value='Animate' id='butt_ano' /></td></tr></table>"


    document.getElementById("spn_divpopup").innerHTML = htm_main;

}
function GetWindowSize(dimension) {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    if (dimension == "w") return myWidth;
    if (dimension == "h") return myHeight;
    return 0;
}
function createwindow() {

    vDiv = document.createElement("div");
    vDiv.id = "weather_48";
    document.body.appendChild(vDiv);
    vDiv.style.position = "absolute";
    vDiv.style.width = 700;
    vDiv.style.height = 500;
    vDiv.style.background = "white";
    vDiv.style.zIndex = 1000;
    vDiv.style.border = "2px solid black";
    vDiv.style.left = GetWindowSize("w") / 2 - 350;
    //vDiv.style.top = GetWindowSize("h")/2 - 250;
    vDiv.style.top = 60;

    vTable = document.createElement("table");
    vTable.width = 700;
    vTable.cellSpacing = 0;
    vTable.cellPadding = 8;
    vDiv.appendChild(vTable);
    vRow = vTable.insertRow(-1);
    vRow.height = 16;
    vCell = vRow.insertCell(-1);
    vCell.innerHTML = "<table><TR><Td width=500 align=center><span id='spn_popuptitle'></span></td><td width=200 align=right><span style='font-size:12px;'onclick=\"deletewindow();\" style='font-size:13px;color:blue;text-decoration:underline;cursor:pointer;'>Close This Window</span></td></tr></table>";
    vRow = vTable.insertRow(-1);
    vRow.style.height = "1px";
    vCell = vRow.insertCell(-1);
    vCell.style.background = "black";
    vRow = vTable.insertRow(-1);
    vCell = vRow.insertCell(-1);

    vCell.innerHTML = "<span id='spn_divpopup' style='font-size:13px;'>" + loadingtext + "</span>";






}


function Get_Cookie( check_name ) {

	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			 
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		
		return null;
	}
   
}
function sendcomments()
{
    var name = document.getElementById("comments_name").value    
    var email = document.getElementById("comments_email").value    
    var comments = document.getElementById("comments").value    
    
    makeRequest('emailcomments.asp?name=' + name + '&email=' + email + '&comments=' +comments ,'spncomments');
  
}
function showcomments(){
    var u = Get_Cookie('weather_user')
    grayOut(true);
    makeRequest('emailcomments.asp?user=' + u,'spncomments');
    document.getElementById('spncomments').style.display='';
}
function reset_windows()

{
    var screenW = 640, screenH = 480;
    if (parseInt(navigator.appVersion)>3) {
     //screenW = screen.width;
     screenH = screen.height;
     screenW = document.body.offsetWidth;
    }
    else if (navigator.appName == "Netscape" 
        && parseInt(navigator.appVersion)==3
        && navigator.javaEnabled()
       ) 
    {
     var jToolkit = java.awt.Toolkit.getDefaultToolkit();
     var jScreenSize = jToolkit.getScreenSize();
     screenW = jScreenSize.width;
     screenH = jScreenSize.height;
    }
    
    //daily emails span
    document.getElementById("spnemails").style.left=(screenW /2) - 250;
    
    //freedata
    document.getElementById("spnfreedata").style.left=(screenW /2) - 275;
    
    //data feed 
  //  document.getElementById("spndatafeed").style.left=(screenW /2) - 275;
    
    //contact us
    document.getElementById("spncontactus").style.left=(screenW /2) - 275;
    
    //closud
    document.getElementById("spnclouds").style.left=(screenW /2) - 250;
    
    //Login page
    document.getElementById("login_page").style.left=(screenW /2) - 200;
    
    //register
    document.getElementById("spnregister").style.left=(screenW /2) - 200;
    
    //gathering data
    document.getElementById("time_load").style.left=(screenW /2) - 150;
    document.getElementById("time_load").style.top=200;
    
    //48 hour forecast
    document.getElementById("d48").style.left=(screenW /2) - 300;
  //first page ad
    document.getElementById("bigmacad").style.left=(screenW /2) - 325;
    
    //first page ad
    document.getElementById("spnselecttowns").style.left=(screenW /2) - 200;
   
   
    sessiont_cookie= Get_Cookie('currentsession');
    if (sessiont_cookie != 'done'){
       
       //********* shows the big adddddddddd *****************************************
       //document.getElementById("bigmacad").style.display='';
     }  
   //  document.getElementById("time_load").style.display='none'
}

function bigad(){
    sessiont_cookie= Get_Cookie('currentsession');
    
    if (sessiont_cookie != 'done'){
        Set_Cookie('currentsession','done');
    //    grayOut(true);
       // document.getElementById("bigmacad").style.display='';
        
        
    }
}

function addbar(s){

 myJsProgressBarHandler.setPercentage('element1',s);
}
function resendauth()
{
    var u = document.getElementById("userid").value
    makeRequest('login.asp?email=' + u ,'logindetails')
}
function postlogin(){
    var t 
    var u = document.getElementById("userid").value
    var p = document.getElementById("passid").value
    document.getElementById("logindetails").style.display='none'
    document.getElementById('spnemails').style.display='none'
    
    makeRequest('login.asp?u=' + u +'&p='+ p,'logindetails')
    
    window.setTimeout("checklogin()", 2000);
   
}

function lostpassword()
{
    var err=0
    var emailaddr = document.getElementById("lostemailaddr").value 
    
        if ((emailaddr.indexOf('@')<2 ) || (emailaddr.indexOf('.')<4 )){
        err = 1
        document.getElementById("lostemailaddrerror").innerHTML = "<font color=red><i> incorrect </i></font>"
        }  
        if (err==0){
        makeRequest('lostpassword.asp?emailaddr=' + emailaddr ,'spnregister');
    }
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
   
}
function hideloginbuttons(){
        var u = Get_Cookie('weather_user')
        
        if ((u!='') && (u!= null)){
            document.getElementById("but_logout").style.display=''
            document.getElementById("but_register").style.display='none'
            document.getElementById("but_login").style.display='none'
            
        }else{
            document.getElementById("but_logout").style.display='none'
            document.getElementById("but_register").style.display=''
            document.getElementById("but_login").style.display=''
        
        }     
            
            

}

 function Delete_Cookie( name, path, domain ) {
    if ( Get_Cookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }

function logout()
    {
    Delete_Cookie('weather_user','/','')
    document.getElementById("but_logout").style.display='none'
    document.getElementById("but_register").style.display=''
    document.getElementById("but_login").style.display=''
    
}
function showmyweather(){
    
    var u = Get_Cookie('weather_user')
    
    if (u != null){
          // makeRequest('MyWeather.asp?user=' + u,'maindisplay')
           window.location.href = 'MyWeather.asp?user=' + u
         }else{
            grayOut(true);
            document.getElementById("spnmyweather").style.display='';   
         } 
    
    
}
function deleteweather(r)
{
    
 //   makeRequest('MyWeather.asp?delete='+r+'&user=' + Get_Cookie('weather_user'),'maindisplay')
    window.location.href = 'MyWeather.asp?delete='+r+'&user=' + Get_Cookie('weather_user')
}
function moveweather(r)
{
     
    //makeRequest('MyWeather.asp?order='+r+'&user=' + Get_Cookie('weather_user'),'maindisplay')
     window.location.href = 'MyWeather.asp?order='+r+'&user=' + Get_Cookie('weather_user')
    
}
function checklogin(){
    document.getElementById("logindetails").style.display=''
    var email = document.getElementById("userid").value
    var isIN = document.getElementById("logindetails").innerHTML
    if (isIN == 'Checking......'){
        
        
        Set_Cookie('weather_user',email,1000,'/','','')
        document.getElementById("logindetails").innerHTML = 'Nice... you have successfully  logged in, enjoy!'
        document.getElementById("hidelogintable").style.display='none'
        hideloginbuttons()
       // loadsavedloc()
    }else{
      //  alert('our')
    }
    
    
   // Set_Cookie('weather_user',
}
function showemailform(){
    var u = Get_Cookie('weather_user')
    grayOut(true);
    makeRequest('emails.asp?user=' + u,'spnemails');
    document.getElementById('spnemails').style.display='';
}
function updateemailtime()
{
    var u = Get_Cookie('weather_user')
    var t = document.getElementById("time").value
    makeRequest('emails.asp?time=' + t + '&user=' + u,'spnemails');
    document.getElementById('spnemails').style.display='';
}
function sendtestemail()
{
    var u = Get_Cookie('weather_user')
   
    makeRequest('emails.asp?testmails=1&user=' + u,'spnemails');
    document.getElementById('spnemails').style.display='';
    
}

function CheckRegistorForm(){

    var err =0
    document.getElementById("reqemail").innerHTML = ''
    document.getElementById("reqpassword").innerHTML =''
    document.getElementById("reqpasswordcom").innerHTML=''
    document.getElementById("reqfullname").innerHTML=''
    
    var email = document.getElementById("regemail").value
    var pass = document.getElementById("regpassword").value
    var compass = document.getElementById("regpasswordcom").value
    var fullname  =document.getElementById("regfullname").value
    
    var cell  =document.getElementById("regcell").value
    var town  =document.getElementById("regtown").value
  
     if (email == '') {
        document.getElementById("reqemail").innerHTML = '<Br>incorrect'
        err=1
    }
  
    if ( (pass == '') && (pass.length < 4)) {
        document.getElementById("reqpassword").innerHTML = '<BR>incorrect (min 4 char)'
        err=1
    }
   if (pass != compass) {
        document.getElementById("reqpasswordcom").innerHTML = '<BR>does not match password'
        err=1
   // alert(fullname.length)    
    }if (fullname.length < 4 ) {
        document.getElementById("reqfullname").innerHTML = '<BR>incorrect'
        err=1
    }
    
    
    if (err!=1){
        
        makeRequest('register.asp?email=' + email +'&pass=' + pass +'&fullname=' +fullname +'&cell=' +cell +'&town=' +town,'spnregister')
    } 
    

}


function login(){
             
            grayOut(true);
            
            document.getElementById("login_page").style.display='';
            document.getElementById("hidelogintable").style.display=''
            document.getElementById('spnemails').style.display='none'
}

function historysite(r){
    grayOut(true);
   document.getElementById("time_load").style.display=''
    window.location.href = "history.asp?area=" + r
}
function weathersite(r){
    grayOut(true);
  document.getElementById("time_load").style.display=''
    window.location.href = "default.asp?area=" + r
}
function savelocation(loc)
{
    var loginuser 
    grayOut(true);
    loginuser =  Get_Cookie('weather_user')
   // alert(loginuser)
    if( loginuser != null){
         //   Delete_Cookie('weather_user','/','')
            
            makeRequest('savelocation.asp?location=' + loc +'&user=' + loginuser,'saveloc')
            document.getElementById("saveloc").style.display='';
       //     loadsavedloc()
        }else{
            
            document.getElementById("logindetails").innerHTML = "You need to login b4 you can save your weather "  
            document.getElementById("login_page").style.display='';
            document.getElementById("hidelogintable").style.display=''
            
        }
    
    //alert(Get_Cookie('username'))
   // makeRequest('savelocation.asp?area=' + loc,'msgtext')
   // alert("s")
}

function sendtofriend()
{
    document.getElementById("tellyourname").innerHTML = "*"
    document.getElementById("tellfriendsname").innerHTML = "*"
    document.getElementById("tellfriendsemail").innerHTML = "*"
    
    var err=0
    var yname = document.getElementById("your_name").value    
    var yemail = document.getElementById("your_email").value    
    var fname = document.getElementById("friends_name").value    
    var femail = document.getElementById("friends_email").value
    var wid = document.getElementById("weathertempid").value
    var wname = document.getElementById("wname").value        
    var comments = document.getElementById("comments").value    
    
    // Loop over the string value replacing out each matching
    while (comments.indexOf( "'" ) != -1){comments = comments.replace( "'", "`" )}
    while (yname.indexOf( "'" ) != -1){yname = yname.replace( "'", "`" )}
    while (fname.indexOf( "'" ) != -1){fname = fname.replace( "'", "`" )}
    

    
    
    if (yname.length < 1 ){
        err = 1
        document.getElementById("tellyourname").innerHTML = "*&nbsp;<i> required </i>"
        }
    if (fname.length < 1 ){
        err = 1
        document.getElementById("tellfriendsname").innerHTML = "*&nbsp;<i> required </i>"
        }
    if ((femail.indexOf('@')<2 ) || (femail.indexOf('.')<4 )){
        err = 1
        document.getElementById("tellfriendsemail").innerHTML = "*&nbsp;<i> incorrect </i>"
        }        
    
    
    if (err==0){
        makeRequest('tellafriend.asp?wname=' + wname + '&wid=' + wid + '&yname=' + yname + '&yemail=' + yemail + '&fname=' + fname + '&femail=' + femail + '&comments=' +comments ,'spncomments');
    }
}
function showdetails(s){
    grayOut(true);
    document.getElementById(s).style.display='';
  //  document.getElementById("spnweatherlist").style.visibility='hidden';
    centeronload()
    //document.getElementById(h).style.display='none';
    //document.getElementById(hh).style.display='none';
    
}
function showlistbox(){

document.getElementById("spnweatherlist").style.visibility='';
grayOut(false);
document.getElementById('DetailsDetails').style.display='none';

}
function centeronload(){
        //cause ajax does not see this so i have to load it at the onclick
        var screenW = 640, screenH = 480;
        if (parseInt(navigator.appVersion)>3) {
         //screenW = screen.width;
         screenH = screen.height;
         screenW = document.body.offsetWidth;
        }
        else if (navigator.appName == "Netscape" 
            && parseInt(navigator.appVersion)==3
            && navigator.javaEnabled()
           ) 
        {
         var jToolkit = java.awt.Toolkit.getDefaultToolkit();
         var jScreenSize = jToolkit.getScreenSize();
         screenW = jScreenSize.width;
         screenH = jScreenSize.height;
        }
        
    document.getElementById("marinestrip").style.left=(screenW /2) - 350;
    
    document.getElementById("DetailsDetails").style.left=(screenW /2) - 350;
    
}


function grayOut(vis, options) {

  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 50;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
   // document.getElementById("spnweatherlist").style.visibility='hidden';
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    var pageWidth='100%';
       var pageHeight='170%';
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';	
    document.getElementById("spnweatherlist").style.display='none';	 
  } else {
    
     dark.style.display='none';
     document.getElementById("spnweatherlist").style.display='';
  }
}
function gettextads(x,y,x1,y1){



}