var IGAZIROOT='http://deiramarket.com/'
if (window.location.hostname=='ubuntu') 
  var IGAZIROOT='http://ubuntu/dm2/'

// Cross-browser event listener
function listenForEventIn(obj,type,func,bubble) {
	if (obj.addEventListener) {
	obj.addEventListener(type,func,bubble); // For Presto and Gecko
	}
	else if ( obj.attachEvent ) {
	obj.attachEvent("on" + type, func); // For Trident
	}
}
// Window.onload
function csakszam(e)  {
   var k;
   if (e.charCode)	{
	 k = e.charCode; 
	 }
   else if (e.keyCode)	{
	 k = e.keyCode; // For Presto
	 }
   if (k != 37 && k != 38 && k != 39 && k != 40 && k != 35 && k != 46 && k != 8 && k != 36 && k != 9 && k != 13 && k != 45 )  {
	 if ( k < 47 || k > 57 ) {
	   if ( e.preventDefault )  {
		 e.preventDefault(); // For Presto and Gecko
		 }
	   else {
		 e.returnValue=false; // For Trident
	   }
	 }
	}
}
function csakszamesenter(e)  {
   var k;
   if (e.charCode)	{
	 k = e.charCode; 
	 }
   else if (e.keyCode)	{
	 k = e.keyCode; // For Presto
	 }
  if (k != 37 && k != 38 && k != 39 && k != 40 && k != 35 && k != 46 && k != 8 && k != 36 && k != 9 && k != 45 )  {
	 if ( k < 47 || k > 57 ) {
	   if ( e.preventDefault )  {
		 e.preventDefault(); // For Presto and Gecko
		 }
	   else {
		 e.returnValue=false; // For Trident
	   }
	 }
	}
  if (k===13) Web_ID_Search();
}

function intvalid (num) {
  var szam=num.value;
  i=szam.indexOf(".",0);	   
  if (i!=-1) {
     szam=szam.substring(0,i);	  
     num.value=szam;
  }
  var  n='';
  for (var x=0; x<szam.length; x++) {
    if (!isNaN(parseInt(szam.charAt(x)))) {
	   n=n+szam.charAt(x);
	}
  }
  num.value=n;
//  for (var x=0; x<n.length; x++) {
//   if (isNaN(parseInt(n[x]))) {
//      alert ('Only positive integer is allowed ! I think '+num.value+' is not a positive integer ! (but not sure :-))');
//      num.value="";  
//	  break;
//	}
//  }
}

function js_newlocation(l) {
alert(l);
location=l;
}

// EZTET en raktam ide, ez szkrollogtatja a DIVET

scrollStep=2

timerUp=""
timerDown=""

function toTop(id){
document.getElementById(id).scrollTop=0
}

function scrollDivDown(id){
clearTimeout(timerDown) 
document.getElementById(id).scrollTop+=scrollStep
timerDown=setTimeout("scrollDivDown('"+id+"')",10)
}

function scrollDivUp(id){
clearTimeout(timerUp)
document.getElementById(id).scrollTop-=scrollStep
timerUp=setTimeout("scrollDivUp('"+id+"')",10)
}

function toBottom(id){
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}

function stopMe(){
clearTimeout(timerDown) 
clearTimeout(timerUp)
}

// na es itt a vege

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// ezt megin en raktam ide, tooltip

var tooltip=function(){
	var id = 'tt';
	var top = 0;
	var left = 0;
	var maxw = 500;
	var speed = 60;
	var timer = 60;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w,ttleft,tttop){
			if (ttleft == null) {left = 20;} else {left = ttleft;}
			if (tttop == null) {top = -50;} else {top = tttop;}
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
		// For IE6 compatibity - nick 22/08/2008 11:32
		var u = 0, l = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				u = window.pageYOffset;
				l = window.pageXOffset;
				} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
					//DOM compliant
					u = document.body.scrollTop;
					l = document.body.scrollLeft;
					} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
						//IE6 standards compliant mode
						u = document.documentElement.scrollTop;
						l = document.documentElement.scrollLeft;
					}
		u = ie ? event.clientY + u : e.pageY;
		l = ie ? event.clientX + l : e.pageX;
		tt.style.top = (u - h) + 'px';
		tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

