	function display_block(block_id, handle){

		var e = document.getElementById(block_id);
		var h = document.getElementById(handle);
		
		if(h.checked)
			e.style.display = 'block';
			else
			e.style.display = 'none';
			
	}
	
	function hide_block(block_id){

		var e = document.getElementById(block_id);

			e.style.display = 'none';
			
	}
	
	function WindowOnload(f) {
	    var prev=window.onload;
	    window.onload=function(){ if(prev)prev(); f(); }
  	}
  	
	var win= null;
	function NewWindow(mypage,myname,w,h,scroll){
		
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
	settings +='resizable=yes';
	win=window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4)win.window.focus();

}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}

function getHTTPObject() {
    var xmlhttp;
  
    if(window.XMLHttpRequest){
      xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject){
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      if (!xmlhttp){
          xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     
     }
    return xmlhttp;
  
  }
var http = getHTTPObject();

   function handleHttpResponse() {   
        if (http.readyState == 4) {
              if(http.status==200) {
              var results=http.responseText;
              document.getElementById(target_div).innerHTML = results;
              //alert(document.getElementById(target_div).innerHTML)
              }
        }
   }
       
   function getRequestedResponseFromPHP() { 
   	
		   	var request_str;
		   	var sId = document.getElementById(from_element_id).value;
		   	
		   	if(own_value != '') request_str = '&own_value=' + own_value;
		   	else request_str = '';
		   	
            http.open(ajax_request_method, url_get + escape(sId) + request_str, true);
            http.onreadystatechange = handleHttpResponse;
            http.send(null);
        }
        
        
  function resetbut(){
  //document.getElementById("state").value='';
  }
  

function SelectMoveRows(SS1,SS2)
{
    var SelID='';
    var SelText='';
    // Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
        if (SS1.options[i].selected == true)
        {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            var newRow = new Option(SelText,SelID);
            SS2.options[SS2.length]=newRow;
            SS1.options[i]=null;
        }
    }
    SelectSort(SS2);
}
function SelectSort(SelList)
{
    var ID='';
    var Text='';
    for (x=0; x < SelList.length - 1; x++)
    {
        for (y=x + 1; y < SelList.length; y++)
        {
            if (SelList[x].text > SelList[y].text)
            {
                // Swap rows
                ID=SelList[x].value;
                Text=SelList[x].text;
                SelList[x].value=SelList[y].value;
                SelList[x].text=SelList[y].text;
                SelList[y].value=ID;
                SelList[y].text=Text;
            }
        }
    }
}

var checkflag = "false";

function check(field) {
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		
		checkflag = "true";
		
		return "Uncheck All"; 
	}
	else {
		
		for (i = 0; i < field.length; i++) {
			field[i].checked = false;
		}
		
		checkflag = "false";
		
		return "Check All"; }
}
//Start Menu
var menu1=new Array()
menu1[0]='<a href="contact_manager.php?action=find_a_contact&amp;info=general" style="color:#FFFFFF;">Contact Information</a>'
//menu1[1]='<a href="contact_manager.php?action=find_a_contact&amp;info=personal" style="color:#FFFFFF;">Personal Information</a>'
menu1[2]='<a href="contact_manager.php?action=find_a_contact&amp;info=groups" style="color:#FFFFFF;">Groups/Interests</a>'
menu1[3]='<a href="contact_manager.php?action=find_a_contact&amp;info=purchase" style="color:#FFFFFF;">Loan Data</a>'
menu1[4]='<a href="contact_manager.php?action=find_a_contact&amp;info=realtor" style="color:#FFFFFF;">Referral Source</a>'
menu1[5]='<a href="contact_manager.php?action=find_a_contact&amp;info=red" style="color:#FFFFFF;">Real Estate Data</a>'
menu1[6]='<a href="contact_manager.php?action=find_a_contact&amp;info=phone" style="color:#FFFFFF;">Phone Numbers</a>'
menu1[7]='<a href="contact_manager.php?action=find_a_contact&amp;info=all" style="color:#FFFFFF;">All</a>'

