checkflds=new Array();
pag_sort=[0,0];
var InfoWind
var TipX=0,TipY=0; //to move DW Tip when IE select box obstructs it
isIE=(window.innerWidth) ? 0 : 1;

function loadtest(){
var d=new Date();
}

function loader(){

/*
var ibuff=document.getElementById("buffer");
var a=ibuff.document.body.innerHTML;
content.write(a);
//content.write( 'pigs do' );
<?php phpALERT("Line 35";include_once("php_loader.inc") ?>

if(!isIE){
var a=document.getElementById("content");	
a.style.marginRight="170px";
}
	if(document.forms[0]){
	var e,i,els=document.forms[0].elements;
	
	//document.forms[0].elements[0].focus()
		
		for (i=0;i<els.length;i++){
		//alert(els[0].id+' is '+els[0].type);
	
		e=els[i].value;
		if ( e && ( e.length==0 || e==null ) ) {els[i].focus();break;}
		}
	}
//alert("jscript 35");
//document.write("<?php phpALERT('Line 37 php'); ?>");
*/
}

function checkform() {
var obj=document.forms[0];
//if(obj.dir!="ltr"){return(true)};
var m="",f="",c="\n",v="",err=0,e,el,i,a;

for (var i=0;i<obj.elements.length;i++){
	el=obj.elements[i];
	if(el.value=="" && el.className=="required"){ 
		if(el.type=='select' && el.options[0].value==''){continue; } //empty select box
			if (el.parentElement){ 
				e=el.parentElement.parentElement.children[0].innerHTML;
			}else{
				e=el.parentNode.parentNode.childNodes[0].innerHTML;
			}
			a=e.indexOf('<');
			if (a != -1){e=e.substring(0,a);}
			m+=c+e;c="\n"
			f=(f=="") ? el.id : f;
		}
	}
if (m!="") {
	alert ("The information below is required:-"+m);
	err=1;
	}
if (!err && "undefined"!=typeof obj.email){
		err=!checkemail(obj.email) 
		}

if (!err && "undefined"!=typeof obj.password){
				err=!checkpass(obj.password) 
		}

if (!err && "undefined"!=typeof obj.password_new){
				err=!checkpass(obj.password_new) 
		}
if (!err){return(true)}
else{putFocus(f);return(false)}
}
//_____________________________________________________________________________________
function focus_out(fld,buff){
var c=fld.className;
var val=fld.value;
var id=fld.id;
c=c.substring(3);
fld.className=c;
//alert(id+" leaving val is "+val);
if (buff&&buff!=""){checkChange(fld,buff)};
}
//_____________________________________________________________________________________

function focus_in(fld,a){
var c=fld.className;
//if(a){alert(fld.id+" is class"+c);}
c="FOC"+c;
fld.className=c;
//fld.select();
return(false);
}

function checkChange(el,buff){
if (buff&&buff!=""){
var ok=1,id=el.id,val=el.value; 

if(ok&&val!=''){
	var ibuff=document.getElementById("buffer") 
	var a='buffer.php?fld='+id+'&val='+val+'&func='+buff;
	//alert(a);
	ibuff.src=a;
	}
	}
return (false);
}

function checkTaken(fld,yn){
//alert(fld+" "+yn);
if (yn!=0){
		el=document.getElementById(fld);
		//el.focus();el.select();
		alert("Sorry, "+fld+' '+el.value+" is already taken.\nPlease try another")
		//el.value="";
		var e="putFocus('"+fld+"')";
		setTimeout(e,0);
	}
return (false);
}		
//_____________________________________________________________________________________

function getObject(id) {
return document.getElementById(id);
}

function toggleBox(link) {
var lText = link.innerHTML;
divId=link.id+"box"
var d = getObject(divId);
	 if (lText == '+') { link.innerHTML = '-'; d.style.display = 'block'; }
	 else { link.innerHTML = '+'; d.style.display = 'none'; }
}


function getRowIndex(cell) {
  return document.all ? cell.parentElement.rowIndex : cell.parentNode.rowIndex;
}

//_____________________________________________________________________________________

function skippage(){
document.forms[0].source.value+="S"
document.forms[0].submit()
}

//_____________________________________________________________________________________

function wordCounter(evt,field,maxlimit,force) { // for use with textareas

var k=keyPressed(evt,0);
if ((!maxlimit||k==0) && !force ){return};
var max=maxlimit;
var V=field.value,wordcounter=k!=0;
V=V.replace(/\s+/g, " ");
var x=0,len=V.length;
var L=document.getElementById("_"+field.id);
	
	if (maxlimit>0){		
		
		if ( k && k>46){return;}
		//window.status=k;
		V=trim(V);
		len=V.length;
			if (len > 0){
				V=ltov(V,' ');
				len=V.length;
				if (maxlimit < len){
				V=V.slice(0,maxlimit);len=maxlimit;
				V=V.join(' ');field.value = V;
				}
			if (k==32){setCaretTo(field,field.value.length );}
			}
		L.value = maxlimit - len;
			
	}else{ //neg limit means count chars
		maxlimit=Math.abs(maxlimit);
		L.value = maxlimit-V.length;
		
		if (len > maxlimit) {
			alert("Limit reached!");
			field.value = field.value.substring(0, maxlimit);
			L.value = 0;
		}
	}
//field.value = V;
}
//_____________________________________________________________________________________


