////////////////////////////////////////////////////////////////////////////////
//  swarathma.com javascripts
//  Author: Sanjeev Nayak
//  Copyright (C) 2008 swarathma.com. All rights reserved.
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
//  Generic scripts
////////////////////////////////////////////////////////////////////////////////


//  This will write the top menu bar. The piece of html written by this script  
//  was being repeated on every page, so made it into a script to avoid code
//  duplication. 
function write_top_menubar(page) {

	document.write("<table border='0' cellpadding='0' cellspacing='0'>");
	document.write("<tr align='left'>");
	document.write("<td><a href='http://swarathma.com/sound.html' title='Sound' alt='Sound'><img src='images/links/" + page + "/sound.png' border='0' class='highlight'></a></td>");
	document.write("<td width='2'></td>");
	document.write("<td><a href='http://swarathma.com/band.html' title='Band' alt='Band'><img src='images/links/" + page + "/band.png' border='0' class='highlight'></a></td>");
	document.write("<td width='1'></td>");
	document.write("<td><a href='http://swarathma.com/album.html' title='Album' alt='Album'><img src='images/links/" + page + "/album.png' border='0' class='highlight'></a></td>");
	document.write("<td width='3'></td>");
	document.write("<td><a href='http://swarathma.com/photos.html' title='Photos' alt='Photos'><img src='images/links/" + page + "/photos.png' border='0' class='highlight'></a></td>");
	document.write("<td width='2'></td>");
	document.write("<td><a href='http://swarathma.in/blog.asp' title='Blog' alt='Blog'><img src='images/links/" + page + "/blog.png' border='0' class='highlight'></a></td>");
	document.write("<td width='1'></td>");
	document.write("<td><a href='http://swarathma.com/video.html' title='Video' alt='Video'><img src='images/links/" + page + "/video.png' border='0' class='highlight'></a></td>");
	document.write("<td width='1'></td>");
	document.write("<td><a href='http://swarathma.in/guestbook.asp' title='Guestbook' alt='Guestbook'><img src='images/links/" + page + "/guestbook.png' border='0' class='highlight'></a></td>");
	document.write("<td width='3'></td>");
	document.write("<td><a href='http://swarathma.com/horn.html' title='Horn' alt='Horn'><img src='images/links/" + page + "/horn.png' border='0' class='highlight'></a></td>");
	document.write("</tr>");
	document.write("</table>");
}


// function to write the top area
function write_top_area(page) {
	
	document.write("<tr height='35'>");
	document.write("<td width='49' ></td>");
	document.write("<td width='912'></td>");
	document.write("<td width='39'></td>");
	document.write("</tr>");
	document.write("<tr height='40'>");
	document.write("<td></td>");
	if (page == "presskit")	{
		document.write("<td align='center'>");
		document.write("<img src='../images/links/" + page + "/presskit.png' border='0'>");
		document.write("</td>");
	} else {
		document.write("<td align='left'>");
		write_top_menubar(page);
		document.write("</td>");
	}
	document.write("<td></td>");
	document.write("</tr>");
}

// function get musicyogi url
function get_musicyogi_url()
{
	return "http://shopping.indiatimes.com/i/f/t/Swarathma_28Audio_CD_29-pid-2488244-ctl-20376475-cat--pc--&bid=&prc=&sid=&q=swarathma&";
}

function get_soundpad_url()
{
	return "";
}

function get_buy_swarathma_album_html()
{
	return "<a class='contentalbumbuy' href='" + get_musicyogi_url() + "' target='_NEW'><span class='contentalbumbuy'>buy the </span><span class='contentalbumname'>swarathma </span><span class='contentalbumbuy'>album</span></a>";
}

function get_buy_soundpad_album_html()
{
	return "<a class='contentalbumbuy' href='" + get_soundpad_url() + "' target='_NEW'><span class='contentalbumbuy'>buy the </span><span class='contentalbumname'>soundpad </span><span class='contentalbumbuy'>album</span></a>";
}

