// JavaScript Document

function login()
{
	document.blip.submit();	
}
function init()
{		 

   var formInputs = document.getElementsByTagName('input');
      for (var i = 0; i < formInputs.length; i++) {
          var theInput = formInputs[i];
        	
              if ((theInput.type == 'text' || theInput.type == 'password') && theInput.className.match(/\bcleardefault\b/)) {  
               /* Add event handlers */          
                 addEvent(theInput, 'focus', clearDefaultText, false);
                 addEvent(theInput, 'blur', replaceDefaultText, false);
                 
                 if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            	}
        	}
    }
    
     weekAjax("http://sn.blipcam.com/appwebcam/Actprofile.php");
     
}
function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}

function weekAjax(strURL) {
	
	document.getElementById('month').style.display="none";
	document.getElementById('today').style.display="none";
	document.getElementById('week').style.display="block";
	
	document.getElementById('page1').style.display="block";
	document.getElementById('page2').style.display="none";
	document.getElementById('page3').style.display="none";
	
	document.getElementById('litag3').className="";
	document.getElementById('litag2').className="";
	document.getElementById('litag1').className= "active";
	
			
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			
            Weekactive(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystringweek());
}
function getquerystringweek() {
	
   qstr="p";
    return qstr;
}
function Weekactive(str)
{
	
	var res=str;
	if(res == 0)
	{		
			document.getElementById('week').innerHTML = 'No Pokes Found....';
	}
	else
	{
	 var recparam_array = str.split(",");    
     //var user_count = recparam_array[0].split("^");
     var frname_array = recparam_array[0].split("^");
     var imgname_array = recparam_array[1].split("^");
     var imgpath_array = recparam_array[2].split("^");
     var day_array =     recparam_array[3].split("^");
     var hour_array =    recparam_array[4].split("^");
     var min_array =     recparam_array[5].split("^");
     var sec_array =     recparam_array[6].split("^");
	
	 listvideoact="";
	 listvideoact = new Array();
	 var shtime = "";
	 var count=imgpath_array.length;
	 
	    created = "Created";
        by = "By";
		sent = "Sent";
		ago = "ago";
		Alltime ="ALL TIME ACTIVE";
		
		 for(var g=0;g<count;g++){	
			    
				if(parseInt(sec_array[g]) > 60) {
		          if(parseInt(min_array[g]) > 60) {
			         if(parseInt(hour_array[g]) > 24) {
                        shtime = day_array[g] + " days "+ago;
			         } else {
                            shtime = hour_array[g] + " hours "+ago;
			         }
			       } else {
			           shtime = min_array[g] + " minutes "+ago;
			       }
			    }  else {
			     shtime =   sec_array[g] + " seconds "+ago;
			    }				
			 		
		    	listvideoact.push('<span style="float:left;width:90px;margin:12px;height:130px;margin-top:15px;"><div><img src="'+ imgpath_array[g]+imgname_array[g]+'" width="90" height="90" /></div><div style="text-align:left;width:95px;margin-bottom:5px;margin-top:5px;"><p style="margin:10px;color:#000066;font-size:10px;font-weight: bold;font-family: tahoma;">'+by+' '+frname_array[g]+'</p><hr style="height: 2px;color:red"/><p style="margin:10px;color:#000066;font-size:10px;font-family: tahoma;">'+created+' '+shtime+'</p></div></span>');		    	
				
        }        
     	//document.getElementById('week').innerHTML = listvideoact.join('');
		listvideoact.push('weekpokes');
        initPagination();
	}
	
}

