//--- DM scripts ©2002 Pas de Deux, www.pdd.nl

// global variables
var explainOrig
var explain = "hej"; // Set To work slide show in IE properly! 13-sept. by Sander Wildenberg

function init()
	{
		// do anything here when page is loaded
		// store original explaintext (this is the text bottomleft)
	}


// set the eplain tekst to given string (this acts like a hint)
function hint(aString){
	if (document.all){	
		if (aString==0){
        	explain.innerHTML = explainOrig
			}
		else{
			explainOrig = explain.innerHTML
			explain.innerHTML = aString
			}
		}
	}
// a general popupWindow
// closes any other window poppe with this script

function popWindow(theURL,width,height) {
  popup=window.open(theURL,'popup','status=no,resizable=yes,scrollbars=yes');
  if (popup.opener == null) popup.opener = self;
  popup.resizeTo(width,height)
  popup.moveTo(100,100)
  popup.focus()
return false
}

// start login layer script
// for showing/hiding/positioning quicklogin...
var hide  = true;
var loginLayer = false;

function logInit(){
	loginLayer = true
}

function redo(){
//alert("redo")
if (loginLayer){
	showhide('loginLayer', 'hidden')
	}
}

function showhide(obj, visState){
	if (obj=="patience"){
		var x = new getObj(obj)
		logo_semi.src="images/main/dm_seq.gif"
	    x.style.left = (document.body.clientWidth/2) - 200 //center the patience layer
		x.style.visibility = visState;
	}

	else
	{
		var x = new getObj(obj)
    	x.style.visibility = visState;
	}
}

function setLyr(obj,lyr)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	if (lyr == 'testP') newY -= 50;
	var x = new getObj(lyr);
	x.style.top = newY + 25;
	x.style.left = newX + 5;
}

