function pop_div(e) {
	if($("cvv_dialog")) $("cvv_dialog").remove(); 
	
	email_popup = new DivDialogs();
	
	divwidth = 671;

	email_popup.create("Pet Trash Container Dogs");
	email_popup.static_top = "45";
	email_popup.element.obj.id = "cvv_dialog";
	email_popup.element.obj.style.width = divwidth+"px";
	email_popup.element.obj.style.width = divwidth+"px";
	email_popup.element.handle.style.width = "663px";
	email_popup.element.handle.down('div.div_dialog_header_text').style.width = "616px";
	email_popup.element.obj.down('div.div_dialog_content_footer').style.width = "653px";
	email_popup.element.data.style.width = "631px";
	email_popup.element.data.style.height = "810px";
	email_popup.element.data.style.background = "#ffffff";
	email_popup.init();
	
	var clframe  = new Element('img', {src:"pics/pet-trash-bag.gif"});	
	
	email_popup.element.data.update(clframe);
	
	email_popup.show_element(e);
}

function get_document_window_height() {
	if(document.body && document.body.clientHeight &&
			(document.body.clientHeight > 1)) return document.body.clientHeight;
	else if (window && window.innerHeight) return window.innerHeight;
	else if (document.documentElement && document.documentElement.offsetHeight)
		return document.documentElement.offsetHeight;
	else if (document.body && document.body.offsetHeight)
		return document.body.offsetHeight;
	return 0;
}

function get_document_window_width() {
	if (document.body && document.body.clientWidth)
		return document.body.clientWidth;
	else if (window && window.innerWidth) return window.innerWidth;
	else if (document.documentElement && document.documentElement.offsetWidth)
		return document.documentElement.offsetWidth;
	else if (document.body && document.body.offsetWidth)
		return document.body.offsetWidth;
	return 0;
}

function convert_width(width,window_width) {
   if (width == null) width = page_width + 52;
   else if (typeof(width) == 'string') {
      var percent_pos = width.indexOf('%');
      if (percent_pos != -1) width = window_width * (width.substr(0,percent_pos) / 100);
   }
	
   if (! document.all) {
	   if (width > (window_width - 25)) width = window_width - 25;
   }
   else if (width > (window_width - 10)) width = window_width - 10;
   
   return width;
}

function convert_height(height,window_height) {
	if (height == null) height = window_height;
	else if (typeof(height) == 'string') {
		var percent_pos = height.indexOf('%');
	    if (percent_pos != -1) height = window_height * (height.substr(0,percent_pos) / 100);
	}
	
   if (height > (window_height - 40)) height = window_height - 40;

   return height;
}

function calculate_left(width,window_width) {
   var left = (window_width - width) / 2;

   if (! document.all) left += 10;
   if (left < 0) left = 0;
	
   return left;
}

function calculate_top(height,window_height) {
	var top = ((window_height - height) / 2) - 3;
	
	if (top < 0) top = 0;
	
	return top;
}

function get_iframe(id)
{
	var iframe = document.frames ? document.frames[id] : document.getElementById(id);
	var ifWin = iframe.contentWindow || iframe;
	return ifWin;
	
} 

function print_iframe(id)
{
	var ifWin = get_iframe(id);
	ifWin.focus()
	ifWin.print();
	
	return false;
} 


var debug_container = new Element('div', {id:'debug_cont',style:"width:700px;color:#666;background:#fff;overflow:auto;height:200px;"});

var debug_table = new Element('table', {cellpadding:2,cellspacing:1,style:'width:100%;'});
var debug_tbody = new Element('tbody');
var debug_tr    = new Element('tr', {id:'debug_header'});
var function_td = new Element('th',{style:"width:150px;line-height:19px;color:#fff;background:#666;",valign:'top'});
var message_td  = new Element('th',{style:"line-height:19px;color:#fff;background:#666;",valign:'top'});


function show_debug() {	
    		
	function_td.insert("FUNCTION");
	message_td.insert("MESSAGE");

	debug_tr.insert(this.function_td); 
	debug_tr.insert(this.message_td); 
	debug_tbody.insert(this.debug_tr); 
	debug_table.insert(this.debug_tbody); 	
	debug_container.insert(this.debug_table);
	
	dbody.insert(this.debug_container); 
	debug_container.absolutize();
    divDialogs.create_dialog('draggable', 'debug_cont', 'debug_header', null);
}