function monthAjax(strURL) {

	document.getElementById('week').style.display="none";
	document.getElementById('today').style.display="none";
	document.getElementById('month').style.display="block";
	
	document.getElementById('page1').style.display="none";
	document.getElementById('page2').style.display="block";
	document.getElementById('page3').style.display="none";
	
	document.getElementById('litag3').className="";
	document.getElementById('litag2').className="active";
	document.getElementById('litag1').className= "";
	
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			
            Monthactive(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getqrymonth());
}
function getqrymonth() {
	
   qstr="p";
    return qstr;
}
function Monthactive(str)
{
	var res=str;
	if(res == 0)
	{		
			document.getElementById('month').innerHTML = 'No Pokes Found....';
	}
	else
	{
	 var recparam_array = str.split(",");    
     //var user_count = recparam_array[0].split("^");
     var frname_array = recparam_array[0].split("^");
     var imgname_array = recparam_array[1].split("^");
     var imgpath_array = recparam_array[2].split("^");
     var day_array =     recparam_array[3].split("^");
     var hour_array =    recparam_array[4].split("^");
     var min_array =     recparam_array[5].split("^");
     var sec_array =     recparam_array[6].split("^");
	
	 listvideoact="";
	 listvideoact = new Array();
	 var shtime="";
	 var count=imgpath_array.length;
	    created = "Created";
        by = "By";
		sent = "Sent";
		ago = "ago";
		Alltime ="ALL TIME ACTIVE";
		
		 for(var g=0;g<count;g++){
			 
			 if(parseInt(sec_array[g]) > 60) {
		          if(parseInt(min_array[g]) > 60) {
			         if(parseInt(hour_array[g]) > 24) {
                        shtime = day_array[g] + " days "+ago;
			         } else {
                            shtime = hour_array[g] + " hours "+ago;
			         }
			       } else {
			           shtime = min_array[g] + " minutes "+ago;
			       }
			    }  else {
			     shtime =   sec_array[g] + " seconds "+ago;
			    }				
				
		    	listvideoact.push('<span style="float:left;width:90px;margin:12px;height:130px;margin-top:15px;"><div><img src="'+ imgpath_array[g]+imgname_array[g]+'" width="90" height="90" /></div><div style="text-align:left;width:95px;margin-bottom:5px;margin-top:5px;"><p style="margin:10px;color:#000066;font-size:10px;font-weight: bold;font-family: tahoma;">'+by+'  '+frname_array[g]+'</p><hr style="height: 2px;color:red"/><p style="margin:10px;color:#000066;font-size:10px;font-family: tahoma;">'+created+' '+shtime+'</p></div></span>');		    	
				
        }  
		
     	//document.getElementById('month').innerHTML = listvideoact.join('');
		listvideoact.push('monthpokes');
        initPagination();
	}
	
}

function todayAjax(strURL) {
	
	document.getElementById('week').style.display="none";
	document.getElementById('month').style.display="none";
	document.getElementById('today').style.display="block";
	
	document.getElementById('page1').style.display="none";
	document.getElementById('page2').style.display="none";
	document.getElementById('page3').style.display="block";
	
	document.getElementById('litag3').className="active";
	document.getElementById('litag2').className="";
	document.getElementById('litag1').className= "";
	
	
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			
			Todayactive(self.xmlHttpReq.responseText);
			
        }
    }
    self.xmlHttpReq.send(getqrytoday());
}
function getqrytoday() {
	
   qstr="t";
    return qstr;
}
function Todayactive(str)
{
	
	var res=str;	
	if(res == 0)
	{	
	
			document.getElementById('today').innerHTML = 'No Pokes Found....';
			
	}
	else
	{
		
		var recparam_array = str.split(",");    
		//var user_count = recparam_array[0].split("^");
		var frname_array = recparam_array[0].split("^");
		var imgname_array = recparam_array[1].split("^");
		var imgpath_array = recparam_array[2].split("^");
		var day_array =     recparam_array[3].split("^");
     	var hour_array =    recparam_array[4].split("^");
    	var min_array =     recparam_array[5].split("^");
    	var sec_array =     recparam_array[6].split("^");
		
		listvideoact="";
		listvideoact = new Array();
		var shtime="";
		var count=imgpath_array.length;
			created = "Created";
			by = "By";
			sent = "Sent";
			ago = "ago";
			Alltime ="ALL TIME ACTIVE";
		
				for(var g=0;g<count;g++){	
				
					if(parseInt(sec_array[g]) > 60) {
						  if(parseInt(min_array[g]) > 60) {
							 if(parseInt(hour_array[g]) > 24) {
								shtime = day_array[g] + " days "+ago;
							 } else {
									shtime = hour_array[g] + " hours "+ago;
							 }
						   } else {
							   shtime = min_array[g] + " minutes "+ago;
						   }
						}  else {
						 shtime =   sec_array[g] + " seconds "+ago;
					}		
							 
				
						listvideoact.push('<span style="float:left;width:90px;margin:12px;height:130px;margin-top:15px;"><div><img src="'+ imgpath_array[g]+imgname_array[g]+'" width="90" height="90" /></div><div style="text-align:left;width:95px;margin-bottom:5px;margin-top:5px;"><p style="margin:10px;color:#000066;font-size:10px;font-weight: bold;font-family: tahoma;">'+by+' '+frname_array[g]+'</p><hr style="height: 2px;color:red"/><p style="margin:10px;color:#000066;font-size:10px;font-family: tahoma;">'+created+' '+shtime+'</p></div></span>');		    	
						
			}        
			//document.getElementById('today').innerHTML = listvideoact.join('');
			listvideoact.push('todaypokes');
            initPagination();
			
	}
	
}