var menu2=new Array()
menu2[0]='<a href="contact_manager.php?action=send_email&amp;info=text" style="color:#FFFFFF;">Plain Text Email</a>'
menu2[1]='<a href="contact_manager.php?action=send_email&amp;info=mm" style="color:#FFFFFF;">MMaterial Email</a>'

var menuwidth='145px' //default menu width
var menubgcolor='#cc0000'  //menu bgcolor
var disappeardelay=150  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu
//End Menu


function convertToEpoch1( date ){
	
	var splitDate = date.split('/');
	
	var jointDate = new Date(splitDate[2], splitDate[0] - 1, splitDate[1], 0,0,0);
		
	var epochDate = jointDate.getTime()/1000.0;		
		
	return epochDate;		
		
}


function convertToEpoch2( date ){
	
	var splitDate = date.split('/');
	
	var jointDate = new Date(splitDate[2], splitDate[0] - 1, splitDate[1], 23,59,59);
		
	var epochDate = jointDate.getTime()/1000.0;		
		
	return epochDate;		
		
}





function generateReport(date1, date2){

   if ( date1 == '' ){
   	   			
		alert('"From" field is empty');
		return;		
      	   	
   }
   
   if ( date2 == '' ){
   	   			
		alert('"Through" field is empty');
		return;		      	   	
   }      	

   if ( date2 < date1 ){
   	   	
   	   	alert ('You need to enter a valid date range');   	   	
   	   	return;   	   	
   }   		
	
   window.location = 'http://www.prosourcemm.com/adm/contact_manager.php?action=purchase_new_list&date1='+date1+'&date2='+date2;
		
				
}

function toggleElement( id ){
	
	var el = document.getElementById(id);
	el.style.display = (el.style.display != 'none' ? 'none' : 'block' );
}


function ajaxFunction( uid ){
	var ajaxRequest;  
	
	try{
		
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
		
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	ajaxRequest.onreadystatechange = function(){
		//if(ajaxRequest.readyState == 4){
		//	var ajaxDisplay = document.getElementById('ajaxDiv');
		//	ajaxDisplay.innerHTML = ajaxRequest.responseText;
		//}
	}
	//var age = document.getElementById('age').value;
	//var wpm = document.getElementById('wpm').value;
	var state_id = document.getElementById('state').value;
	//alert(state_id);
	var queryString = "?uid="+uid+"&fieldname=state&content="+state_id;
	ajaxRequest.open("GET", "cm/contact_update.php" + queryString, true);
	ajaxRequest.send(null); 
}

function ajaxFunction2( uid , eid , evalue){
	var ajaxRequest;  
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	ajaxRequest.onreadystatechange = function(){
	}
	
	var queryString = "?uid="+uid+"&fieldname="+eid+"&content="+evalue;
	//alert(queryString);
	ajaxRequest.open("GET", "cm/contact_update.php" + queryString, true);
	ajaxRequest.send(null); 
}

function get_mm_id(){
	var params = window.location.search.split('&');
	for(var i=0; i<params.length; i++){
		if(params[i].split('=')[0].search('mm_id') != -1)
			return params[i].split('=')[1];
	}
	return -1;
}

function renamePersonalizedMaterial(){

	$( "#dialog-form" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"Save": function() {

				$.ajax({
					  url: "checkReminders.php",
					  global: false,
					  type: "POST",
					  data: {
								id : get_mm_id(), 
								action: "update_mm_name",
								name: $('#mm_name').val()
							},
					  dataType: "json",
					  success: function(data){
						 if(data.success){
							$("#dialog-form").dialog("close");
							window.location = window.location ;
						 }
						 else
							$( "#error-dialog" ).dialog({
								height: 140,
								modal: true
							});

					  }
				   }
				);
				
			},
			Cancel: function() {
				$( this ).dialog( "close" );
			}
		},
		close: function() {
		}
	});
	
	$("#dialog-form").dialog('open');
}