function populate(elem,txt,val){
el = (typeof elem != 'string') ? elem : document.getElementById(elem);
if (!el){ el=document.getElementById(elem+"[]") ; }
if ("|" != txt.charAt(0)) {txt="|"+txt;val="|"+val;}
txt=txt.split("|");val=val.split("|");
var newop,ic;
var O=el.options.length;
var T=txt.length;
var M=Math.min(O,T);
	for(ic=0; ic < M; ic++){
		el.options[ic].text=txt[ic]
		el.options[ic].value = val[ic];
		}
	el.options[0].selected=true;
	if (O >= T){
		for( ic = M; ic < O; ic++ ){el.options[M]=null}
	}else{
		for( ic=M; ic < T; ic++ ){
			newop = new Option();
			newop.value = val[ic];
			newop.text = txt[ic];
			el.options[ic] = newop;
			}
	}
}

function mat_write(mat,i,val){
var a=mat+'['+i+'] = '+val;
alert(a);
//eval (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 checkemail(elem){
	//another version
	//alert("in checkmail");
	var str = (typeof elem == 'string') ? elem : elem.value ; 
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
		testresults=true;
	}else{
		alert("Please check your email address")
		var e=elem.id;
		//alert("179 e is "+e);
		e="putFocus('email')";
		//alert("181 e is "+e);
		setTimeout(e,0);
		testresults=false

	}
	return (testresults)
}

function checkpass(elem){
	var str = elem.value ; 
	var id=elem.id;
	var l=str.length;
	//alert(id+"=id l="+l);
	if ( l==0 && id=="password_new" ){ return(true) }
	
	var filter= /[\W_]/; // allow only letters and numbers
	var err="",ok=true;
	
	if ( (l < 6) || (l > 10) ) {
			
			
			err+= "Your password is " + str.length + " characters long.\n";
			err+= "It must be 6 thru 10 characters long.\n"
			}
	if (filter.test(str)) {
			err+= (err!="") ? "Also it" : "Your password";
			err+= " contains illegal characters.\n";
			err+= "Only letters & numbers please.\n";
			}
	
	if(err!=""){
		ok=false;
		err+= "Have another go.";
		if(obj.dir!="ltr"){err="Wrong Username/Password"};
		elem.focus();
		alert(err)
		//var e="putFocus("+elem+")";
		//setTimeout(e,0);
		}
	
return (ok)
}
//_____________________________________________________________________________________

function selectinfo(fld){
//put following into <select ...  onChange='selectinfo(this.form.$fldname)'
alert (fld.options[fld.selectedIndex].value)
}

//_____________________________________________________________________________________

function str_repeat(s,r){
a="";
for (var i = 0;i < r; i++) {a+=s;}
return (a)
}
//_____________________________________________________________________________________

function putFocus(el) {
if ("object"!=typeof el){el=document.getElementById(el);el.focus();
				if (el.type=='text'){el.select();}
}else{
    	if (document.forms.length > 0) {
			if(document.forms[0].elements[el]){
     			if ("string"==typeof(el)){$i="";
     			}else{$i=((document.forms[0].elements[el].type)=="submit") ? 1:0}
      	document.forms[0].elements[el+$i].focus();
      	}
		}
	}
//return (false);
}

//_____________________________________________________________________________________

function keyPressed(evt,notcursor) {
var K=0;
evt = (evt) ? evt : ((window.event) ? event : null);
    
    if (evt) {
    var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
       if (elem) {
       K = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
       
       	if (notcursor && K>36 && K<41){ K=0; }//ignores cursor movement keys
       }
    }
return K;
}

function keyCheck(ev) {
		var k=keyPressed(ev);
		if (k=='¬'){centerPopUp("getvars.php")};
		if (k=='{'){ };
		if (k=='}'){ };
	}

//_____________________________________________________________________________________
function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}
//_____________________________________________________________________________________


function selchange(el,upfld,buffunc,numb){
var i,c=1,d='',val='',mess='',fld=el.id;

//if(!numb){numb=''}
if (numb){numb='&numb='+numb}else{numb=''}

if (el.multiple){
	for( i=0; i < el.options.length; i++){
		if (el.options[i].selected==true){
			if (el.size < c++){
				alert("You may only select "+el.size);
				el.options[i].selected=false;
				return(0);
			}else{
			val+=d+el.options[i].value; 
			d=',';
			}
		}
	}

}else{

val=el.options[el.selectedIndex].value;

}

	if(buffunc){ 
			if (buffunc=="dummy"){return(0)}; //see e.g. diy_net/docs/db2
			mess='fld='+fld+'&val='+val+numb;
			buffer_send(mess,buffunc);
	}else{	
		if(getObject(upfld) || getObject(upfld+'[]')){
		mess='fld='+fld+'&val='+val;
		buffer_send(mess,'formlink');
		}
	}
}

