// clean field's text
function cleanText(fm, txt) {
        if (fm.value == txt) fm.value = '';
        return true;
}

// change id and action for item update
function actSubmit(na, ni, act, id)
{
	document.main[na].value = act;
	document.main[ni].value = id;
	document.main.submit();
}
// display html in popop window
function showHTML(str,w,h,pre,bg) {
	bg = bg ? bg : 'eeffdd';
	myWin = window.open("", "HTML", 
	"width="+w+",height="+h+",status=no,resizable=yes,scrollbars=yes,top=200,left=500");
	myWin.document.writeln("<html><title>HTML Preview</title><head>");
	myWin.document.writeln("<link rel=\"stylesheet\" href=\"/php.css\">");
	myWin.document.writeln("</head><body bgcolor="+bg+">");
	if (pre) myWin.document.writeln("<pre>");
	myWin.document.writeln("<font>");
	myWin.document.writeln(str);
	myWin.document.writeln("</font>");
	if (pre) myWin.document.writeln("</pre>");
	myWin.document.writeln("<p align=right><a href=# onclick=\"self.close\(\);\">Close</a>");
	myWin.document.writeln("</body></html>");
	myWin.document.close();
	myWin.focus();
}
				
// declare required windows before hand
var imgWin;
var myWin;
//popup an image window
function imgpop(id,title,W,H)
{
	if (imgWin != null) imgWin.close();
	imgWin = open(id,"IMAGE",'width='+W+',height='+H+',resizable=yes');
	if (imgWin.opener == null) imgWin.opener = self;
	imgWin.document.writeln("<html><title>"+title+"</title>\n");
	imgWin.document.writeln("<body marginwidth=0 marginheight=6 topmargin=6 bottommargin=0 leftmargin=0 rightmargin=0>");
	imgWin.document.writeln("<style type=text/css>\nA:link {font-family: Verdana, Arial, sans-serif;COLOR: #6611C8; TEXT-DECORATION: none;font-size: 12px;}\n");
	imgWin.document.writeln("A:visited {font-family: Verdana, Arial, sans-serif;COLOR: #C81166; TEXT-DECORATION: none;font-size: 12px;}\n</style>\n");
	imgWin.document.writeln("<p align=center><img src=\"/imgload/dumper.php?id="+id+"\"><br><br><br><br>\n");
	imgWin.document.writeln("<table><tr><td><img src=/images/close.jpg align=absmiddle> </td> ");
	imgWin.document.writeln("<td><a href=# onclick=\"self.close\(\);\">Close Window</a></td></tr></table></p>");
	imgWin.document.close();
	imgWin.focus();
	imgWin.resizeTo(W,H);
	return true;

}
//popup windows
function pop(page,title,W,H,s,m,st,t)
{
	if (myWin != null) myWin.close();
	s = s ? s : 'no';
	m = m ? m : 'no';
	st = st ? st : 'no';
	t = t ? t : 'no';
	myWin = open(page,title,'screenX=200,screenY=100,width='+
		W+',height='+
		H+',scrollbars='+
		s+',resizable=yes'
		+',menubar='+
		m+',status='+
		st+',toolbar='+
		t);
	if (myWin.opener == null) myWin.opener = self;
	myWin.focus();
	return true;
}
//popup windows
function mypop(page,title,d,s)
{
	var arr = d.split("-");
	var w = arr[0];
	var h = arr[1];
	//alert(w+"-"+h);
	myWin = open(page,title,'width='+w
	+',height='+h
	+',scrollbars='+s
	+',resizable=no');
	if (myWin.opener == null) myWin.opener = self;
	var NS = (navigator.appName=="Netscape")?true:false;	
	// resize window
	/*
	iWidth = (NS)?myWin.innerWidth:
	myWin.document.body.clientWidth;
	iHeight = (NS)?myWin.innerHeight:
	myWin.document.body.clientHeight;
	myWin.resizeBy(w-iWidth, h-iHeight);
	*/
	myWin.moveTo(200,300);
	myWin.resizeTo(w,h);
	myWin.focus();
	return true;
}

//popup fullsize windows
function bigpop(page)
{
	myWin = open(page);
	if (myWin.opener == null) myWin.opener = self;
	myWin.focus();
	return true;
}
// resizable window
function resizingWindow(w,h){
	if(self.resizeTo)
	{
		self.resizeTo(w, h);
	}
}

var counter = 0;
function refreshMe()
{
	if (++counter == 1) location.reload(true);
	else return false;
}
// populate the focus field
function getFocus(fname,cname)
{
/*	
	var form = false;
	for (i = 0; i < form.length; i++) {
		form = document.forms[i];
		alert(form);
		if (form) break;
	}
	if (!form) return false;
*/

	form = document.forms[fname];

	for (i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		//if (e.type == "password" || 
		if (e.name == cname) {
			e.focus();
			break;
		}
	}
}

function smilie(s) {
	// inserts smilie text
	document.mform.content.value += " "+s;
	document.mform.content.focus();
}

function imagelink(src, img) {
	// inserts images link 
	self.opener.document.mform.content.value += '<img src="'+src+'/'+img+'" border=0>\n';
	self.opener.document.mform.content.focus();
}

// get the days from birth for Jasmine
function borndays(birth,ms)
{
	var ob = birth; 
	var birth = new Date(birth);
	var d = birth.getDate();
	var m = birth.getMonth() + 1;
	var y = birth.getFullYear();
	var strDate = y+'-'+m+'-'+d;
	var today = new Date();
	var diff;
	td = today.getTime();
	bd = birth.getTime();
	if (td > bd) 
	{
		diff = td - bd;
	} 
	else
	{
		diff = bd - td;
	}
	// Number of milliseconds
	var days = Math.floor(diff / (1000 * 60 * 60 * 24 ));
	// Convert to days
	days = days + ms;
	var str;
	if (ob) 
	{
		str = "<a href='./?bday=" + strDate +
			"'><font color=red><b>" + days +
			"</b></font></a>";
	}
	else 
	{
		str = "<a href='./'>" +
			"<font color=blue><b>" + ms +
			"</b></font></a>";
	}
	document.write(str); 
}
// submit form values							
function subMe (fname, field, val)
{
	form = document.forms[fname];
	form.elements[field].value = val;
	form.submit();
}
		
