var pending_change = false;
var pop_window = null;
var isDebug = false;
var uid = null;
var unm = null;
var pwd = null;
var search_results=null;
var fname=null;
var lname=null;
var phone=null;
var genm=null;
var genf=null;
var clock=null;
var calendar=null;
var menu=null;
var body=null;
var modal=null;
var dialog=null;
var winW=0;
var winH=0;
var menuH=48;
var statH=48
var page = "";
var timeout_timer=300;
var prev_search="";
var user_id="";
var acc="";
var next_div="";
var next_page="";
var load_args="";
var iconFolder="default";
var def_dialog_title="Dialog";
var def_dialog_loading="Loading... Please Wait...";

function error(module,message)
{
	alert("Error in " + module.toUpperCase() + " module!\n\n" + message);
	return(false);
}

function checkPending()
{
	if(pending_change)
	{
		if(!confirm("You have made changes that have not been saved.\n\nIf you continue your changes will be lost."))
		{
			return(false);
		}
		pending_change=false;
	}
	return(true);
}

function show_dialog(title,content)
{
	if(title=="")
	{
		dialog_title.innerHTML=def_dialog_title;
	}
	else
	{
		dialog_title.innerHTML=title;
	}
	dialog.innerHTML=content;
	show(modal);
}

function show_ajax_dialog(title,page,parms)
{
	if(title=="")
	{
		dialog_title.innerHTML=def_dialog_title;
	}
	else
	{
		dialog_title.innerHTML=title;
	}
	dialog.innerHTML=def_dialog_loading;
	show(modal);
	return(ajax_load(dialog,page,parms));
}

