// JavaScript Document
// Created By : Raman
// Created On : 25th December, 2008

//var wsUrl = "http://localhost/DailyDigest/";
var wsUrl = "http://dailydigest.in/";
function GetHttpObject(){
var xmlHttpObj;
	try {   
		xmlHttpObj = new XMLHttpRequest();              
		return xmlHttpObj;
	}
	catch (e){        
		try{
			xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");                   
			return xmlHttpObj; 
		}
		catch (e){           
			try{
				xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");                      
				return xmlHttpObj;      
			}
			catch (e)
			{        
				alert("Sorry, Your browser does not support AJAX!");        
				return null;        
			}     
		}   
	}     
}
function UpdateData(){
	var xmlHttp = GetHttpObject();
	if (xmlHttp != null){
		var em=document.getElementById('email').value;
		var url="includes/savenlemail.php?n="+em+'&'+(new Date()).getTime();
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState == 4)	{
				document.getElementById('newsletter').innerHTML=xmlHttp.responseText;
			}	
		}
		xmlHttp.send(null); 
	}
}
function VNewsletter(email, divid){  
    if (document.getElementById(email).value == ""){
        alert("Kindly enter your email.");
        document.getElementById(email).focus();
        return false;
    }
    else if (document.getElementById(email).value !="" && !checkemail(document.getElementById(email).value)){
        alert (document.getElementById(email).value + " is not a valid email, Please enter a valid email");
        document.getElementById(email).focus();
        return false;
    } 
    else{
        SaveDB(email, divid);
		return false;
    }
}

function SaveDB(email, divid){
	var xmlHttp = GetAjaxObject();
	if (xmlHttp != null){
		var url = wsUrl + "includes/savenlemail.php?m="+Math.random()+"&em=" + document.getElementById(email).value;	
		
		xmlHttp.open("GET", url, true);  
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 ){ 
				 //alert(xmlHttp.responseText);
				  document.getElementById(divid).innerHTML = "<br /><br />" + xmlHttp.responseText + "<br /><br />";
			}            
		}    
		xmlHttp.send(null);    
	}   
}

function checkemail(emailadd){
	var result = false;
	var theStr = new String(emailadd);
	var index = theStr.indexOf("@");
	if (index > 0){
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+2))
		result = true;
	}  		
	return result;
}

 

var MDSK = {}
MDSK.Slideshow = Class.create();
MDSK.Slideshow.DefaultOptions = {
  duration: 0.8,
  seconds_per_slide: 10.0,
  pause_on_mouseover: false, // TODO: pause_on_mouseover
  onChange: function() {}
}

Object.extend(MDSK.Slideshow.prototype, {
  initialize: function(container, slide_selector, options) {
	var me = this;  
    this.options = Object.extend(Object.extend({},MDSK.Slideshow.DefaultOptions), options || {});
    this.container = $(container);
	this.slides = Selector.findChildElements(this.container, [slide_selector]);
	this.slides.sort(function(a,b){
			return me.rndm(-1,1);
		});
    this.currentSlide = 0;
    this.paused = false;
    var self = this;
    var Found=false
    this.slides.each(function(slide, idx) {
      if (idx > 0) Element.hide(slide);
      if (self.options.pause_on_mouseover) {
        // Event.observe(slide, 'mouseover', self.pause.bind(self))
        // Event.observe(slide, 'mouseout', self.unpause.bind(self))
      }
    })
    this.slides[0].style.display = "block";
   	
	this.start();
    this.options.onChange(this);
  },
  
  forward: function() {
    var newSlideIdx = this.currentSlide+1;
    if (newSlideIdx >= this.slides.length) newSlideIdx = 0;
    this.transition(newSlideIdx);
  },
  
  backward: function() {
    var newSlideIdx = this.currentSlide-1;
    if (newSlideIdx < 0) newSlideIdx = this.slides.length-1;
	
	var currNum = newSlideIdx+1;
	var num1 = document.getElementById("numDisp");	
	num1.src = null;
	num1.src = "" + currNum + ".jpg";

    this.transition(newSlideIdx);
  },
  
  jumpToSlide: function(idx) {
    if (idx < 0 || idx >= this.slides.length) return false;
    this.stop();
    this.transition(idx);
/* ------------------custom code - you can delete this if you want to customize the slideshow\s look and feel your way. this code is used to change the background color of the div's when slideshow moves from one slide to another---------------*/
	for (i = 0; i < this.slides.length; i++)
	{
		var nam = document.getElementById("showStyle"+i);
		if(idx == i)
		{
			nam.style.backgroundColor = "#666666";
		}
		else
		{
			nam.style.backgroundColor = "#999999";
		}
	}
/*-----------------------custom code ends------------------*/
  },
  
  start: function() {
    if (this.interval) return;
    this.interval = setInterval(this.forward.bind(this), this.options.seconds_per_slide * 1000);
    this.container.addClassName('playing');
  },
  
  stop: function() {
    if (!this.interval) return;
    clearInterval(this.interval);
    this.interval = null;
    this.container.removeClassName('playing');
  },
  
  pausePlay: function() {
    if (this.interval)  this.stop();
    else                this.start();
    },
	
  rndm : function(min, max){
		return Math.floor(Math.random() * (max - min + 1) + min);
	},			
	
  /* ========== */
  
  transition: function(newSlideIdx) {
    var oldSlideIdx = this.currentSlide;
    if (newSlideIdx == oldSlideIdx) return;
    if (this.fadeIn && this.fadeIn.state != 'finished') this.fadeIn.cancel();
    if (this.fadeOut && this.fadeOut.state != 'finished') {
      this.fadeOut.cancel(); Element.hide(this.fadeOut.element);
    }
    this.fadeOut = new Effect.Fade(this.slides[oldSlideIdx], {duration: this.options.duration});
    this.fadeIn = new Effect.Appear(this.slides[newSlideIdx], {duration: this.options.duration});
    this.currentSlide = newSlideIdx;
    this.options.onChange(this);
	
	
/* ------------------custom code - you can delete this if you want to customize the slideshow\s look and feel your way. this code is used to change the background color of the div's when slideshow moves from one slide to another---------------*/
	for (i = 0; i < this.slides.length; i++)
	{
		var nam = document.getElementById("showStyle"+i);
		if(this.currentSlide == i)
		{
			nam.style.backgroundColor = "#666666";
		}
		else
		{
			nam.style.backgroundColor = "#999999";
		}
	}
	/*--------------------------custom code ends ----------------------*/
  } 
});

var req;

function navigate(month,year,st,catId) {
        var url = "includes/calendar.php?month="+month+"&year="+year+"&st="+st+"&catId="+catId;
        if(window.XMLHttpRequest) {
                req = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req.open("GET", url, true);
        req.onreadystatechange = callback;
        req.send(null);
}

function callback() {        
        obj = document.getElementById("calendar");
        setFade(0);
        
		if(req.readyState == 4) {
                if(req.status == 200) {
                        response = req.responseText;
                        obj.innerHTML = response;
                        fade(0);
                } else {
                        alert("There was a problem retrieving the data:\n" + req.statusText);
                }
        }
}

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
    }
}

function setFade(amt) {
	obj = document.getElementById("calendar");
	
	amt = (amt == 100)?99.999:amt;
  
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
  
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}


// JavaScript Document
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