// itt a toooltip vege


//--------------------------------------------------FORM.JS----------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//

test=false;

var xmlHttp;

function GetXmlHttpObject() {
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
	try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support HTTP Request !");
      return false;
      }
	}  
  }
return xmlHttp;
}

function showTime()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if (xmlHttp.responseText=='login')
      alert ('You have to log in for this service !');
	if (xmlHttp.responseText) {
      if (document.getElementById('ID_fav'+xmlHttp.responseText).className=='myitem') {
        document.getElementById('ID_fav'+xmlHttp.responseText).className='fav1';
        document.getElementById('ID_fav'+xmlHttp.responseText).title='Add to watch list';
	    alert ('It has been deleted from watch list !');
	    }
	   else {
	    document.getElementById('ID_fav'+xmlHttp.responseText).className='myitem';
        document.getElementById('ID_fav'+xmlHttp.responseText).title='Clear from watch list';
	    alert ('It has been inserted to watch list !');
	  }
	  }
	 else {
	  alert ('Watch list update is failed !');
	}
  }  
}

function runphp(phpName) {
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
   return;
 xmlHttp.onreadystatechange=showTime;
 xmlHttp.open("GET",phpName,true);
 xmlHttp.send(null);
}

function active_response()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if (xmlHttp.responseText=='login')
     alert ('You have to login for this service !');
    if (xmlHttp.responseText=='lejart')
     alert ('Sorry ! This service available for PREMIUM members only ! Please check your profile !');
	if (xmlHttp.responseText) { 
      if (document.getElementById('ID_status'+xmlHttp.responseText).innerHTML=='SUSPEND') {
		document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).innerHTML='SUSPENDED';
        document.getElementById('ID_status'+xmlHttp.responseText).innerHTML='ACTIVATE';
        document.getElementById('ID_status'+xmlHttp.responseText).title='ACTIVATE This Ad';
	    document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).className='status_S';
        document.getElementById('ID_relist'+xmlHttp.responseText).style.display="none";
		alert ("It has been suspended !");
	    }
	   else {
		document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).innerHTML='ACTIVE';
        document.getElementById('ID_status'+xmlHttp.responseText).innerHTML='SUSPEND';
        document.getElementById('ID_status'+xmlHttp.responseText).title='SUSPEND This Ad';
	    document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).className='status_A';
        document.getElementById('ID_relist'+xmlHttp.responseText).style.display="inline";
	    alert ('It has been activated !');
	  }
	 }
	 else {
	  alert ('Item status update is failed !');
	}
  }  
}

function run_php_active (phpName) {
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
   return;
 xmlHttp.onreadystatechange=active_response;
 xmlHttp.open("GET",phpName,true);
 xmlHttp.send(null);
}


function delete_response()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if (xmlHttp.responseText=='login')
      alert ('You have to login for this service !');
	if (xmlHttp.responseText) {
	    document.getElementById('ID_DIV_van_tetel_'+xmlHttp.responseText).style.display="none";
		alert (xmlHttp.responseText+" item has been deleted !");
    }
    else {
	  alert ('Item delete is failed !');
	}
  }
}

function run_php_delete (phpName) {
 if (confirm (' Are you sure to delete item(s) ? ')) {
   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
     return;
   xmlHttp.onreadystatechange=delete_response;
   xmlHttp.open("GET",phpName,true);
   xmlHttp.send(null);
 }
}