function get_home_link_html(page, width)
{
	return "<td width='" + width + "' align='center' valign='bottom'><a href='http://swarathma.com/' title='Home' alt='Home'><img src='images/links/" + page +"/home.png' border='0' class='highlight'></a></td>";
}

function get_swarathma_track(album, track)
{
	document.write("<div class='playercontainer'>");
	document.write("<div class='playertop'></div>");
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='360' height='26'>");
	//document.write("<param name='movie' value='http://swarathma.in/tracks/" + album + "/" + track + "/" + track + ".swf' />");
	document.write("<param name='movie' value='tracks/" + album + "/" + track + "/" + track + ".swf' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='allowScriptAccess' value='always' />");
	document.write("<param name='wmode' value='transparent'>");
	//document.write("<embed src='http://swarathma.in/tracks/" + album + "/" + track + "/" + track + ".swf'");
	document.write("<embed src='tracks/" + album + "/" + track + "/" + track + ".swf'");
	document.write("quality='high'");
	document.write("type='application/x-shockwave-flash'");
	document.write("WMODE='transparent'");
	document.write("width='360'");
	document.write("height='26'");
	document.write("pluginspage='http://www.macromedia.com/go/getflashplayer'");
	document.write("allowScriptAccess='always' />");
	document.write("</object>");
	document.write("</div>");
}



// this will write the footer at the bottom
function write_footer(page, left, right) {
	document.write("<td colspan='3' valign='bottom'>");
	document.write("<table border='0' cellpadding='0' cellspacing='0'>");
	document.write("<tr>");
	document.write("<td width='325' align='right' valign='middle'>" + left + "</td>");
	document.write(get_home_link_html(page, 350));
	document.write("<td width='325' align='left' valign='middle'>" + right + "</td>");
	document.write("</tr>");
	document.write("</table>");
	document.write("</td>");
}


function write_athma_footer() {

}

function write_tracks_footer(album)
{
	if (album == "swarathma") {
		document.write("<td colspan='3' valign='bottom'>");
		document.write("<table border='0' cellpadding='0' cellspacing='0'>");
		document.write("<tr>");
		document.write("<td width='300' align='right' valign='middle'>" + get_buy_swarathma_album_html() + "</td>");
		document.write(get_home_link_html("album", 400));
		document.write("<td width='300' align='left' valign='middle'><a href='jamba.html'><img src='images/links/album/soundpad.png' border='0' title='Open Soundpad album'></a></td>");
		document.write("</tr>");
		document.write("</table>");
		document.write("</td>");
	} else if (album == "soundpad") {
		document.write("<td colspan='3' valign='bottom'>");
		document.write("<table border='0' cellpadding='0' cellspacing='0'>");
		document.write("<tr>");
		document.write("<td width='325' align='right' valign='middle'><a href='jaana_kahan_hai_mujhe.html'><img src='images/links/album/swarathma.jpg' border='0' title='Open Swarathma album'></a></td>");
		document.write(get_home_link_html("album", 350));
		document.write("<td width='325' align='left' valign='middle'>" + get_buy_soundpad_album_html() + "</td>");
		document.write("</tr>");
		document.write("</table>");
		document.write("</td>");
	}
}

// write track listing for every track
function write_track_listing(album)
{
	if (album == "swarathma") {
		document.write("<div class='trackcontainer'><a href='jaana_kahan_hai_mujhe.html' class='tracklisting1'>jaana kahan hai mujhe</a></div>");
		document.write("<div class='trackcontainer'><a href='pyaar_ke_rang.html' class='tracklisting2'>pyaar ke rang</a></div>");
		document.write("<div class='trackcontainer'><a href='sur_mera.html' class='tracklisting1'>sur mera</a></div>");
		document.write("<div class='trackcontainer'><a href='patte_saare.html' class='tracklisting2'>patte saare</a></div>");
		document.write("<div class='trackcontainer'><a href='ee_bhoomi.html' class='tracklisting1'>ee bhoomi</a></div>");
		document.write("<div class='trackcontainer'><a href='bolo_kya_hai.html' class='tracklisting2'>bolo kya hai</a></div>");
		document.write("<div class='trackcontainer'><a href='barsenge.html' class='tracklisting1'>barsenge</a></div>");
		document.write("<div class='trackcontainer'><a href='pyaasi.html' class='tracklisting2'>pyaasi</a></div>");
	} else if (album == "soundpad")	{
		document.write("<div class='trackcontainer'><a href='jamba.html' class='tracklisting1'>jamba</a></div>");
		document.write("<div class='trackcontainer'><a href='yeshu_allah_krishna.html' class='tracklisting2'>yeshu allah krishna</a></div>");
	}
}


