/*
 * Default.js
 *
 * Contains functions used across the site. 
 *
 */
var varHowLong = "30";

 function f_scrollTop() {
	 return f_filterResults (
    	window.pageYOffset ? window.pageYOffset : 0,
    	document.dlocumentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_scrollLeft() {
    return f_filterResults (
    	window.pageXOffset ? window.pageXOffset : 0,
    	document.documentElement ? document.documentElement.scrollLeft : 0,
    	document.body ? document.body.scrollLeft : 0
    );
}

function ReadCookie(cookieName) {
    var theCookie=""+document.cookie;
    var ind=theCookie.indexOf(cookieName);
    if (ind==-1 || cookieName=="") return ""; 
    var ind1=theCookie.indexOf(';',ind);
    if (ind1==-1) ind1=theCookie.length; 
    return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetCookie(cookieName,cookieValue) {
    var today = new Date();
    var expire = new Date();
    expire.setTime(today.getTime() + 10000);
    document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function DeleteCookie(cookieName)
{
    var today = new Date();
    var expire = new Date();
    expire.setTime(today.getDay() - 10000);
    document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

//function LoadBlog(blogId){

//    varURL = "Blogs.aspx#" + blogId.toString();
//    self.setTimeout("self.location.href = varURL;",varHowLong); 
//    varURL = "Blog.aspx?bid=" + blogId.toString();
//    self.setTimeout("self.location.href = varURL;",varHowLong); 


//}

function LoadBlog(blogId, issiteblog, schoolid){
//    varURL = "Blogs.aspx#" + blogId.toString();
//    self.setTimeout("self.location.href = varURL;",varHowLong); 
if(issiteblog)
 {
   varURL = "risBlog.aspx?bid=" + blogId.toString() + "&schoolid=34";
}
else{ 
    varURL = "Blog.aspx?bid=" + blogId.toString() + "&schoolid=" + schoolid ;
}


    self.setTimeout("self.location.href = varURL;",varHowLong); 


}


function LoadBlogByMonthAndYear(month, year, schoolid){

    SetCookie("month", month);
    SetCookie("year", year);
    varURL = "Archive.aspx?schoolid=" + schoolid;
    self.setTimeout("self.location.href = varURL;",varHowLong); 

}


function LoadBlogByMonth(month, schoolid){

    SetCookie("month", month);
    SetCookie("year", 0);
    varURL = "Archive.aspx?schoolid=" + schoolid;
    self.setTimeout("self.location.href = varURL;",varHowLong); 

}



function DoFilter(Value, FilterType){

    var str= document.location.href;

    i=str.indexOf("?");
    start = str.indexOf(FilterType) -1;
    strSearch = str.substring(start + 1,str.length );
    end = strSearch.indexOf("?");

    searchParams = strSearch.substring(0, end);
    str = searchParams +"?t=1&" + FilterType + "=" + Value ;

    return str;
/*
    var str= document.location.href;
    i=str.indexOf("&");
    start = str.indexOf(FilterType) -1;
    strSearch = str.substring(start + 1,str.length );
    end = strSearch.indexOf("&");
    if(end > 0 )
    	searchParams = strSearch.substring(0, end);
    else
    	searchParams = strSearch;

    //alert(searchParams);

    if(searchParams.indexOf("?") < 0)
    	str = str.replace(searchParams , "?" + FilterType + "=" + Value );
    else
    	    str = str.replace(searchParams , FilterType + "="+Value );

    //if(str.indexOf("?") < 0)
    //	str = str.replace(searchParams , "?" + FilterType + "=" + Value );
    //else
    //	    str = str.replace(searchParams , FilterType + "="+Value );

    return str;*/
}                 
                 
function DoRisTagFilter(tagValue, schoolid){
    SetCookie("author", 0);
    var str = DoFilter(tagValue, "search");
    varURL = "RisBlogs.aspx" + str;

    self.setTimeout("self.location.href = varURL;",varHowLong); 
}
function DoPodcastTagFilter(tagValue, schoolid){
    SetCookie("author", 0);
    var str = DoFilter(tagValue, "search");
    varURL = "podcasts.aspx?t=1&search=" + tagValue + "&schoolid=" + schoolid;
    self.setTimeout("self.location.href = varURL;",varHowLong); 
}

function DoLatestTagFilter (tagValue, schoolid){

    SetCookie("author", 0);
//    var str = DoFilter(tagValue, "search");
    varURL = "blogs.aspx?t=1&search=" + tagValue + "&schoolid=" + schoolid;
    self.setTimeout("self.location.href = varURL;",varHowLong); 
}
    
function DoTagFilter(tagValue, schoolid){
    SetCookie("author", 0);
    var str = DoFilter(tagValue, "search");
    varURL = "blogs.aspx?t=1&search=" + tagValue + "&schoolid=" + schoolid;

    self.setTimeout("self.location.href = varURL;",varHowLong); 
}
     
function DoTagFilter1(tagValue){
    var str = DoFilter(tagValue, "search");

    varURL = str ;
    self.setTimeout("self.location.href = varURL;",varHowLong); 
}


function LoadSchool(SchoolId){
    SetCookie("school", SchoolId);
    SetCookie("author", 0);
    varURL = "SchoolHomePage.aspx?schoolid=" + SchoolId;
    self.setTimeout("self.location.href = varURL;",varHowLong); 
}

function LoadBlogAuthor(AuthorId){
    SetCookie("author", AuthorId);
    SetCookie("school", 0);
    varURL = "Blogs.aspx";
    self.setTimeout("self.location.href = varURL;",varHowLong); 
}

function LoadRisBlog(AuthorId, schoolid){
    SetCookie("author", AuthorId);
    SetCookie("school", 0);
    varURL = "risBlogs.aspx";
    self.setTimeout("self.location.href = varURL;",varHowLong); 
}


function LoadAuthor(AuthorId, SchoolId){
    SetCookie("author", AuthorId);
    SetCookie("school", SchoolId);
    varURL = "SchoolsPodcasts.aspx?schoolid=" + SchoolId;
    self.setTimeout("self.location.href = varURL;",varHowLong); 
}

$(document).ready(function(){

$(".myPodcastAlt").click(function()
  {
     
 var str =$(this).find("#myPodcastId").text();
    varURL = "my-podcasts.aspx?pid=" + str + "#" + str;
    self.setTimeout("self.location.href = varURL;",varHowLong); 
 });

$(".myPodcast").click(function()
  {
     
 var str =$(this).find("#myPodcastId").text();
    varURL = "my-podcasts.aspx?pid=" + str + "#" + str;
    self.setTimeout("self.location.href = varURL;",varHowLong); 
 });
 
 $('.myPodcastClickArea').hover(function() {
  $(this).css("cursor", "hand");
}, function() {
  $(this).css("cursor", "pointer");
});


});








function validate(chk){
  if (chk.checked == 0)

    alert("You didn't check it! Let me check it for you."); 

valid = true;

    if ( document.f1.fullname.value == "" )
    {
        alert ( "Please fill in the 'Your Name' box." );
        valid = false;
    }

    return valid;


}

function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