function relist_response()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//	alert (xmlHttp.responseText);
    if (xmlHttp.responseText=='login')
      alert ('You have to login for this service !');
	if (xmlHttp.responseText) {
	    document.getElementById('ID_DIV_van_tetel_'+xmlHttp.responseText).style.display="none";
		alert (xmlHttp.responseText+" item has been relisted !");
    }
    else {
	  alert ('Item relist is failed !');
	}
  }
}

function run_php_relist (phpName) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      return;
    xmlHttp.onreadystatechange=relist_response;
    xmlHttp.open("GET",phpName,true);
    xmlHttp.send(null);
}

function setmailalert_response()   {
//  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//      alert (xmlHttp.responseText);
//  }
}

function run_php_setmailalert (phpName) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      return;
    xmlHttp.onreadystatechange=setmailalert_response;
    xmlHttp.open("GET",phpName,true);
    xmlHttp.send(null);
}

function orderformvalidate()  {
  var errorstr=''; 
  if (document.contact.webid.value=='') 
     errorstr='You have to fill the PRODUCT ID field !';
  if (document.contact.phone.value=='')  
     errorstr='You have to fill the phone field !';
  if (errorstr.length>0) 
    alert (errorstr);	
  document.FV_returnValue = (errorstr == '');
}
function wantedformvalidate()  {
  var errorstr=''; 
  if (document.wantedform.Ititle.value=='') 
     errorstr='You have to fill the * fields ! (Title is empty)';
  if (document.wantedform.Idesc.value=='') 
     errorstr='You have to fill the * fields ! (Message is empty)';
  if (errorstr.length>0) {
    alert (errorstr);	
	}
	else {
	 mehet=confirm (' Are you sure to post this message ? ');
	}
  document.FV_returnValue = ((errorstr == '') && (mehet));
}

function itemformvalidate()  {
  var errorstr=''; 
  if (document.itemform.Ititle.value=='') 
     errorstr='You have to fill the * fields ! (Title is empty)';
  if (document.itemform.Iprice.value<1)  
     errorstr='You have to fill the * fields ! (Price is maybe too low :-))';
  if (document.itemform.Iunit.value=='')  
     errorstr='You have to fill the * fields ! (Unit name is empty)';
  if (document.itemform.Imaincat.value=='00')  
     errorstr='You have to fill the * fields ! (Select a Category)';
  if (document.itemform.Isubcat.value=='00')  
     errorstr='You have to fill the * fields ! (Select a Group)';
  if (errorstr.length>0) 
    alert (errorstr);	
  document.FV_returnValue = (errorstr == '');
}

/*
function fitemformvalidate()  {
  var errorstr=''; 
  if (document.findform.Fminprice.value<0) 
     errorstr='Minimum price is too low !';
  if (Number(document.findform.Fminprice.value) > Number(document.findform.Fmaxprice.value)) 
     errorstr='Minimum price more than maximum price !';
  if (errorstr.length>0) 
    alert (errorstr);	
  document.FV_returnValue = (errorstr == '');
}
*/

// feltölti a legördülö kista elemeit a kiválasztott város area-ival ha volt város változás
function madeSelection (r) {
    var selObj  = document.getElementById('ID_subcat');
    var selcity = document.getElementById('ID_maincat').options[document.getElementById('ID_maincat').selectedIndex].value;
	selObj.options.length = 0;   //mindig elöröl kezdjük a töltikét
    var x=0;
	while (x!=-1) { 	
      i=r.indexOf(":", x);	  //x poziciótól keres : -ot r szrtingben 
	  if (i==-1) break;       //ha nincs : kiszáll
	  s=r.substring(x,i);	  //s-be lerajkja a sztringet
	  x=i+1;                  //átugorjuk a kettös pontot    
	  var code=s;                 //remélhetöleg ez a area kódja

      i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var citycode=s;
	  
	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var areaname=s;
	  
      if (test) 
	    qstr=areaname+'-'+citycode+'-'+code
	   else
	    qstr=areaname;
      if (selcity==citycode) { 
       if (typeof(window.clientInformation) != 'undefined') 
         selObj.add(new Option(qstr, code)); 
	    else
         selObj.add(new Option(qstr, code), null); 
	  }
	}
    selObj.selectedIndex=0;  
}

