﻿// JavaScript Document
var xmlHttp;
//leitourgikothta tou TAB 1
function tab_1_script () {
	show_hide('tab_2', 0);
	show_hide('tab_4', 0);
	show_hide('tab_1', 1);

	show_hide('t1', 0);
	show_hide('t2', 1);
	show_hide('t4', 1);
	show_hide('t1b', 1);
	show_hide('t2b', 0);
	show_hide('t4b', 0);
}
//leitourgikothta tou TAB 2
function tab_2_script () {
	show_hide('tab_1', 0);
	show_hide('tab_4', 0);
	show_hide('tab_2', 1);

	show_hide('t1', 1);
	show_hide('t2', 0);
	show_hide('t4', 1);
	show_hide('t1b', 0);
	show_hide('t2b', 1);
	show_hide('t4b', 0);
}
//leitourgikothta tou TAB 4
function tab_4_script () {
	show_hide('tab_1', 0);
	show_hide('tab_2', 0);
	show_hide('tab_4', 1);

	show_hide('t1', 1);
	show_hide('t2', 1);
	show_hide('t4', 0);
	show_hide('t1b', 0);
	show_hide('t2b', 0);
	show_hide('t4b', 1);
}

//Auti i function emfanizei i kribei ena antikeimeno 
function show_hide(layer_ref, value,adid) {
//prosthiki gia na kanei update sta ratings
if (layer_ref=='tel_hide' && value==1) {
	runscript(adid,2) ;
}

if (value == 1) {
state = 'block';
}
else {
state = 'none';
} 
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}
}

function showTelephone(adID){
	show_hide('tel_show',0);
	show_hide('tel_hide',1, adID);
}

// Elegxos gia tin forma epikoinwnias me ton pwlhth
function check_frm_vendor(p) {
if (p==1) {
	if (document.cont_vend_frm1.email_address.value!='' || document.cont_vend_frm1.telephone_number.value!='')	{
		if ( jcap("captcha1")==1 ) {
		  return true;
		} else {
		  alert("Λάθος Κωδικός !");
		  return false ; 
		}
	}
} else {
	if (document.cont_vend_frm2.email_address.value!='' || document.cont_vend_frm2.telephone_number.value!='')	{
		if ( jcap("captcha2")==1 ) {
		  return true;
		} else {
		  alert("Λάθος Κωδικός !");
		  return false ; 
		}
	}	
}
alert("Παρακαλώ συμπληρώστε τα στοιχεία σας.");
return false;
}

//*****************ajax functions for the image load ******************//
//ajax function show
function showImg(path,p)
{ 
if (p==0) {
	document.image_tab1.src=path;}
else {
	document.image_tab2.src=path;}
	}

//ajax function run
function runscript(adid,p)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="../update_rating.php";
url=url+"?ad_id="+adid;
url=url+"&p="+p; 

xmlHttp.onreadystatechange=stateChanged; 

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

//ajax function checks state
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	//document.getElementById("img_area_big").innerHTML=xmlHttp.responseText;
 } 
}
//ajax function checks state1
function stateChanged1() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	document.getElementById("img_area_big").innerHTML=xmlHttp.responseText;
 } 
}
//ajax function checks state2
function stateChanged2() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	document.getElementById("img_area").innerHTML=xmlHttp.responseText;
 } 
}

//ajax function get
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)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

//save ad script
function saveAd(advert)
{ 
if (advert!=null){
	adid=advert ;
	//alert("Η αγγελία Αποθηκεύτηκε!");
	Message.init();
	//Message.add('This message is just plain.', 'Message', 'sticky');
	Message.add('Η αγγελία Αποθηκεύτηκε!', ' ', 800);
} else {
	//Read tha adid from the parameters
  var p_name = "ad_id";
  p_name = p_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+p_name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );

    adid = results[1];
}
//prosthiki gia na kanei update sta ratings
runscript(adid,1) ;

//cookie name
	var name = "saved_ads";
//read the old cookie
	var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }
//Check if this ad is already stored
cookie_temp = cookieValue ;
while (1==1) {
i = cookie_temp.indexOf('-');
if (i==-1) { 
		cookieValue = cookieValue+adid+"-";
		break; }
if (adid==cookie_temp.substr(0,i)) {break;}
cookie_temp = cookie_temp.substr(i+1); 
}

//save the new cookie
	//ligei se ena mina
    expire = new Date((new Date()).getTime() + 30 * 86400000);

    expire = "; expires=" + expire.toGMTString();


  document.cookie = name + "=" + escape(cookieValue) + expire + ";path=/";
  
  show_hide("ad_save_1",0);
  show_hide("ad_save_2",1);
  show_hide("ad2_save_1",0);
  show_hide("ad2_save_2",1);
}

//report spam script
function rep_spam(adid)
{
	alert("Η αγγελία αναφέρθηκε.");
	runscript(adid,3) ;
}

//Open recomment window
function openit(sURL){
newwindow=open(sURL,"newwin","scrollbars=no, toolbar=no, directories=no, menu bar=no, resizable=yes, status=yes, width=352, height=500");
}