//_____________________________________________________________________________________
function cat_type_sel(sec,cat,typ){
cat=(!cat) ? 0:cat;
typ=(!typ) ? 0:typ;
//alert(sec+"=sec cat="+cat+" typ="+typ);
//var sel="&sector="+sec+"&category="+cat+"&type="+typ;
//var b='table=cards&flds=pix^star_rate,Make^Model,Description^Detail&'+sel;
var b="listpick="+sec+","+cat+","+typ;
//alert("forms_short.js 351 b is "+b);
buffer_send(b);
//b=sec+","+cat+","+typ;
//document.location.href='index.php?cts='+b
//alert("373 "+b);  
return (false);
}

function cat_type_sel_index(sec,cat,typ){
//cat=(!cat) ? 0:cat;
//typ=(!typ) ? 0:typ;
var b=sec;
if(cat){b+=","+cat;}
if(typ){b+=","+typ;}
document.location.href='index.php?cts='+b
return (false);
}

//_____________________________________________________________________________________
function buffer_send(mess,buffprog,el){
if (mess!=''){
	buffprog=(!buffprog) ? 'pagin_buff' : buffprog;
	//alert(mess+" is mess at 391 prog is "+buffprog);
	//if(el){var e=el.href;alert(e);}
	var ibuff=document.getElementById("buffer");
	var a=buffprog+'.php?'+mess;
	ibuff.src=a;
	return (false);
}
}

//_____________________________________________________________________________________
function buffer_receive(mess,tit,div){
	var a,w;
div=(!div) ? 'content' : div;
//div.write(mess);
//alert("forms_short.js 407 tit is "+tit);
if(tit){document.title=tit};
	a=document.getElementById(div);
	a.innerHTML=mess;
	//w=doc.w-400;
	//a.style.width=w;
	a.style.visibility='visible';
	//alert("340 width="+w);
	if (pag_sort[0]!=0){
	a=document.getElementById(pag_sort[0]);
	a.innerHTML=pag_sort[1];
	}
}
//_____________________________________________________________________________________
function pagin_click(mess){
	//alert("361 "+mess);
	var a,b,c,o=0;
	if ( typeof mess == 'number' ){ mess='start='+mess;
	}else if( 'ordby'==mess.substring(0,5) ){
			a=mess.substring(6);
			if(pag_sort[0]==a && pag_sort[1]=='5'){
				pag_sort[1]='6';
			}else{pag_sort=[a,'5'];}
		//alert(pag_sort[0]+"=a0 355 a1="+pag_sort[1]+" mess is "+mess);
		}
buffer_send(mess);
return (false);
}

function toggle(el){
var i,x,h,nh,L,I,E,J,K,JL;
el = (typeof el != 'string') ? el : document.getElementById(el);
var P=el.parentNode //current menu head
var M=P.parentNode
var C=M.childNodes
L=C.length
	for (i=0;i<L;i++) {

		I=C[i];J=I.childNodes;JL=J.length;

			for (x=0;x<JL;x++){
				if (J[x] && J[x].id){
				J=J[x]
				//alert(I.id+"=I J="+J.id+" J class="+J.className)
				nh="1px";
				h=J.style.height||nh;
				if (I!=P) {nh="1px";}
				else{nh = (h=="auto") ? "1px" : "auto";}
				J.style.height=nh;
				}
			}
	}
return false
}

function getArgs() { 
//var args = new Object(); 
var query = location.search.substring(1); 
return query.split("&"); 
/*
var pairs = query.split("&"); 
for(var i = 0; i < pairs.length; i++) { 
var pos = pairs[i].indexOf('='); 
if (pos == -1) continue; 
var argname = pairs[i].substring(0,pos); 
var value = pairs[i].substring(pos+1); 
args[argname] = unescape(value); 

} 
return args; 
*/
} 

function ltov(L,d,quot){
if ("string"==typeof L){var s=L[0];d=(d)? d : "|";L=L.split(d)}
if (quot){for (var i=0;i<L.length;i++){
		L[i]=quot+L[i]+quot}
	}
return L
}

function vtol(v,d){
if ("array"==typeof v){
	//d=' '//(!d) ? ' ': d;
	v=v.join(d)
	//v=replacer(v,',','Y');
	}
return(v)
}

function trim(str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function replacer(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function setCaretTo(obj, pos) { 
    if(obj.createTextRange) { 
        /* Create a TextRange, set the internal pointer to
           a specified position and show the cursor at this
           position
        */ 
        var range = obj.createTextRange(); 
        range.move("character", pos); 
        range.select(); 
    } else if(obj.selectionStart) { 
        /* Gecko is a little bit shorter on that. Simply
           focus the element and set the selection to a
           specified position
        */ 
        obj.focus(); 
        obj.setSelectionRange(pos, pos); 
    } 
} 