function add_debug(funct,mess) {
	if(!$('debug_cont'))
		show_debug();
	
	temp_debug_tr    = new Element('tr');
	temp_function_td = new Element('td',{style:"width:100px;line-height:19px;color:#000;background:#ccc;",valign:'top'});
	temp_message_td  = new Element('td',{style:"line-height:19px;color:#000;background:#ccc;",valign:'top'});	
    		
	temp_function_td.insert(funct);
	temp_message_td.innerHTML = mess;

	temp_debug_tr.insert(temp_function_td); 
	temp_debug_tr.insert(temp_message_td); 
	debug_tbody.insert(temp_debug_tr); 
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function select_date(field_name)
{    
    var date_popup = calender_popup[field_name];
    var date_string_field = $(field_name + '_string');
    var date_value = date_string_field.value;
    if (date_value.length != 8) {
       var date_info = date_value.split("/");
       if (date_info.length == 3) {
          if (date_info[0].length == 1) date_info[0] = '0' + date_info[0];
          if (date_info[1].length == 1) date_info[1] = '0' + date_info[1];
          date_string_field.value = date_info[0] + '/' + date_info[1] +
                                    '/' + date_info[2];
       }
    }
    date_popup.select(date_string_field,field_name + '_icon','MM/dd/yy');
    //positon_calendar($(field_name+"_icon"));
}

function parse_date_field(date_string_field,field_name)
{
    var date_value = date_string_field.value;
    var date_field = document.forms[0][field_name];
    if (date_value == '') {
       date_field.value = '';   return;
    }
    var date_info = date_value.split("/");
    if (date_info.length != 3) {
       date_field.value = '';   return;
    }
    var month = parse_int(date_info[0]) - 1;
    var day = parse_int(date_info[1]);
    var year = parse_int(date_info[2]);
    if (year < 70) year += 2000;
    else year += 1900;
    var date_obj = new Date(year,month,day,0,0,0);
    if (isNaN(date_obj)) {
       date_field.value = '';   return;
    }
    date_field.value = date_obj.getTime() / 1000;
}

function parse_int(num)
{
   if (typeof(num) == "undefined") return 0;
   if (isNaN(num)) return 0;
   var int_num = parseInt(num,10);
   if (isNaN(int_num)) return 0;
   return int_num;
}

function process_selected_date(y,m,d)
{
    if (window.CP_targetInput != null) {
       var dt = new Date(y,m - 1,d,0,0,0);
       if (window.CP_calendarObject != null) {
          window.CP_calendarObject.copyMonthNamesToWindow();
       }
       window.CP_targetInput.value = formatDate(dt,window.CP_dateFormat);
    }
    var field_name = window.CP_targetInput.name;
    field_name = field_name.substring(0,field_name.length - 7);
    parse_date_field(window.CP_targetInput,field_name);
}

function format_date_value(date_value)
{
    if (date_value) var date_obj = new Date(date_value * 1000);
    else var date_obj = new Date();
    var month_value = date_obj.getMonth() + 1;
    if (month_value < 10) month_value = '0' + month_value;
    var day_value = date_obj.getDate();
    if (day_value < 10) day_value = '0' + day_value;
    var date_string = month_value + '/' + day_value + '/' +
                      date_obj.getFullYear();
    return date_string;
}

var month_names = ["January","February","March","April","May","June","July",
                   "August","September","October","November","December"];

function format_date_time_value(date_value)
{
    if (date_value) var date_obj = new Date(date_value * 1000);
    else var date_obj = new Date();
    var minutes = date_obj.getMinutes();
    if (minutes < 10) minutes = "0" + minutes;
    var hours = date_obj.getHours();
    var ampm = "am";
    if (hours == 0) hours = 12;
    if (hours > 11) ampm = "pm";
    if (hours > 12) hours -= 12;
    var date_string = month_names[date_obj.getMonth()] + " " + date_obj.getDate() + ", " +
                      date_obj.getFullYear() + " " + hours + ":" + minutes + " " + ampm;
    return date_string;
}

function scEffects() {
	this.options = {
			duration: .5
	}
}

scEffects.prototype.slide_left_in = function(element) {
	new Effect.SlideRightIn(element, this.options); 
}

scEffects.prototype.slide_left_out = function(element) {
	 new Effect.SlideLeftOut(element, this.options); 
}

scEffects.prototype.raise_blind = function(element) {
	new Effect.BlindUp(element, this.options); 
}
		 
scEffects.prototype.lower_blind = function(element) {
	new Effect.BlindDown(element, this.options); 
}
		 
scEffects.prototype.make_fade = function(element) {
	new Effect.Fade(element, this.options); 
}
		 
scEffects.prototype.slide_down = function(element) {
	new Effect.SlideDown(element,this.options); 
}
		 
scEffects.prototype.slide_up = function(element) {
	new Effect.SlideUp(element,this.options); 
}
		 
scEffects.prototype.make_appear = function(element) {
    new Effect.Appear(element,this.options); 
}
		   
scEffects.prototype.toggle_appear = function(element) {			     
	if(element.visible()) new Effect.Fade(element, this.options); 
	else new Effect.Appear(element, this.options); 
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function offset(obj){  
	var divX = obj.offsetLeft;  
	var divY = obj.offsetTop;  
	var parent = obj.offsetParent;  
	while (parent) {  
	  if (parent.offsetLeft) divX += parent.offsetLeft;  
	  if (parent.offsetTop) divY += parent.offsetTop;  
	  parent = parent.offsetParent;  
	}
	return {x:divX,y:divY};
}

/**
* reads a cookie. returns requested cookie name and value
* returns false if not set or not found
*/
function readCookie(cname){
  var str_c = document.cookie;
  var nameEQ = cname + "=";
	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 false;
}
/**
* makes a cookie called cname and a value of val
*/
function createCookie(cname,val,exp,path){
  c = cname+'='+valu+';';
  if(exp){
    c += 'expires='+exp;
  }
  if(path){
    c += 'path='+path;
  }else{
    c += 'path=/';
  }
  document.cookie = c;
}