function pageselectCallback(page_index, jq){
                // Get number of elements per pagionation page from form
                
	var rs = listvideoact[(listvideoact.length-1)];
	pindex = page_index; 
	var newcontent = '';
                
       /******change by sameena*******/
                
		if( rs == 'monthpokes' ){
			var items_per_page = 21;                	
		}else if ( rs == 'weekpokes' ) {
			var items_per_page = 21;                	
		} else if ( rs == 'todaypokes' ) {
			var items_per_page = 21;                	
		} else {
			var items_per_page = 21;    //change from 12 to 9 again change to 6                	
		}
		
		var max_elem = Math.min((page_index+1) * items_per_page, (listvideoact.length-1));          

		// Iterate through a selection of the content and build an HTML string
		for(var i=page_index*items_per_page;i<max_elem;i++)
		{                	
				if( rs == 'showuserallpokes' ){
					if(listvideoact[i+1] != 'showuserallpokes') {
						newcontent += listvideoact[i+1] ; 
					} else {
						newcontent = newcontent ; 
					}
				} else if( rs == 'userallpokes' ){
					if(listvideoact[i+1] != 'userallpokes') {
						newcontent += listvideoact[i+1] ; 
					} else {
						newcontent = newcontent ; 
					} 
				} else {
					newcontent += listvideoact[i] ; 
				}
		} 
				
		/******change by sameena*******/
					  
		if(rs == 'monthpokes'){    	
			$('#month').html(newcontent); 
		} else if(rs == 'weekpokes') {    	
			$('#week').html(newcontent);     	
		} else if(rs == 'todaypokes') {    	
			$('#today').html(newcontent);     	
		} 
		
		gadgets.window.adjustHeight();
		
		// Prevent click eventpropagation
		return false;
 }
			
function initPagination() {
		
			var num_entries = (listvideoact.length-1);
			// Create pagination element
			
			/********change by sameena*******/
			
			if(listvideoact[listvideoact.length-1] == 'monthpokes') {
				$("#most_paginate").pagination(num_entries, {
			    num_edge_entries: 1,
			    num_display_entries: 2,
			    callback: pageselectCallback,
			    items_per_page:21
			});
			
			} else if(listvideoact[listvideoact.length-1] == 'weekpokes'){
				$("#week_paginate").pagination(num_entries, {
			    num_edge_entries: 1,
			    num_display_entries: 2,
			    callback: pageselectCallback,
			    items_per_page:21    //change from 12 to 9 again change to 6
			});				
				
			}else if(listvideoact[listvideoact.length-1] == 'todaypokes'){
				$("#today_paginate").pagination(num_entries, {
			    num_edge_entries: 1,
			    num_display_entries: 2,
			    callback: pageselectCallback,
			    items_per_page:21
			});				
				
			} else {
				$("#Pagination_shtop").pagination(num_entries, {
			    num_edge_entries: 1,
			    num_display_entries: 2,
			    callback: pageselectCallback,
			    items_per_page:21
			});		
							
			} 
			
	}