function Clear_field(form, field) {
 str = "document." + form + "." + field + ".value = \"\";"
 eval(str);
}

function nonEmpty(form, field, fieldval) {
	strr = "document." + form + "." + field + ".value == \"\";"
	strp = "document." + form + "." + field + ".value = \"" + fieldval + "\";"
	if(eval(strr)) {
		eval(strp)
	}
}

function genmString() {
	var uniqseed = new Date();
	var uniquid_a = uniqseed.toString();
	document.emailist.tsmp.value = uniquid_a;
	var uniquid_b = MD5(uniquid_a);
	document.emailist.tsmpmd.value = uniquid_b;
	//alert(uniquid_a);
	/*var uniquid_b = MD5(uniquid_a);
	var bigstring1o = uniquid_b + 'a1';
	var bigstring1 = MD5(bigstring1o);
	var bigstring2o = uniquid_b + 'y3';
	var bigstring2 = MD5(bigstring2o);
	var bigstring3o = uniquid_b + 'u6';
	var bigstring3 = MD5(bigstring3o);
	var bigstring4o = uniquid_b + 'p8';
	var bigstring4 = MD5(bigstring4o);
	var bigstring5o = uniquid_b + 'g4';
	var bigstring5 = MD5(bigstring5o);
	var bigstring6o = uniquid_b + 'z9';
	var bigstring6 = MD5(bigstring6o);
	var bigstring7o = uniquid_b + 'd0';
	var bigstring7 = MD5(bigstring7o);
	var bigstring8o = uniquid_b + 'c0';
	var bigstring8 = MD5(bigstring8o);
	var bigstr_a = (bigstring1 + bigstring2 + bigstring3 + bigstring4 + bigstring5 + bigstring6 + bigstring7 + bigstring8);
	document.write('<input type="hidden" name="bigstr_b" value="' + bigstr_a + '">');*/
	}
	
function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}

function xMailadd(lang_alert) {
	var e = document.emailist.dmail.value;
	genmString();
	if(check_email(e)) {
		document.emailist.submit();
		//alert('jepp!');
		} else {
		alert(lang_alert);
	}
}

function doOutset(icon) {
	icon.style.border="2 outset #EEEEEE";
	//icon.style.background="#FFFFFF";
	icon.style.cursor="hand";
}

function doClick(icon) {	
	icon.style.border="2 inset #EEEEEE";
}

function doReset(icon) {
	icon.style.border="2 solid #FFFFFF";
	//icon.style.background="";
}

var clockid=new Array()
var clockidoutside=new Array()
var i_clock=-1
var thistime= new Date()
var hours=thistime.getHours()
var minutes=thistime.getMinutes()
var seconds=thistime.getSeconds()
if (eval(hours) <10) {hours="0"+hours}
if (eval(minutes) < 10) {minutes="0"+minutes}
if (seconds < 10) {seconds="0"+seconds}
var thistime = hours+":"+minutes+":"+seconds


function writeclock_cl() {
	if (document.all || document.getElementById || document.layers) {
		document.write("<span id='clock1' style='position:relative'>"+thistime+"</span>")
	}
}

function clockon() {
	thistime= new Date()
	//alert(thistime);
	hours=thistime.getHours()
	minutes=thistime.getMinutes()
	seconds=thistime.getSeconds()
	if (eval(hours) <10) {hours="0"+hours}
	if (eval(minutes) < 10) {minutes="0"+minutes}
	if (seconds < 10) {seconds="0"+seconds}
	thistime = hours+":"+minutes+":"+seconds
		
	if (document.all) {
		//for (i=0;i<=clockid.length-1;i++) {
			var thisclock="clock1";
			thisclock.innerHTML="cTime: " + thistime
		//}
	}
	
	if (document.getElementById) {
		//for (i=0;i<=clockid.length-1;i++) {
			document.getElementById("clock1").innerHTML="" + thistime
		//}
	}
	var timer=setTimeout("clockon()",1000)
}


function start_clocks() {
clockon();
}

function Clear_ifield(field) {
	var zfield = getElement(field);
	zfield.value= "";
 //eval(str);
}

function handlePicsKeyPress(e) {
if (!e) e = window.event;
	// Triggers on keycode Enter
	if (e && e.keyCode == 13) {
		qUery_pic();
	}
}

function handlePicsCKeyPress(e) {
if (!e) e = window.event;
	// Triggers on keycode Enter
	if (e && e.keyCode == 13) {
		cqUery_pic();
	}
}

function handleArtsCKeyPress(e) {
if (!e) e = window.event;
	// Triggers on keycode Enter
	if (e && e.keyCode == 13) {
		qUery_art();
	}
}

function handlePicsPIDKeyPress(e, pid) {
if (!e) e = window.event;
	// Triggers on keycode Enter
	if (e && e.keyCode == 13) {
		chPpic(pid);
	}
}

function handleFilesrcKeyPress(e) {
if (!e) e = window.event;
	// Triggers on keycode Enter
	if (e && e.keyCode == 13) {
		qUery_file();
	}
}

function handleLoginKeyPress(e) {
if (!e) e = window.event;
	// Triggers on keycode Enter
	if (e && e.keyCode == 13) {
		authc.remove();
		retUserarr();
	}
}