function show_thumbnail(name, width, height)
{
	document.write("<td width='91' align='left' valign='top'>");
	if (name != "")	{
		//document.write("<a href='#' onclick=\"window.open('images/photos/full/" + name + ".jpg','" + name + "','width=" + (width + 36) + ",height=" + (height + 24) +",location=0,status=0,resizable=0')\">");
		document.write("<a href='#' onclick=\"_photo('" + name + "', " + width +", " + height + ")\">");
		document.write("<img src='images/photos/thumbnail/" + name + ".jpg' border='0' class='highlight'></a>");
	}
	document.write("</td>");
}

var albumHTML;
var firstTime = true;

function hide_album()
{
	document.getElementById('album').style.visibility = 'hidden'; 
}

function show_album()
{
	if (firstTime)	{
		albumHTML = document.getElementById('album').innerHTML;
		firstTime = false;
	}

	document.getElementById('album').innerHTML = albumHTML;
	document.getElementById('album').style.visibility = 'visible';

}

function show_photo(name, width, height)
{
	document.getElementById('photocontainer').innerHTML = "<img id='photo' border='0' onclick='_album()'>";
	document.getElementById('photo').src = "images/photos/full/" + name + ".jpg";
	document.getElementById('photo').width = width;
	document.getElementById('photo').height = height;
	document.getElementById('photo').style.visibility = 'visible';
	document.getElementById('photocontainer').style.visibility = 'visible';
}

function hide_photo()
{
	document.getElementById('photo').src = "";
	document.getElementById('photo').width = 0;
	document.getElementById('photo').height = 0;
	document.getElementById('photo').style.visibility = 'hidden';
	//document.getElementById('photocontainer').style.visibility = 'hidden';
}

function _album()
{
	hide_photo();
	show_album();
}

function _photo(name, width, height)
{
	show_photo(name, width, height);
	hide_album();
}

function presskit_table()
{
	var row1 = ["swarathma5", "swarathma6", "swarathma7", "swarathma8", "swarathma9", "swarathma10"];
	var row2 = ["uk1", "swarathma2", "swarathma3", "swarathma4", "show1", "show2", "show3"];
	var row3 = ["show4", "show5", "show6", "show7", "show8", "show9", "ghodi"];
	var row4 = ["vasu", "pavan", "montry1", "jishnu", "sanjeev", "varun1", "montry2"];

	document.write("<table border='0' cellpadding='0' cellspacing='0'>");
	presskit_row(row1);
	presskit_row(row2);
	presskit_row(row3);
	presskit_row(row4);
	document.write("</table>");
}

function presskit_row(names)
{
	document.write("<tr height='120'>");
	for (var i=0; i<names.length; i++ )	{
		presskit_col(names[i]);
	}
	document.write("</tr>");
}

function presskit_col(name)
{
	document.write("<td width='120' align='center' valign='middle'>");
	document.write("<a href='images/full/" + name + ".jpg' target='_NEW'>");
	document.write("<img src='images/thumbnail/" + name + ".jpg' border='0' class='highlight'>");
	document.write("</a></td>");
}

// pre-loads the images when the page is loaded - will ensure that images are not
// loaded when mouse is moved over them but loaded upfront.
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// restores the original image - used on the mouse out event
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// find object with the specified id
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// swap the image - used with mouse over event
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// pops up a new browser window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


////////////////////////////////////////////////////////////////////////////////
//  Guestbook client side validation scripts
////////////////////////////////////////////////////////////////////////////////