function ajax_load(container,page,parms)
{
	var cont  = container;
	var t_parms = "ajax=1";
	var txt   = "";
	var ajax  = null;
	var scr   = "";
	var x     = 0;
	var script_pattern = /^.*\<script[^\>]*\>([^\<]*).*$/gi;
	
	if(parms!=undefined) t_parms += "&" + parms;
	
	load_args =  Array.prototype.slice.call(arguments).join(",");
	timeout_timer = 300;
	
	if(page!="timeout") 
	{
		if(!checkPending()) return(false);
	}
	
	try
	{
		if(typeof(cont)=="string")
		{
			cont = document.getElementById(container);
		}
		if(typeof(cont)!="object" | cont==null)
		{
			return(error("load","Invalid container: "+container));
		}
	
		if(typeof(ajax)!="object" | ajax==null)
		{
			if(window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				ajax=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				ajax=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
	catch(er)
	{
		return(error("load","Prep: " + er.message));
	}
	if(typeof(ajax)!="object" | ajax==null)
	{
		return(error("load","Invalid AJAX object"));
	}
	/*
	** Now that the AJAX object has been initialized, lets build the URL
	** and parameters and make the call.
	*/
	try
	{
		txt=cont.innerHTML;
		cont.innerHTML=def_dialog_loading;
//alert("ajax load: " + page + "?" + t_parms);
		ajax.open("POST",page,true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", t_parms.length);
		ajax.setRequestHeader("Connection", "close");
		ajax.onreadystatechange = function()
			{
				if(ajax.readyState==4)
				{
					if(ajax.status==200)
					{
						cont.innerHTML=ajax.responseText;
						src=ajax.responseText.replace(/\n/gi,"");
						if(src.match(script_pattern))
						{
							src=src.replace(script_pattern,"$1");
							if(src!="" & src!=ajax.responseText)
							{
								eval(src);
							}
						}
					}
					else
					{
						cont.innerHTML="Error " + ajax.status + ' ' + page + '<br>' + load_args;
					}
				}
			}
		ajax.send(t_parms);
		return(true);
	}
	catch(er)
	{
		cont.innerHTML=txt;
		return(error("load","Call: " + er.message));
	}
}

function showhide(id)
{
	var obj=null;
	try
	{
		if(typeof(id)=="object")
		{
			obj=id;
		}
		else
		{
			obj=document.getElementById(id);
		}
		if(obj!=null)
		{
			if(obj.style.display=="none")
			{
				obj.style.display="";
			}
			else
			{
				obj.style.display="none";
			}
		}
	}
	catch(er)
	{
		// ignore errors
	}
}

function hide(id)
{
	var obj=null;
	try
	{
		if(typeof(id)=="object")
		{
			obj=id;
		}
		else
		{
			obj=document.getElementById(id);
		}
		if(obj!=null)
		{
			obj.style.display="none";
			if(obj.id=='modal') 
			{
				dialog.innerHTML=def_dialog_loading;
				dialog_title.innerHTML=def_dialog_title;
			}
		}
	}
	catch(er)
	{
		error("hide",er.message);
	}
}

function show(id)
{
	try
	{
		if(typeof(id)=="object")
		{
			id.style.display="";
		}
		else
		{
			var obj=document.getElementById(id);
			if(obj!=null) obj.style.display="";
		}
	}
	catch(er)
	{
		error("show",er.message);
	}
}

function setfocus(id)
{
	try
	{
		if(typeof(id)=="object")
		{
			id.focus();
		}
		else
		{
			var obj=document.getElementById(id);
			if(obj!=null) obj.focus();
		}
	}
	catch(er)
	{
		error("focus",er.message);
	}
}

function popup(link,width,height)
{
	try
	{
		pop_window.close();
	}
	catch(er)
	{
		// ignore any error
	}
	
	try
	{	
		pop_window = window.open(link.href,"info","width="+width+",height="+height+"status=0,toolbar=0,scrollbars=1,resize=1");
	}
	catch(er)
	{
		// ignore any error
	}
	
	return(false);
	
}

function getWindowSize()
{
	if(document.body.clientWidth)
	{
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}
	else if(window.innerWidth)
	{
		winW = window.innerWidth;
		winH = window.innerHeight;
	}
	else if(document.documentElement.clientWidth)
	{
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	}
	else
	{
		window.onresize = null;
		alert("Can't calculate window size");
		winW = 800;
		winH = 600;
	}
	menu.style.height=menuH+"px";
	body.style.top=menuH+"px";
	body.style.height=(winH-menuH)+"px";
}

function login(div,page,sales_icons)
{
	var admin_only=0;
	var no_admin=0;
	
	if(!checkPending()) return(false);
	
	show(modal);
	for(x=3;x<arguments.length;x++)
	{
		if(arguments[x]=="admin_only")
		{
			admin_only = 1;
		}
		if(arguments[x]=="no_admin")
		{
			no_admin = 1;
		}
	}
	load(dialog,"login","div=" + div,"page=" + page,"sico=" + sales_icons,"admin_only=" + admin_only,"no_admin=" + no_admin);
}

function ident(div,page,sales_icons)
{
	if(!checkPending()) return(false);
	show(modal);
	load(dialog,"ident","div=" + div,"page=" + page,"sico=" + sales_icons);
}

function get_person(div,page)
{
	if(!checkPending()) return(false);
	show(modal);
	load(dialog,"get_person","div=" + div,"page=" + page);
}

function get_pass(obj,userid)
{
	uid = document.getElementById("uid");
	unm = document.getElementById("unm");
	pwd = document.getElementById("pwd");

	hide("user_list");
	show("user_login");

	uid.value = userid;
	unm.innerHTML = obj.innerHTML;
	pwd.focus();
}

function setBackground(div,style)
{
	var d = document.getElementById(div);
	
	if(d != null) d.style.background=style;
}

function checkDate(obj)
{
	var seg="";
	var str=obj.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim
	var m=0;
	var d=0;
	var y=0;

	if(str=="")
	{
		obj.value="";
		return(true);
	}
	seg=str.split('/');
	if(seg.length==1) str="1/1/0"+seg[0];
	if(seg.length==2) str="0"+seg[0]+"/1/0"+seg[1];
	if(seg.length==3) str="0"+seg[0]+"/0"+seg[1]+"/0"+seg[2];
	tmp = new Date(str);
	if(tmp=='Invalid Date') 
	{
		alert("Invalid Date\n\nCorrect this date or blank out this entry before you continue.\n\nA valid date should look like this: 3/15/2010");
		obj.focus();
		obj.select();
		return(false);
	}
	m=(tmp.getMonth()+1);
	d=tmp.getDate();
	y=tmp.getFullYear();
	if(m<10) m="0"+m;
	if(d<10) d="0"+d;
	obj.value=m+'/'+d+'/'+y;
}

function checkTime(obj)
{
	var h=0;
	var m=0;
	var seg="";
	var str=obj.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim
	
	if(str=="")
	{
		obj.value="";
		return(true);
	}
	str = str.toUpperCase().replace(/(AM|PM)/,":$1");
	if(str.replace(/^[0-9]{1,2}:[0-9]{1,2}:(AM|PM)$/,"") != "")
	{
		tmp='Invalid Date';
	}
	else
	{
		seg=str.split(":");
		h=parseInt(seg[0],10);
		m=parseInt(seg[1],10);		
		if(seg[2]=='PM' & h<12) h=h+12;
		if(seg[2]=='AM' & h==12) h=0;
		seg[0]="00"+h;
		seg[1]="00"+m;
		str = "01/01/1900 "+seg[0].substr(seg[0].length-2)+":"+seg[1].substr(seg[1].length-2)+":00";
		tmp = new Date(str);
	}
	if(tmp=='Invalid Date') 
	{
		alert("Invalid Time\n\nCorrect this time or blank out this entry before you continue.\n\nA valid time should look like this: 1:45pm");
		obj.focus();
		obj.select();
		return(false);
	}
	tHours = tmp.getHours(tmp);
	tMinutes = tmp.getMinutes(tmp);
	timeOfDay = ( tHours < 12 ) ? "am" : "pm";
	tHours = ( tHours > 12 ) ? tHours - 12 : tHours;
	tHours = ( tHours == 0 ) ? 12 : tHours;
	tHours = ( tHours < 10 ? "0" : "" ) + tHours;
	tMinutes = ( tMinutes < 10 ? "0" : "" ) + tMinutes;
	obj.value = tHours + ":" + tMinutes + timeOfDay;
}

function keyPress(e,enter,escape)
{
	var btn = null;
	var key = 0;
	var obj = null;
	var str = "";
	var seg = "";
	var tmp = 0;
	var ch  = "";
	var s   = 0;
	var tMinutes = 0;
	var tHours = 0;
	var timeOfDay = "";

	// look for window.event in case event isn't passed in
	if (window.event) { e = window.event; }
	key=e.keyCode;
            if(!key) ch=String.fromCharCode(e.which);
            if(e.target) 
	{
		obj=e.target 
	}
	else if(e.srcElement)
	{
		obj=e.srcElement;
	}
	if (key == 13 & enter != "")
	{
		btn = document.getElementById(enter);
	}
	else if (key == 27 & escape != "")
	{
		btn = document.getElementById(escape);
	}
	if(btn != null) 
	{
		btn.focus();
		btn.click();
	}
	else if (arguments.length>3 & obj!=null & ch!='')
	{
		if(arguments[3]=='alpha')
		{
			if(ch.replace(/[^a-z]/gi,'')=='') return(false);
		}
		if(arguments[3]=='digits')
		{
			if(ch<'0' | ch>'9') return(false);
		}
		if(arguments[3]=='number')
		{
			str=newValue(obj,ch);
			if(str+'1' != ""+parseFloat(str+'1')) return(false);
		}
		if(arguments[3]=='money')
		{
			obj.onblur=function()
			{
				str=obj.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim
				if(str=="")
				{
					obj.value="";
					return(true);
				}
				obj.value=parseFloat(str).toFixed(2);
			}
			str=newValue(obj,ch);
			if(str+'1' != ""+parseFloat(str+'1')) return(false);
			if(str.indexOf(".")>=0 & str.indexOf(".")<str.length-3) return(false);
		}
		if(arguments[3]=='date')
		{
			str=newValue(obj,ch);
			seg=str.split('/');
			if(seg.length==1) str="1/1/0"+seg[0];
			if(seg.length==2) str="0"+seg[0]+"/1/0"+seg[1];
			if(seg.length==3) str="0"+seg[0]+"/0"+seg[1]+"/0"+seg[2];
			tmp = new Date(str);
			if(tmp=='Invalid Date') return(false);
		}
		if(arguments[3]=='time')
		{
			if(ch.replace(/[^0-9:apm]/gi,'')=='') return(false);
		}
	}
}

function undoChange(img)
{
	var fld_base = img.id.substr(5);
	var fld = document.getElementById(fld_base)
	img.style.display='none';
	document.getElementById('blnk_'+fld_base).style.display="";
	fld.value=document.getElementById('orig_'+fld_base).value;
	fld.focus();
}

function changed(div)
{
	var flds = null;
	var fld  = 0;
	var fld1 = null;
	var fld2 = null;
	var v1 = "";
	var v2 = "";
	var haschanged = false;
	var fld_base = "";
	
	if(typeof(div)=="string") div = document.getElementById(div);
	if(flds=null) return(false);
	flds = div.getElementsByTagName('input');
	for(fld in flds)
	{
		if(flds[fld].id && flds[fld].id.substr(0,5)=='orig_')
		{
			fld_base = flds[fld].id.substr(5);
			fld1 = flds[fld];
			fld2 = document.getElementById(fld_base);
			v1=fld1.value;
			v2=fld2.value;
			if(v1.match(/[0-9]{3}-[0-9]{3}-[0-9]{4}/))
			{
				v1=v1.replace(/[^0-9]/g,'');
				v2=v2.replace(/[^0-9]/g,'');
			}
			if(v1==v2)
			{
				document.getElementById('undo_'+fld_base).style.display="none";
				document.getElementById('blnk_'+fld_base).style.display="";
			}
			else
			{
				haschanged=true;
				document.getElementById('undo_'+fld_base).style.display="";
				document.getElementById('blnk_'+fld_base).style.display="none";
			}
		}
	}
	pending_change=haschanged;
	save_btn=document.getElementById(div.id+"_save");
	if(save_btn!=null)
	{
		if(haschanged)
		{
			save_btn.style.display="";
		}
		// Once displayed, the save button will not go away but the user can cancel.
		// This prevents accidentally hiding the save button.
	}
}
function digitsOnly(obj)
{
	if(typeof(obj)=="string")
	{
		return(obj.replace(/[^0-9]/g,''));
	}
	else
	{
		obj.value = obj.value.replace(/[^0-9]/g,'');
	}
}

function phoneFormat(obj)
{
	digitsOnly(obj);
	var str='0000000000'+obj.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim & Pad
	str=str.substr(-10);
	if(str=='0000000000')
	{
		obj.value='';
	}
	else
	{
		str=str.substring(0,3)+'-'+str.substring(3,6)+'-'+str.substring(6,10);
		obj.value=str;
	}
}

function newValue(obj,txt)
{
	var t = obj.value;
	var s = obj.selectionStart;
	var e = obj.selectionEnd;
	return(t.substring(0,s)+txt+t.substring(e));
}

function person_search()
{
	var f=fname.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim
	var l=lname.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim
	var p=digitsOnly(phone.value).replace(/^0*/,'');
	
	if(prev_search!=f+l+p)
	{
		prev_search=f+l+p;
		load(search_results,"get_person_search","fname="+f,"lname="+l,"phone="+p);
	}
}

function person_add()
{
	var f=fname.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim
	var l=lname.value.replace(/^\s*/, "").replace(/\s*$/, ""); // trim
	var p=digitsOnly(phone.value).replace(/^0*/,'');
	var g='?';

	prev_search="";
	
	if(genf.checked) g='F'; 
	if(genm.checked) g='M';
	
	fname.focus();
	if(f=="" | l=="" | g=="?")
	{
		alert("You need to enter a First Name, Last Name and select a Gender setting.\n\nIf the person doesn't want to give their name, use John Doe or Jane Doe.");
	}
	else
	{
		load(search_results,"get_person_search","fname="+f,"lname="+l,"phone="+p,"gender="+g,"add_person=1","uid="+user_id);
	}	
}

function person_use()
{
	var frm = null;
	var x = 0;
	var y = 0;
	var lst = new Array();
	var chk = search_results.getElementsByTagName("input");
	
	if(chk!=null && chk.length==1 && !chk[0].checked) togleCheck(chk[0]); // If there is only one entry, check it automatically

	frm=buildForm(search_results);	
	if(!frm["person"])
	{
		alert("You need to select a person from the list.");
	}
	else
	{
		hide(modal);
		load(next_div,next_page,"uid="+user_id,"acc="+acc,"pid="+frm["person"]);
	}
	
}

function submitForm(obj)
{
	var flds = null;
	var div = "";
	var cmd = "";
	var fld = "";
	var module = "";
	var action = "";

	if(typeof(obj)=="string") obj=document.getElementById(obj);
	flds=buildForm(obj);
	if(flds==null) return(null);

	if("action" in flds)
	{
		action = flds.action;
		delete flds.action;
	}
	if("module" in flds)
	{
		module = flds.module;
		delete flds.module;
	}
	else
	{
		alert("Module information is missing!\n\nYour information cannot be submitted until this is fixed.");
		return(false);
	}
	if("div" in flds)
	{
		div = flds.div;
		delete flds.div;
	}
	else
	{
		div = obj.id;
	}
	if("validation" in flds)
	{
		if(!eval(flds.validation+"(flds)")) return(false)
		delete flds.validation;
	}
	cmd="load('"+div+"','"+page+"','"+module+"','"+action+"'";
	for(fld in flds)
	{
		if(fld!="")
		{
			cmd+=",'"+fld+"="+flds[fld]+"'";
		}
	}
	cmd+=")";
	pending_change=false; // We are saving so no need to consider the change pending any longer.
	eval(cmd);
}
function buildForm(obj)
{
	var frm = null;
	var flds = {};
	var x = 0;
	var fld_name = "";

	if(typeof(obj)=="string") obj=document.getElementById(obj);
	if(obj==null) 
	{
		alert('Invalid form object');
		return(null);
	}
	frm=obj.getElementsByTagName('input');	
	
	for(x=0;x<frm.length;x++)
	{
		if(frm[x].name=="") 
		{
			fld_name=frm[x].id;
		}
		else
		{
			fld_name=frm[x].name;
		}
		if(fld_name!="")
		{
			if(frm[x].type.toLowerCase()=="checkbox" | frm[x].type.toLowerCase()=="radio")
			{
				if(frm[x].checked)
				{
					if(flds[fld_name]==null)
					{
						flds[fld_name] = new Array();
					}
					flds[fld_name].push(frm[x].value);
				}
			}
			else if(frm[x].type.toLowerCase()!="button")
			{
				flds[fld_name] = frm[x].value;
			}
		}
	}
	frm=obj.getElementsByTagName('select');	
	for(x=0;x<frm.length;x++)
	{
		if(frm[x].name=="") 
		{
			fld_name=frm[x].id;
		}
		else
		{
			fld_name=frm[x].name;
		}
		if(fld_name!="")
		{
			flds[fld_name] = frm[x].value;
		}
	}
	frm=obj.getElementsByTagName('textarea');	
	for(x=0;x<frm.length;x++)
	{
		if(frm[x].name=="") 
		{
			fld_name=frm[x].id;
		}
		else
		{
			fld_name=frm[x].name;
		}
		if(fld_name!="")
		{
			flds[fld_name] = escape(frm[x].value);
		}
	}
	for(x in flds)
	{
		if(typeof(flds[x])=='object' && flds[x] && flds[x].length)
		{
			flds[x]=flds[x].join(',');
		}
	}
	return(flds);
}

function updateClock()
{
	var currentTime = new Date();
	var currentHours = currentTime.getHours();
	var currentMinutes = currentTime.getMinutes();
	var currentSeconds = currentTime.getSeconds();
	var timeOfDay = "";
  
  	if(clock!=null)
  	{
		currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
		currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
		timeOfDay = ( currentHours < 12 ) ? "am" : "pm";
		currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
		currentHours = ( currentHours == 0 ) ? 12 : currentHours;
//		clock.innerHTML = currentHours + ":" + currentMinutes + ":" + currentSeconds + timeOfDay;
		clock.innerHTML = currentHours + ":" + currentMinutes + timeOfDay;
		setTimeout("updateClock()",30000);
	}
	if(calendar!=null)
	{
		calendar.innerHTML  = (1+currentTime.getMonth())+"/";
		calendar.innerHTML += currentTime.getDate()+"/";
		calendar.innerHTML += currentTime.getFullYear();
	}
}

function Collection() 
{
	var collection = {};
	var order = [];

	this.add = function(property, value) 
	{
		if (!this.exists(property)) 
		{
			collection[property] = value;
			order.push(property);
		}
	}
	this.remove = function(property) 
	{
		collection[property] = null;
		var ii = order.length;
		while (ii-- > 0) 
		{
			if (order[ii] == property) 
			{
				order[ii] = null;
				break;
			}
		}
	}
	this.toString = function() 
	{
		var output = [];
		for (var ii = 0; ii < order.length; ++ii) 
		{
			if (order[ii] != null) 
			{
				output.push(collection[order[ii]]);
			}
		}
		return output;
	}
	this.getKeys = function() 
	{
		var keys = [];
		for (var ii = 0; ii < order.length; ++ii) 
		{
			if (order[ii] != null) 
			{
				keys.push(order[ii]);
			}
		}
		return keys;
	}
	this.update = function(property, value) 
	{
		if (value != null) 
		{
			collection[property] = value;
		}
		var ii = order.length;
		while (ii-- > 0) 
		{
			if (order[ii] == property) 
			{
				order[ii] = null;
				order.push(property);
				break;
			}
		}
	}
	this.exists = function(property) 
	{
		return collection[property] != null;
	}
}

function togleCheck(chk)
{
	var img=null;
	var inp=null;
	var x=0;
	
	if(typeof(chk)=="string") chk=document.getElementById(chk);
	if(chk!=null)
	{
		chk.checked=!chk.checked; 
		img=document.getElementById("chk_"+chk.value);

		if(img!=null)
		{
			if(chk.checked) 
			{
				img.src=iconFolder+"/check_16.png"; 
			}
			else  
			{
				img.src=iconFolder+"/uncheck_16.png";
			}
		}
		if(chk.type.toLowerCase()=='radio')
		{
			inp=document.getElementsByTagName('input');
			for(x=0;x<inp.length;x++)
			{
				if(inp[x].name==chk.name & inp[x].type.toLowerCase()=='radio')
				{
					img=document.getElementById("chk_"+inp[x].value);
					if(img!=null)
					{
						if(inp[x].checked) 
						{
							img.src="pics/icons/"+iconFolder+"/check_16.png"; 
						}
						else  
						{
							img.src="pics/icons/"+iconFolder+"/uncheck_16.png";
						}
					}
				}
			}
		}
	}
}

function eventAddHandler(eventSourceId, eventType, func)
{
	var eventSource = null;
	var eventRef = "";
	var eventHandlers = null;
	
	if(typeof(eventSourceId)=="string")
	{
		eventSource = document.getElementById(eventSourceId);
	}
	else
	{
		eventSource = eventSourceId;
	}
	eventRef = eventSource.id + "." + eventType;
	eventHandlers = eval(eventRef);
	if(typeof eventHandlers == 'function') 
	{ 
		// not first handler
		eval(eventRef + " = function() {eventHandlers(); func();}");
	} 
	else 
	{ 
		// first handler
		eval(eventRef + " = func;");
	}
} 

function simClick(id)
{
	var obj=document.getElementById(id);
	if(obj!=null) 
	{
		obj.focus();
		obj.onclick();
	}
}

function setFocus(obj)
{
	if(typeof(obj)=='string') obj=document.getElementById(obj);
	if(obj!=null)
	{
		obj.focus();
		obj.select();
	}
}

function setCookie(c_name,value)
{
	var exdate=new Date();
	if(arguments.length==3)
	{
		exdate.setDate(exdate.getDate()+arguments[2]);
		document.cookie=c_name+ "=" +escape(value)+";expires="+exdate.toUTCString();
	}
	else
	{
		document.cookie=c_name+ "=" +escape(value)
	}
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}