function changeSubcat (r) {
    var selcity = document.getElementById('ID_maincat').options[document.getElementById('ID_maincat').selectedIndex].value;
    var selarea = document.getElementById('ID_subcat').options[document.getElementById('ID_subcat').selectedIndex].value;
    var x=0;
	while (x!=-1) { 	
      i=r.indexOf(":", x);	  //x poziciótól keres : -ot r szrtingben 
	  if (i==-1) break;       //ha nincs : kiszáll
	  s=r.substring(x,i);	  //s-be lerajkja a sztringet
	  x=i+1;                  //átugorjuk a kettös pontot    
	  var code=s;                 //remélhetöleg ez a area kódja

      i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var citycode=s;
	  
	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
      var areaname=s;

      if ((selcity==citycode) && (selarea==code)) {
	  break;
     }
	}
}

function showfilesfield (c) {
// document.getElementById('ID_pic'+c).value='';
 document.getElementById('ID_pic'+c).style.display="inline";
}
function hidefilesfield (c) {
// document.getElementById('ID_pic'+c).value='';
 document.getElementById('ID_pic'+c).style.display="none";
}

function changeFeatcolor (c) {
if (document.getElementById('ID_DIV_check'+c).className=='textbluehoka')
   document.getElementById('ID_DIV_check'+c).className='textgreen';
  else
   document.getElementById('ID_DIV_check'+c).className='textbluehoka';
}



//--------------------------------------------------MAP.JS----------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//

var test=false;
var map;
var is_marker = false;
var marker='none';
var polygon_overlay='none';


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function setloadevent(x,y,z,p) {
  addLoadEvent(map_initialize(x,y,z,p));
  if (window.attachEvent) {
        window.attachEvent("onunload", function() {
                GUnload();      // Internet Explorer
        });
   } else {
        window.addEventListener("unload", function() {
                GUnload(); // Firefox and standard browsers
        }, false);
  }
}  

function map_initialize(center_lat, center_lng, zoom_level, polygon) {
 //center_lat=25.077200666275154;
 //center_lng=55.140380859375;
 if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(center_lat, center_lng), eval(zoom_level));
  map.addControl(new GMapTypeControl());
  map.addControl(new GSmallMapControl());
  maplat=document.getElementById("ID_maplat").value;
  maplng=document.getElementById("ID_maplng").value;
  clickmarker_func =function(latlng) {
									  map.openInfoWindowHtml(latlng, "It's a property location ! It's nice place !");
						 	   }
  dragmarker_func = function(latlng) {     
 								       var marker_latitude=latlng.lat();
								       var marker_longitude=latlng.lng();
								       document.getElementById("ID_maplat").value=marker_latitude;
								       document.getElementById("ID_maplng").value=marker_longitude;
 								       //alert (marker_latitude+' kint '+marker_longitude);
								     }
  drg=false;
  if (document.getElementById("ID_mapdrg").value==true)
    drg=true
  if ((maplat!=0) && (maplng!=0)) {
	markerpoint=new GLatLng(maplat, maplng);
	marker = new GMarker(markerpoint, {draggable: drg})
    //GEvent.addListener (marker, "click", clickmarker_func);
    GEvent.addListener(marker,"dragend", dragmarker_func);
    map.addOverlay(marker);
	is_marker=true;
  }
  
  setmarker_func = function(overlay, latlng) {     
                     if ( (latlng) && (document.getElementById("ID_mapdrg").value==true) ) { 
                       if (is_marker) {
                         map.removeOverlay(marker);
                       } 
                       drg=false;
      			       if (document.getElementById("ID_mapdrg").value==true)
					      drg=true
					   marker = new GMarker(latlng, {draggable: drg})
                        clickmarker_func =function(latlng) {
					                                      map.openInfoWindowHtml(latlng, "It's a property location ! It's nice place !");
					                                     }
					   dragmarker_func = function(latlng) {     
														   var marker_latitude=latlng.lat();
														   var marker_longitude=latlng.lng();
														   document.getElementById("ID_maplat").value=marker_latitude;
														   document.getElementById("ID_maplng").value=marker_longitude;
														   //alert (marker_latitude+'  bent '+marker_longitude);
														  }
					    GEvent.addListener (marker, "click",   clickmarker_func);
                        GEvent.addListener (marker, "dragend", dragmarker_func);
                       map.addOverlay(marker);
					   is_marker=true;
                       var marker_latitude=latlng.lat();
                       var marker_longitude=latlng.lng();
                       document.getElementById("ID_maplat").value=marker_latitude;
                       document.getElementById("ID_maplng").value=marker_longitude;
                       //alert (marker_latitude+'   '+marker_longitude);
                     }
                   };
  
    GEvent.addListener(map,"click", setmarker_func);
	if (polygon!=0) {
	  var encodedPoints = polygon; //"}fbxCc{roIzh@rp@f_B`tAop@b_Ay|Bm~AqOeWUyWju@mu@";
	  var encodedLevels = "B";
	  polygon_overlay = new GPolyline.fromEncoded({
							  color: "#FF0000",weight: 4,opacity: 0.4,points: encodedPoints,levels: encodedLevels,zoomFactor:32, numLevels: 4 });
	  map.addOverlay(polygon_overlay);
	}

 } 
}