String.prototype.replaceAll = function( 
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
while (intIndexOfMatch != -1){
strText = strText.replace( strTarget, strSubString )
intIndexOfMatch = strText.indexOf( strTarget );
}
return( strText );
}

function retDocidtype(url) {
	var tvarr = new Array();
	if(url.search(/youtube/) != -1) {
		var docid = GetURLParam('v', url);
		tvarr[0] = 'youtube';
		tvarr[1] = 'Youtube video';
		tvarr[2] = 'http://www.youtube.com/watch?v='+docid;
		tvarr[3] = docid;
		tvarr[4] = 'you';
		tvarr[5] = 'http://www.youtube.com/v/';
		tvarr[6] = 'YouTube';
	}
	if(url.search(/google/) != -1) {
		var docid = GetURLParam('docid', url);
		tvarr[0] = 'google';
		tvarr[1] = 'Google video';
		tvarr[2] = 'http://video.google.com/videoplay?docid='+docid;
		tvarr[3] = docid;
		tvarr[4] = 'goo';
		tvarr[5] = 'http://video.google.com/googleplayer.swf?docid=';
		tvarr[6] = '';
	}
	if(url.search(/myspace/) != -1) {
		var docid = GetURLParam('v', url);
		tvarr[0] = '';
		tvarr[1] = 'Myspace video';
		tvarr[2] = 'http://video.google.com/videoplay?docid='+docid;
		tvarr[3] = docid;
		tvarr[4] = 'my';
		tvarr[5] = '';
		tvarr[6] = '';
	}
	if(tvarr[0] == '') {
		alert('Video not supported');
		return "";
		} else {
		return tvarr;
	}
}

function mkEmbed(url, w, h) {
	return '<embed src="'+url+'" type="application/x-shockwave-flash" wmode="transparent" width="'+w+'" height="'+h+'"></embed>';
}

function retUniquid() {
	var uniqseed = new Date();
	var urk = uniqseed.toString();
	var ure = MD5(urk).toString();
	return ure;
}

// The function for opening videowindow
function mkEmbedwin(docid, vtype, w, h) {
	var xtype = 'Video';
	if(vtype == 'youtube') {
		xtype = 'Youtube video';
		var zvidx = 'http://www.youtube.com/v/';
	}
	if(vtype == 'google') {
		xtype = 'Google video';
		var zvidx = 'http://video.google.com/googleplayer.swf?docid=';
	}
	if(vtype == 'myspace') {
		xtype = 'Myspace video';
		var zvidx = '';
	}
	var dox = '<meta http-equiv="Pragma" content="no-cache">\n';
  dox += '<META HTTP-EQUIV="Expires" CONTENT="-1">\n';
	dox += '<link rel="STYLESHEET" type="text/css" href="style/amel.css">\n';
	var pContent = 'Yup';
	var xtHeader = '<html>\n<head>\n<title>Node: '+xtype+'</title>\n'+dox+'</head>\n';
	xtHeader = xtHeader + '<body class="pagebody">\n';
	var xtEnd = '</body>\n</html>';
	pReturn = '<div id="chwrtools" name="chwrtools" class="chwrtools">'+mkEmbed(zvidx+docid, w, h)+'</div>\n';
	windowdprops = 'menubars=no,location=no,toolbars=no,scrollbars=no,resizable=no,status=no,width='+(parseInt(w)+1)+',height='+(parseInt(h)+1)+',top=50,left=50';
	self.name = "c"+retUniquid();
	runvideox = window.open("","d"+retUniquid(),windowdprops);
	with (runvideox.document) {
		open();
		write(xtHeader + pReturn + xtEnd);
		runvideox.focus();
		close();
	}
}

/*
System functions
*/
// Function for storing caret pos
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
// Function for getting page elements, cross browser
function getElement(id) { 
	if (document.getElementById) { // W3C DOM 
		return document.getElementById(id); 
		} else if (document.all) { // IE 4 
		return document.all[id]; 
		} else if (document.layers) { // NS 4 
		return document.layers[id]; 
	} 
} 
// Function for clearing msgfield and link fields
function clean_screen(elm, child1, child2) {
	var exfield = getElement(elm);
	exfield.value= "";
	var exurl = getElement(child1);
	exurl.value = "";
	var exurltext = getElement(child2);
	exurltext.value = "";
}
// Function for removing whitespace from end of text
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// Trimming
function LTrim(str) {
 for (var i=0; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i++);
 return str.substring(i,str.length);
}
function RxTrim(str) {
 for (var i=str.length-1; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i--);
 return str.substring(0,i+1);
}
function Trim(str) {
 return LTrim(RxTrim(str));
}

// Function for checking whitespace
function isWhitespace(charToCheck) {
	var whitespaceChar = " ";
	if(charToCheck == whitespaceChar) {
	return true;
	} else {
	return false;
	}
}

function pVideo(newin, id, xwiname, width, height) {
	xwiname=window.open(newin, xwiname,"resizable=no,scrollbars=no,status=no,width="+width+",height="+height+",top=40,left=40");		
}

function doOutset(icon) {
	icon.style.border="2px outset #FFFFFF";
}

function doReset(icon) {
	icon.style.border="2px solid #FFFFFF";
}