function findPosX(obj){
	var curleft = 0;
	if (document.getElementById || document.all){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}


function getObj(name){
 if (document.getElementById){
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all){
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers){
	   if (document.layers[name]){
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else{
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}


//end loginlayer script



//begin functions for HTML editor
function drawAlert(aUrl){
	var OK = confirm("Weet u zeker dat u ... wilt verwijderen uit de database?")
	if (OK){
	window.location=aUrl
	}
	else{
	//nothing yet
	}
}
	var newWindow;
	
	function butOpenWin_onclick(arg)
	{
	var newWindow;
	var WinTop=(screen.height / 2) - 125;
	var WinLeft=(screen.height / 2) - 125;
	var WindowFeatures="resizable=yes,width=650,height=500,status,location,";
	WindowFeatures = WindowFeatures + "left=" + WinLeft + ",";
	WindowFeatures = WindowFeatures + "top=" + WinTop;
	
	var openstring="window.open('../htmledit/editor.html?"+arg+"', 'mywindow', WindowFeatures)";
	
	newWindow = eval(openstring);
	//newWindow =window.open("editor.html?", "mywindow", WindowFeatures);
	}
	
	function butGetText_onclick()
	{
		if (typeof(newWindow)=="undefined" || newWindow.closed == true)
		{
			alert("no window is open");
		}
		else
		{
			var theHtml = "" + newWindow.document.frames("myEditor").document.frames("textEdit").document.body.innerHTML + "";
			document.fHtmlEditor.EditorValue.value = theHtml
		}
	}

	function butPutText_onclick(arg)
	{
		//if (typeof(newWindow)=="undefined" || newWindow.closed == true)
		window_onunload()
		
		//{
			butOpenWin_onclick(arg);
			//alert("no window is open");
		//}
			//var test = eval(arg);
			var test=arg;
			//alert ("test=" + test);
			var test2 = "document.fHtmlEditor."+test+".value";
			//alert ('test2='+test2);
			//var TextToPut=eval(test2);
			//newWindow.document.all.editbar._editor.newDocument();
			//if(TextToPut !="")
			//{
			//	newWindow.document.all.editbar._editor.textEdit.document.write(TextToPut);
			//}
		
	}
	
		function submitform(){
	document.fHtmlEditor.submit();
	}
	
	
function window_onunload()
{
	if (typeof(newWindow)!="undefined")
	{
		if (newWindow.closed==false)
		{
			newWindow.close();
		}
	}
}
//end functions for HTML editor

//begin function 
function deleteadAlert(aUrl){
 var OK = confirm("Weet u zeker dat u deze advertentie wilt verwijderen?")
 if (OK){
 window.location=aUrl
 }
 else{
 //nothing yet
 }
} 
//end function

//begin function
function deletehaveAlert(aUrl){
 var OK = confirm("Weet u zeker dat u dit item wilt verwijderen?")
 if (OK){
 window.location=aUrl
 }
 else{
 //nothing yet
//end function
 }
} 

function gotoUrl(aUrl){
window.location=aUrl
}

//email verifier
 
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 validate(aForm, aField, aCheck) { 
//alert('debug')
var returnValue=false;
if(aCheck){
  if(!check_email(eval(aForm + "." + aField + ".value"))){
   alert("Er is geen geldig emailadres opgegeven");
   eval(aForm + "." + aField + ".focus()");
  }
  else{
   returnValue=true;
   showhide('patience','visible');
   eval(aForm + ".submit()");
  }
}
else{

  if((eval(aForm + "." + aField + ".value"))==''){
    //nothing
  }
  else{

    if(!check_email(eval(aForm + "." + aField + ".value"))){
     alert("Er is geen geldig emailadres opgegeven");
     eval(aForm + "." + aField + ".focus()");
    }
    else{
     returnValue=true;
	 showhide('patience','visible');
     eval(aForm + ".submit()");
    }
  }

}
return returnValue;
}


function validate_tell_a_friend(aForm, aField, aCheck) { 
//alert('debug')
var returnValue=false;
if(aCheck){
  if(!check_email(eval(aForm + "." + aField + ".value"))){
   alert("Er is geen geldig emailadres opgegeven");
   eval(aForm + "." + aField + ".focus()");
  }
  else{
   returnValue=true;
   showhide('patience','visible');
   eval(aForm + ".submit()");
  }
}
else{

  if((eval(aForm + "." + aField + ".value"))==''){
    //nothing
  }
  else{

    if(!check_email(eval(aForm + "." + aField + ".value"))){
     alert("Er is geen geldig emailadres opgegeven");
     eval(aForm + "." + aField + ".focus()");
    }
	
	

    else{
     returnValue=true;
	 showhide('patience','visible');
     eval(aForm + ".submit()");
    }
  }

}
return returnValue;
}



function validate_emails()
{
	
	var returnValue;
	if(document.tellfriendform.email1.value=="" && document.tellfriendform.email2.value=="" && document.tellfriendform.email3.value=="")
	{
		alert("Er is geen emailadres voor een ontvanger opgegeven");
		returnValue=false;
	}
	else
	{
		returnValue=true;
	}
	return returnValue;
}

var gAanbod
var gVraag

function initMarket()
{
gAanbod = aanbodPrijs.innerHTML
gVraag = vraagPrijs.innerHTML

displayPrijs.innerHTML=gAanbod
aanbodPrijs.innerHTML=''
vraagPrijs.innerHTML=''
}

function switchMarket(){
    var market = document.form
	for (var i = 0; i < market.status.length; i++) {
		if (market.status[i].checked) {
			break
		}
	}
	var marketState = (market.status[i].value)

	// now display the right info
	if (marketState==1){
	//gevraagd
	displayPrijs.innerHTML=gVraag
	displayPhoto.innerHTML = ' '
	}
	else{
	//aangeboden
    displayPrijs.innerHTML=gAanbod
	displayPhoto.innerHTML='U kunt een eigen foto bij uw advertentie plaatsen zodra de transactie volledig is voltooid.'
	}
}
