
function get_cookie ( cookie_name ){
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function set_distributor(DistributorIBLink, DistributorID){

new Effect.Move($('dlist'),{x: 0, y: -195, fps:30, mode:'relative'},{ queue: 'end' });
$('viewlist').style.display='block';
$('hidelist').style.display='none';

var exdays = 365;
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(DistributorIBLink) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
var oldDist=get_cookie('Distributor');
document.cookie='Distributor='+c_value;
// alert (get_cookie('Distributor'));

var what = './process.php?action=setDistributor&id='+DistributorID+'&oldDist='+oldDist;
// alert (what); 

new Ajax.Request(what, {
	onComplete: function(response) {
		var results = response.responseText;
		var resultsarray=results.split("~");
		var test=resultsarray[0];
		var distName=resultsarray[1];
		var distContact=resultsarray[2];
		var distPhone=resultsarray[3];
		var distCityState1=resultsarray[4];
		var distCityState2=resultsarray[4];
		document.getElementById('distName').innerHTML=distName;
		document.getElementById('distContact').innerHTML=distContact;
		document.getElementById('distPhone').innerHTML=distPhone;
		document.getElementById('distCityState1').innerHTML=distCityState1;
		document.getElementById('distCityState2').innerHTML=distCityState2;
	}
});

}

function showhide(str) {
	var e = document.getElementById(str);
	if(e.style.display == 'none')
	e.style.display = 'block';
	else
	e.style.display = 'none';
}

function blind(element){
	new Effect.toggle(element,'Blind', {duration:.5});
}

function Submit(url,action,formname) {
	var check=validateContact(formname);
	//alert(check);
	if (check=='yes'){
		var what = url;
		what = what + "?action="+action;
		//alert(what);	
		document.getElementById('SubmitButton').style.display='none';
		document.getElementById('SubmitResponse').style.display='block';
		document.getElementById('SubmitResponse').innerHTML='Submitting <img src=../images/load-bar.gif>';
		
		var form = $(formname)
		var element = form.serialize(); 
		//alert("form.serialize() : " + element.inspect());
			new Ajax.Request(what, {
			method: "post",
			parameters: { data: $(formname).serialize()},
			onComplete: function(response) {
				var results = response.responseText;
				var resultsarray=results.split("~");
				var test=resultsarray[0];
				var where=resultsarray[1];
				var content=resultsarray[2];
				document.getElementById(where).innerHTML=content;
			}
		});
	}
}

function change(url,action) {
	var what = url;
	what = what + "?action="+action;
	//alert(what);	
	
$('p1').stopObserving('mouseout');
$('p2').stopObserving('mouseout');
$('p3').stopObserving('mouseout');
$('p4').stopObserving('mouseout');
$('p5').stopObserving('mouseout');

$('p1').stopObserving('mouseover');
$('p2').stopObserving('mouseover');
$('p3').stopObserving('mouseover');
$('p4').stopObserving('mouseover');
$('p5').stopObserving('mouseover');

$('p1').stopObserving('click');
$('p2').stopObserving('click');
$('p3').stopObserving('click');
$('p4').stopObserving('click');
$('p5').stopObserving('click');

		new Ajax.Request(what, {
		onComplete: function(response) {
			var results = response.responseText;
			var resultsarray=results.split("~");
			var test=resultsarray[0];
			var where=resultsarray[1];
			var content=resultsarray[2];
			document.getElementById(where).innerHTML=content;
			
			if (action=='p1'){
				$('p1').style.cursor='default';
			}else{
				Event.observe($('p1'), 'mouseover', function() {
				$('p1').style.background='rgb(2,3,215)';
				$('p1').style.color='#ffffff';
				});
				Event.observe($('p1'), 'mouseout', function() {
				$('p1').style.background='rgb(255, 191, 0)';
				$('p1').style.color='rgb(2,3,215)';
				});
				Event.observe($('p1'), 'click', function() {
				change('./products.php',this.id);
				});
			}
			
			if (action=='p2'){
				$('p2').style.cursor='default';
			}else{
				Event.observe($('p2'), 'mouseover', function() {
				$('p2').style.background='rgb(2,3,215)';
				$('p2').style.color='#ffffff';
				});
				Event.observe($('p2'), 'mouseout', function() {
				$('p2').style.background='rgb(255, 191, 0)';
				$('p2').style.color='rgb(2,3,215)';
				});
				Event.observe($('p2'), 'click', function() {
				change('./products.php',this.id);
				});
			}
			
			if (action=='p3'){
				$('p3').style.cursor='default';
			}else{
				Event.observe($('p3'), 'mouseover', function() {
				$('p3').style.background='rgb(2,3,215)';
				$('p3').style.color='#ffffff';
				});
				Event.observe($('p3'), 'mouseout', function() {
				$('p3').style.background='rgb(255, 191, 0)';
				$('p3').style.color='rgb(2,3,215)';
				});
				Event.observe($('p3'), 'click', function() {
				change('./products.php',this.id);
				});

			}
			
			if (action=='p4'){
				$('p4').style.cursor='default';
			}else{
				Event.observe($('p4'), 'mouseover', function() {
				$('p4').style.background='rgb(2,3,215)';
				$('p4').style.color='#ffffff';
				});
				Event.observe($('p4'), 'mouseout', function() {
				$('p4').style.background='rgb(255, 191, 0)';
				$('p4').style.color='rgb(2,3,215)';
				});
				Event.observe($('p4'), 'click', function() {
				change('./products.php',this.id);
				});
			}
			
			if (action=='p5'){
				$('p5').style.cursor='default';
			}else{
				Event.observe($('p5'), 'mouseover', function() {
				$('p5').style.background='rgb(2,3,215)';
				$('p5').style.color='#ffffff';
				});
				Event.observe($('p5'), 'mouseout', function() {
				$('p5').style.background='rgb(255, 191, 0)';
				$('p5').style.color='rgb(2,3,215)';
				});
				Event.observe($('p5'), 'click', function() {
				change('./products.php',this.id);
				});
			}

		}
	});

}
