
function getCookie(Name)
{
	var p1,p2;
	var sstr = Name+'=';
  if(document.cookie.length > 0)
  {
  	p1=document.cookie.indexOf(sstr);
    if(p1 != -1)
    {
    	p1 += sstr.length;
      p2 = document.cookie.indexOf(';', p1);
			if(p2 == -1) p2 = document.cookie.length;
    	return unescape(document.cookie.substring(p1,p2));
  	}
	}
	return null;
}

function setCookie(Name, Value, expdays)
{
	if(Value)
	{
		var dat1=new Date();
		dat1.setDate(expdays);
		document.cookie=Name+'='+escape(Value) + ((expdays) ? ';expires=' + dat1.toGMTString() : '' );
	}
	else
	{
		if(getCookie(Name)) document.cookie = Name + '=;expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
}

function hvbt(btx,sw)
{
	btx.className=sw?'btt cpointer':'btt';
}

function wopen(ev,fn1,w1,h1)
{
	var x1,y1;
	x1=ev.clientX+120;
	y1=ev.clientY+30;
	if(x1+w1>screen.availWidth-30) x1=screen.availWidth-w1-30;
	if(y1+h1>screen.availHeight-30) y1=screen.availHeight-h1-30;
	window.open('html/'+fn1+'.htm','_blank','top='+y1+',left='+x1+',height='+h1+',width='+w1+',toolbar=0');
}

function about()
{
	window.open('html/company.htm',null,'top=190,left=100,height=440,width=500');
}

function tchange()		// opdaterer menuen i new_ad
{
	var i1,i2,fld,t1;
	t1 = document.forms['newad'].cat1.value;
	fld = document.forms['newad'].cat2;
	i2 = t1!=0 ? (t1==13 ? 2 : ((t1&3)==2 ? 3 : 1)) : 0;
	fld.length = s1[i2].length;
	fld.selectedIndex = -1;
	for(i1=0; i1 < s1[i2].length; ++i1)
	{
		fld.options[i1].text = s1[i2][i1].substr(3);
		fld.options[i1].value = s1[i2][i1].substr(0,3);
	}
}

function showad(id)
{
	window.open('/ad_show.php?adid='+id,'_blank','location=0,scrollbars=1,top=0,left=0,width=600,height='+screen.availHeight);
}

function hvpict(btx,sw)
{
	btx.className=sw?'frontad frontad_hv':'frontad';
}

function activate_row(id)
{
	if(currow>=0) document.getElementById('rw'+currow).className='highl0';
	document.getElementById('rw'+id).className='highl4';
	currow = id;
}

function o_contact(typ,id)
{
	activate_row(id);
	window.open("/contact.php?id="+id+"&typ="+typ,"_blank","scrollbars=1,top=100,left=270,width=500,height=300");
}

function o_adw(id)
{
//	var c1 = document.body.style.cursor;
//	document.body.style.cursor = 'wait';
	window.open('/ad_show.php?adid='+id,'_blank','scrollbars=1,top=0,left=0,width=600,height='+screen.availHeight);
//	document.body.style.cursor = c1;
}
function o_ad(id)
{
	activate_row(id);
	o_adw(id);
}

function mOPict(ev,id,vis)
{
	var posx = 0;
	var posy = 0;
	if (!ev) var ev = window.event;
	if (ev.pageX || ev.pageY)
	{
		posx = ev.pageX;
		posy = ev.pageY;
	}
	else if (ev.clientX || ev.clientY)
	{
		posx = ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = ev.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	document.getElementById(id).style.visibility=vis?'visible':'hidden';
	document.getElementById(id).style.left=posx+20;
	document.getElementById(id).style.top=posy-60;
}

function rwchange(id,max1)
{
	var i1 = document.forms[0].elements["my"+id].value - 0;
	switch(i1) 
	{
		case -1: 
			alert('"X" vil fjerne annoncen/profilen fra din liste!');
			break;
			
		case 2:
		case 3:
			if(i1 > max1)
			{
				alert(
					'Der er ikke penge nok på din konto til du kan vælge denne mulighed!\n\n'+
					'Du kan indsætte et beløb via menuen "Konto".'
					);
				document.forms[0].elements["my"+id].value = 0;
			}
			break;
	}	
	activate_row(id);
	document.forms[0].elements["c"+id].value|=4;
	globalchange=true;
}

function emailalert()
{
	alert('Du skal indtaste din email-adresse og aktivere din konto, før du kan benytte denne funktion.');
}

function bt_back()
{
	if(globalchange) document.forms[0].save_form.value=1;
}

function myinit(w1)
{
	var i1,elm;
	if(w1.document.forms[0]) switch(w1.document.forms[0].name)
	{
		case 'ad':
			elm = w1.document.forms[0].elements;
			for(i1=0; i1 < elm.length; ++i1) fchange(elm[i1],1);
			globalchange=false;
			break;
		case 'newad':
			// Nedenstående arrays genereres af gen_newad_js.php
			s1=new Array();s1[0]=new Array();
			s1[1]=new Array();s1[1][0]='900Andet';s1[1][1]='015Bil';s1[1][2]='020Billed- og lydanlæg';s1[1][3]='030Bolig/ejendom';s1[1][4]='040Byggematerialer';s1[1][5]='050Båd/skib';s1[1][6]='060Computer og mobil';s1[1][7]='080Dyr';s1[1][8]='090Hvidevare';s1[1][9]='130Møbler/indretning';
			s1[2]=new Array();s1[2][0]='560Personlig kontakt';
			s1[3]=new Array();s1[3][0]='510Job';
			s1[4]=new Array();s1[4][0]='200Ferie og fritid';s1[4][1]='100Landbrugsmaskiner';s1[4][2]='110Musik/film/bøger/blade';s1[4][3]='120Musikinstrumenter/-udstyr';s1[4][4]='140Personlig pleje';s1[4][5]='150Tøj/beklædning';s1[4][6]='160Værktøj';
			tchange();
			w1.document.forms[0].localusr.value=getCookie('localusr');
			break;
		case 'wr_mail':
			window.moveTo(250,80);
			window.resizeTo(500,430);
			break;
	}

  var ai = document.getElementsByTagName('input');
  for(i1=0; i1<ai.length; i1++) switch(ai[i1].getAttribute('type'))
  {
	  case 'submit':
	  case 'button':
	  	switch(ai[i1].className)
	  	{
		  	case 'btt':
  	      ai[i1].onmouseover = function() { this.className='btt_h'; };
		      ai[i1].onmouseout = function() { this.className='btt'; };
		      break;
		  	case 'bt':
		      ai[i1].onmouseover = function() { this.className='bt cpointer'; };
		      ai[i1].onmouseout = function() { this.className='bt'; };
		      break;
		    case 'bt2':
		      ai[i1].onmouseover = function() { this.className='bt2_h'; };
		      ai[i1].onmouseout = function() { this.className='bt2'; };
		      break;
 		    case 'bt_big':
		      ai[i1].onmouseover = function() { this.className='bt_big_h'; };
		      ai[i1].onmouseout = function() { this.className='bt_big'; };
		      break;
      }
      break;
  }
	if(onload_msg.length) alert(onload_msg);
}

function confirm_email(frm1)
{
	return confirm('Du har angivet følgende email-adresse:\n\n' +
					frm1.email.value +
					'\n\nKontrollér venligst, at email-adressen er korrekt,\n'+
					'da du ikke vil kunne logge ind på 123fundet, uden\n' +
					'at aktivere din konto via denne email-adresse.\n\n' +
					'Klik "OK" hvis den er korrekt.\n' +
					'Klik "Annullér" for at rette.');			
}
