/* -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

	Function	: miscscripts.js
	Version 	: 1.00
	Last Update	: 04-06-2011  
	Latest CCNo	:
	----------------------------*/


//	alert(Date.parse('2011-02-31'));

// Tue May 03 2011 21:12:24 GMT+0100 (GMT Daylight Time)
/*dd = new Date();
tt = dd.toString();
rr = tt.split(' ');
alert(Date.parse(dd.toString()) + ' ' + dd.toString() + ' ' + rr[0]);*/



function SendField()
{
	arg_in	= arguments.length;

	for ( a=0;a < arg_in; a=a+2 )
	{
		s1 = arguments[a];
		p1 = document.getElementsByName(arguments[a+1]);
		p1[0].value = s1;	
	}
}

function hide_obj(val)
{
	document.getElementById(val).style.visibility = "hidden";
}

function show_obj(val)
{
	document.getElementById(val).style.visibility = "visible";
}

function DisableOnAction(item,val)
{
	axnfld = document.getElementsByName(item);
	arg_in	= arguments.length;
	exp_arg = arguments.callee.length;

	if ( axnfld[0].checked )
	{
		// disable fields
		for ( i=exp_arg;i < arg_in; i++)
		{
			tt = document.getElementsByName(arguments[i]);
			tt[0].disabled = true;
		}
	}
	else
	{
		// enable fields
		for ( i=exp_arg;i < arg_in; i++)
		{
			tt = document.getElementsByName(arguments[i]);
			tt[0].disabled = false;
		}
	}
}

function is_jenabled(val)
{
    return document.state.value = 'true';
}

function setfocuson(next)
{
  // find  obj
 	itm2 = document.getElementsByName(next);
	itm2[0].focus();
	itm2[0].select();
}

function goback($buttonval)
{
	document.writeln("<input type='button' value='" + $buttonval + 
					"' alt ='Click this OK Button' onclick='history.back()'/>")
}

//	----------------------------------

function writeclose(mode)
{
	txt = '[ ';
	switch (mode)
	{
		case 'cp':				
			if ( window.history.length > 1 )
				txt = txt + "<b>&laquo</b><a href='javascript:history.back();' title='Back'>Back</a> | ";
			txt =  txt + "<a href='javascript:window.print();' title='Print this document'>Print</a> | ";
			txt = txt + "<a href='javascript:window.close();' title='Close window'>Close</a>";
			break;

		default:					
			txt = txt + "<a href='javascript:window.close();' title='Close window'>Close</a>";
			break;
	}
	txt = txt + ' ]';
	document.writeln(txt);
}

//	----------------------------------

function tabfocus(obj)
{
	obj.style.border = '2px dashed #FFD700';
}

//	----------------------------------

function nofocus(obj)
{
	obj.style.border = 'none';
}

//	----------------------------------

function viewer(pageurl,size)
{

	if (arguments.length != 2)
		size = 'b';

	switch (size)
	{
		case 's':				//	--	small
			wid = 400;
			hei = 300;
			break;

		case 'm':				//	--	medium
			wid = 550;
			hei = 450;
			break;

		default:					//	-- large
			wid = 750;
			hei = 650;
			break;
	}

 	OpenWin = window.open(pageurl, "new",
			"toolbar=No, menubar=No, location=No, scrollbars=Yes, resizable=Yes, width=" + wid +
			", height=" + hei);

}

//	----------------------------------

function resizewin(ww,hh)
{
	rewin=this.resizeTo(ww,hh)
}

//	----------------------------------

function is_spaces(txt)
{
	pattern = /^\s+$/;

	result = pattern.test(txt);
	if (!result)
		return false;
	else
		return true;
}

function tickAll(form_name,name,col,itemcount)
{
// ---- put a tick in all checkboxes

	var max = itemcount + 1;
	var obj = document.forms[form_name];
	var itm, itemname,a;

  	for( i=1; i < max; i++ ) 
	{
		if ( col > 0 )
			itm = name + i + '_' + col;
		else
			itm = name + i;

		obj[itm].checked = true;
	}

 	return true;
}

function untickAll(form_name,name,col,itemcount)
{
// ---- remove a tick in all checkboxes

	var max = itemcount + 1;
	var obj = document.forms[form_name];
	var itm, itemname,a ;

  	for( i=1; i < max; i++ ) 
	{
		if ( col > 0 )
			itm = name + i + '_' + col;
		else
			itm = name + i;
		obj[itm].checked = false;
	}

	return true;
}


function changetrivia(dyvar,itemcnt1,itemcnt2,speed)
{
	var changespeed = speed;
	var passon = dyvar;
	var arraycnt1 = itemcnt1;
	var arraycnt2 = itemcnt2;
	var message;
	var idx;

	if (cnt > arraycnt2) {cnt=0}

	message = newsarray[arraycnt1][cnt];

	a = document.getElementById(passon);
	a.innerHTML = message;
		
	cnt++;
	writespeed=setTimeout('changetrivia("'+ passon + '",' + arraycnt1 + 
				',' + arraycnt2 + ',' + changespeed + ')',changespeed);
}

/*	Image Gallery
*/
function reverse_gallery_state(arrayid, objn)
{
	if ( cntc == (arraycnt-1) )
		cntc = 0;
	else
		cntc++;

	a = document.getElementById(objn);
	a.innerHTML = newsarray[arrayid][cntc];

// setTimeout("'gallery_slideshow(\"" + arrayid + ", " + objn + ", " + cntc + "\")'",10000);
	writespeed=setTimeout('gallery_slideshow('+ arrayid + ',"' 
									+ objn + '",' + cntc + ')',12000);
}

function gallery_slideshow(arrayid, objn, ino)
{
	if ( cntc == arraycnt ) 
		{cntc=0}
//alert(cntc + ' + ' + arraycnt);
//clearTimeout();

	a = document.getElementById(objn);
	a.innerHTML = newsarray[arrayid][cntc];
cntc++;
// setTimeout("'gallery_slideshow(\"" + arrayid + ", " + objn + ", " + cntc + "\")'",10000);
	writespeed=setTimeout('gallery_slideshow('+ arrayid + ',"' 
									+ objn + '",' + cntc + ')',12000);
}
function prev_image(arrayid, objn)
{
	if ( cntc == 0 )
		cntc = arraycnt-1;
	else
		cntc--;

	a = document.getElementById(objn);
	a.innerHTML = newsarray[arrayid][cntc];

// setTimeout("'gallery_slideshow(\"" + arrayid + ", " + objn + ", " + cntc + "\")'",10000);
	writespeed=setTimeout('gallery_slideshow('+ arrayid + ',"' 
									+ objn + '",' + cntc + ')',12000);
}
function next_image(arrayid, objn)
{
	if ( cntc == (arraycnt-1) )
		cntc = 0;
	else
		cntc++;

	a = document.getElementById(objn);
	a.innerHTML = newsarray[arrayid][cntc];

// setTimeout("'gallery_slideshow(\"" + arrayid + ", " + objn + ", " + cntc + "\")'",10000);
	writespeed=setTimeout('gallery_slideshow('+ arrayid + ',"' 
									+ objn + '",' + cntc + ')',20000);
}


