window.onload = init;

function init() {

     displayDate("date");
     browserBoomkark("bookmark");
     doPopups();
     displayFlash("flashcontent");
	 
	 displayFlashPodcast1("podcast1");
     displayFlashPodcast2("podcast2");
	 displayFlashPodcast3("podcast3");
	 displayFlashPodcast4("podcast4");
	 displayFlashPodcast5("podcast5");
	 displayFlashPodcast6("podcast6");
	 displayFlashPodcast7("podcast7");
	 displayFlashPodcast8("podcast8");
			
	 RSSPopup();
	 
}

// DE - 8/27/2007
// function changes the form action url, allowing cross url posting
function jsRedirect(url) {
    document.forms[0].action = url;
}

// RSS Feed (what is RSS?)
function RSSPopup() {

    var link  = document.getElementById('RSSPopup');

    if (link) {
    
        link.onclick = function() {

            makePopup(this.href, 'RSS', 'width=285,height=485');

            return false;
        };
    }
}

// subscribe to stitches mag
function subscribeIssue(frm) {
     
     var f = frm;
     var pub = "st"; 
     var url = "http://www.submag.com/sub/"+pub+"?tc=1&isp=asiembed"; 

     url += "&fn="+escape(f.fn.value); 
     url += "&ln="+escape(f.ln.value); 
     url += "&co="+escape(f.co.value); 
     url += "&adr="+escape(f.adr.value); 
     url += "&cit="+escape(f.cit.value); 
     url += "&st="+f.st.options[f.st.selectedIndex].value; 
     url += "&zip="+escape(f.zip.value); 
	 url += "&eml="+escape(f.eml.value);
 
     makePopup(url, 'StitchMagazineSubscriptionForm', 'scrollbars=yes,width=800,height=600');
} 

// view newsletters
function viewNewsletter(menu) {

     var index = menu.selectedIndex; 

	 if (index != 0 ) { 

		 var url = menu.options[index].value; 
         menu.selectedIndex = 0; // reset
         openWindow(url);       
     }
}

// validate form fields
function validateEmail(frm) {
	
     if (!/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/.test(frm.email.value)) {
     
          alert("Please enter a valid email");
          frm.email.focus()
          return false
     }
	
	 return true;
}

// display date
function displayDate(id) {

     var currentDate = document.getElementById(id);

     var dtDate = new Date();
     var dtYear = dtDate.getFullYear();
     var dtDay = dtDate.getDay();
     var dtMonth = dtDate.getMonth();  
     var dtNow = dtDate.getDate(); 
   
     var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
     var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

     if (dtNow < 10) { dtNow = "0" + dtNow };
     
     var date = days[dtDay]+ ", " + months[dtMonth]+ " " + dtNow + ", " + dtYear;

     currentDate.innerHTML = date;
}

// replace target = "_blank"
function doPopups() {

  var links = document.getElementsByTagName("a");
 
  for (var i=0; i < links.length; i++) {
 
    if (links[i].className.match("externalLink")) {
		links[i].className = links[i].className + " newWinStyle";
		
		if (links[i].title == "") {
		    links[i].title = "(new window)";
		} else {
		    links[i].title = links[i].title + " (new window)";	
		}
	 	
	 	links[i].onclick = function(e) {
			
			if (!e) e=window.event;
			if(e.shiftKey || e.ctrlKey || e.altKey) return;
			    openWindow (this.href);
			    return false;
			}
        }
    }
}

// create new window
function openWindow (url) { 
     
     var win = window.open(url);
     win.focus()
}

// create popup window
function makePopup(url, name, features) {
   
    var win = window.open(url, name, features);
    win.focus();
}

function displayFlash(id) {

    var tmp = document.getElementById(id)

    // If not on default.asp then the "flashcontent" id will not be there
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/videocast/stitches/video3.swf", "mymovie", "186", "180", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast1(id) {

    var tmp = document.getElementById(id)

    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/031708/music/MZ000074.mp3", "mymovie1", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast2(id) {

    var tmp = document.getElementById(id)
	
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/110207/music/FredLebow.mp3", "mymovie2", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast3(id) {

    var tmp = document.getElementById(id)
	
	// only displaysing on Podcast page
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/bowles/music/bowles.mp3", "mymovie3", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast4(id) {

    var tmp = document.getElementById(id)
	
	// only displaysing on Podcast page
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/PatBaldes/music/baldes.mp3", "mymovie4", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast5(id) {

    var tmp = document.getElementById(id)
	
	// only displaysing on Podcast page
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/MarieZeffer/music/zeffer.mp3", "mymovie5", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast6(id) {

    var tmp = document.getElementById(id)
	
	// only displaysing on Podcast page
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/KenBerg/music/berg.mp3", "mymovie6", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast7(id) {

    var tmp = document.getElementById(id)
	
	// only displaysing on Podcast page
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/BobParker/music/parker.mp3", "mymovie7", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function displayFlashPodcast8(id) {

    var tmp = document.getElementById(id)
	
	// only displaysing on Podcast page
    if (tmp) {

        var so = new SWFObject("http://cdn.asicentral.com/idesign/global/podcast/stitches/podcastplayer.swf?file=http://cdn.asicentral.com/idesign/global/podcast/JeanFitzsimons/music/fitzsimmons.mp3", "mymovie8", "150", "35", "8", "#eef4f9");
        so.write(id);
    }
}

function browserBoomkark(elm) {

    var link = document.getElementById(elm);

        switch (BrowserDetect.browser) {

	        case 'Explorer': // supports making page default homepage
	
		        link.innerHTML = 'Set to Home Page';
		
		        link.style.cursor = 'pointer';
		
		        link.onclick = function () {
	
			        this.style.behavior='url(#default#homepage)';
			        this.setHomePage('http://www.asipublications.com/stitches/');
	            }
	
	            break;

	        case 'Firefox': // only supports making page a favorite
	
		        link.innerHTML = 'Set to Favorite';
		
		        link.style.cursor = 'pointer';
	
		        link.onclick = function () {
	
			    window.sidebar.addPanel('Stitches', 'http://www.asipublications.com/stitches', "");
	        }
	
	        break;

	        default:

		    // nothing is displayed for other browsers (empty span)
        }
}