//  Script to check if an email address is valid
function validate_email_address(email) {
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return filter.test(email);
}

//  Script to check if the guestbook post is valid in terms of the string lengths,
//  values etc. It also strips off the leading and trailing spaces.
function validate_guestbook_post(frm) {

    // max lengths for each field
    var maxmsglen = 2000;
    var maxnamelen = 64;
    var maxemaillen = 64;
    
    // trim the spaces
    frm.Person.value = trim(frm.Person.value);
    frm.EMail.value = trim(frm.EMail.value);
    frm.Message.value = trim(frm.Message.value);
    frm.Homepage.value = trim(frm.Homepage.value);

	// is the 'name' field empty?
    if (frm.Person.value.length == 0) {
        alert("Please enter your name. You cannot leave the 'Name' field empty!");
        frm.Person.focus();
        return false;
    }
    
	// is the 'name' field too long?
    if (frm.Person.value.length > maxnamelen) {
        alert("Your name seems to be too long. Please limit the size of your name to " + maxnamelen + " characters.");
        frm.Person.focus();
        return false;
    }

	// is the 'email' field empty?
    if (frm.EMail.value.length == 0) {
        //alert("Please enter your e-mail address. You cannot leave the 'E-mail' field empty!");
        frm.EMail.focus();
        return true;
    } else if (frm.EMail.value.length > maxnamelen) { // is the 'email' field too long?
        alert("Your E-mail address seems to be too long. Please limit the size of your E-mail address to " + maxemaillen + " characters.");
        frm.EMail.focus();
        return false;
    } else if (validate_email_address(frm.EMail.value) == false) { // is the email address bad?
        alert("Please enter a valid email address. The one you have entered '" + frm.EMail.value + "' is invalid.");
        frm.EMail.focus();
        return false;
    }
    
	// is the 'message' field empty?
    if (frm.Message.value.length == 0) {
        alert("Please enter your message. You cannot leave the 'Message' field empty!");
        frm.Message.focus();
        return false;
    }

	// is the 'message' field too long?
    if (frm.Message.value.length > maxmsglen) {
        alert("Your message seems to be too long. Please limit the size of your message to " + maxlen + " characters.");
        frm.Message.focus();
        return false;
    }

	// if we're here, the values entered by the user must be okay.
    return true;
}

//  Script to strip off the leading and trailing spaces in a string
function trim(str) {

    // strip off any leading spaces
    while (str.substring(0, 1) == ' ') {
        str = str.substring(1, str.length);
    }

	// strip off any trailing spaces
    while (str.substring(str.length-1, str.length) == ' ') {
        str = str.substring(0, str.length-1);
    }
    return str;
}

function gbLogout() {
}

var JmlButton = new cJmlButton();

function cJmlButton() {
    this.Normal = "images/others/jml_normal.png";
    this.Hover = "images/others/jml_hover.png";
    this.Click = "images/others/jml_click.png";
}

cJmlButton.prototype.MouseOut = function() {
    document.getElementById("jmlbutton").src = this.Normal;
}

cJmlButton.prototype.MouseOver = function() {
    document.getElementById("jmlbutton").src = this.Hover;
}

cJmlButton.prototype.MouseDown = function() {
    document.getElementById("jmlbutton").src = this.Click;
}


function JoinMailingList() {
    var email = document.getElementById("email").value
    if (email == "" || email == "Enter your e-mail id") {
        // return without doing anything - no need to show error message
        return;
    }
    if (validate_email_address(email)) {
        document.jml.submit();
    } else {
        alert("Please enter a valid email address. The one you have entered '" + email + "' is invalid.");
    }

}

function JmlEmailOnFocus() {
    var email = document.getElementById("email").value;
    if (email == "Enter your e-mail id") {
        document.getElementById("email").value = "";
    }
    document.getElementById("email").className = "jmlfocus";
}

function JmlEmailNoFocus() {
    var email = document.getElementById("email").value;
    if (email == "") {
        document.getElementById("email").value = "Enter your e-mail id";
        document.getElementById("email").className = "jmlnofocus";
    }
}