function randomString() 
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  window.open(URLStr, randomString(), 'toolbar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


var Cookie = {
  set: function(name, value, days) {
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
  },
  get: function(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
  },
  erase: function(name) {
	 this.set(name,"",-1);
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};

/*schedule*/
var scheduleRowArray = new Array();
function scheduleRowHighlight(obj)
{	
    
	if(e = Ext.get(obj)){
	
		var data = Ext.decode(e.getAttribute('vidswap:data'));
	
		if(scheduleRowArray.indexOf(data.id) < 0){
	
			Ext.get('tableRow_' + data.id).setStyle('backgroundColor', '#f0f0f2');
			e.removeClass('schedule-checkbox-off');
			e.addClass('schedule-checkbox-on');
			scheduleRowArray.push(data.id);
	
		} else {
	
			Ext.get('tableRow_' + data.id).setStyle('backgroundColor', '');
			e.removeClass('schedule-checkbox-on');
			e.addClass('schedule-checkbox-off');
			scheduleRowArray.remove(data.id);
	
		}
	
		if(scheduleRowArray.length > 0){
		
		    Ext.get('schedule-multi-tools').setDisplayed(true);
		
		} else {
		    
		    Ext.get('schedule-multi-tools').setDisplayed(false);
		    
		}
	
	}

}
var scheduleCheckAllStatus = 0;
function scheduleCheckAll()
{
	var scb = Ext.query('.schedule-checkbox-base');
	if(scb){
		Ext.each(scb, function(obj, i, all){
			if(scheduleCheckAllStatus==1) scheduleRowOff(obj);
			else scheduleRowOn(obj);
		}, this);
	}

    if(scheduleCheckAllStatus==0) scheduleCheckAllStatus=1;
    else scheduleCheckAllStatus=0;

    if(scheduleRowArray.length > 0){Ext.get('schedule-multi-tools').setDisplayed(true);}
	else {Ext.get('schedule-multi-tools').setDisplayed(false);}
}
function scheduleRowOn(obj)
{
	if(e = Ext.get(obj)){
		var data = Ext.decode(e.getAttribute('vidswap:data'));
		
		Ext.get('tableRow_' + data.id).setStyle('backgroundColor', '#f0f0f2');
		e.removeClass('schedule-checkbox-off');
		e.addClass('schedule-checkbox-on');	
		
		if(scheduleRowArray.indexOf(data.playlist_id) < 0) scheduleRowArray.push(data.playlist_id);
	}	
}
function scheduleRowOff(obj)
{
	if(e = Ext.get(obj)){
		var data = Ext.decode(e.getAttribute('vidswap:data'));
		
		Ext.get('tableRow_' + data.id).setStyle('backgroundColor', '');
		e.removeClass('schedule-checkbox-on');
		e.addClass('schedule-checkbox-off');
		
		if(scheduleRowArray.indexOf(data.playlist_id) >= 0) scheduleRowArray.remove(data.playlist_id);
	}
}
/*
constants
*/
Ext.BLANK_IMAGE_URL = '/js/ext/resources/images/default/s.gif';