function login_kell() {
	alert ("Please login first or register !");
}

function form_on(){
	document.getElementById('desc').style.display='none';
	document.getElementById('contact').style.display='none';
	document.getElementById('formcontactus').style.display='block';
	document.getElementById('formcontactus').style.visibility='visible';
}
function form_off(){
	document.getElementById('formcontactus').style.display='none';
	document.getElementById('formcontactus').style.visibility='hidden';
	document.getElementById('desc').style.display='block';
	document.getElementById('contact').style.display='block';
}
function login() {
	var loginForm = document.getElementById("loginForm");
	if (loginForm.username.value == "") {
		alert("Please enter your E-mail.");
		return false;
	}
	if (loginForm.password.value == "") {
		alert("Please enter your password.");
		return false;
	}
	loginForm.submit();
}
function Web_ID_Search(){
	var WID = document.getElementById('Web_ID_Input').value;
	if (WID == "") {
		alert("Please enter an PRODUCT ID number !");
		return false;
	}
	location=IGAZIROOT+WID;
}

function change_find(c,t,l){
	if (!l)
	  login_kell();
	 else 
	  location=IGAZIROOT+'dubai/wholesaler/searchupdate.php?cfc='+c+'&cft='+t;
}

function delete_find(l,m){
	if (!l)
	  login_kell();
	 else 
	  location=IGAZIROOT+'dubai/wholesaler/searchupdate.php?dfc='+m;
}
function new_location_login(l,m){
	if (!l)
	  login_kell();
	 else 
	  location=m;
}
function email_mehet(l){
	if (!l)
	  login_kell();
	 else 
	  form_on();
}

function form_mehet(l){
	if (!l) {
	  login_kell();
	}
	 else {
	 formvalidate();
	 }
}

function FindFormSubmit(s, m) {
	if (s=='F')
	  document.getElementById('first').value=1;
	if (s=='L') {
	  document.getElementById('last').value=1;
	  document.getElementById('oldpagecount').value=m;
	}
	if (s=='G') 
	  document.getElementById('mutat').value=m;
	if (s=='N') {
	  document.getElementById('next').value=1;
	  document.getElementById('oldmutat').value=m;
	}
	if (s=='P') {
	  document.getElementById('prev').value=1;
	  document.getElementById('oldmutat').value=m;
	}
	document.findform.submit();
}


