
var g_CurrentlyPullingID = 0;
var m_ImgArray = new Array();

var m_IE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var m_Opera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;


// =======================================================
   function ChooseCity(par_Path) {

       l_Obj = document.getElementById('city_list');
       if (l_Obj.style.display == 'block')
       {
         l_Obj.style.display = 'none';
         return false;  
       }

       if (g_CurrentlyPullingID > 0) {
          alert(QPL_STR_JS_PROCESS_REQ);
          setTimeout('ClearPullID()', 5000);
          return false;
       }

       g_CurrentlyPullingID = -1;
       l_URL = par_Path + '/_index.php?qact=citylist';
           
       $('please_wait').style.display= 'block';
       PullInfo(6, l_URL + '&rand=' + Math.random());  

       return false;
   }
// =======================================================
   function bookmark(title, url) {	
          if (title == undefined)		
              title = document.title;	
         if (url == undefined)		
            url = top.location.href;	
         if (window.sidebar) {		
            window.sidebar.addPanel(title, url, '');	
         } else if (window.opera && window.print) {		
             var t = document.createElement('a');		
             t.setAttribute('rel', 'sidebar');		
             t.setAttribute('href', url);		
             t.setAttribute('title', title);		
             t.click();	
         } else {		
             window.external.AddFavorite(url, title);	
         }	

       return false;
  }

// =======================================================
function makesubmitadv(parActName) {
	var f = document.forms.adv;
	f.qact.value = parActName;
	f.submit();
}
// =======================================================

function ChangePic(par_PicIndex, par_AdvID)
{
var obj = document.getElementById("Big" + par_AdvID);
    obj.src = m_ImgArray[par_AdvID][par_PicIndex];
}
// =======================================================
function checkSubmitSendForm() 
{
  var f = document.forms.email; 

  if ((f.FIO.value == '') ||
      (f.Email.value == '') ||
      (f.Text.value == '')) {
      alert(QPL_STR_JS_FILL_ALL); 
      return false;
  }

  return true;
}

// ==========================================================

function LoadSendCompliant(par_ID, par_Path) {
    
  if (g_CurrentlyPullingID > 0) {
     alert(QPL_STR_JS_PROCESS_REQ);
     setTimeout('ClearPullID()', 5000);
     return false;
  }

  g_CurrentlyPullingID = par_ID;
  l_URL = par_Path + '/_index.php?qact=send_complaint&id=' + par_ID;
      
  $('please_wait').style.display= 'block';
  PullInfo(3, l_URL + '&rand=' + Math.random());  

  return false;
}

// ==========================================================

function DoCommonRequest(par_Request, par_ID) {
    
  if (g_CurrentlyPullingID > 0) {
     alert(QPL_STR_JS_PROCESS_REQ);
     setTimeout('ClearPullID()', 5000);
     return false;
  }

  g_CurrentlyPullingID = par_ID;
  l_URL = par_Request;
      
  $('please_wait').style.display= 'block';
  PullInfo(4, l_URL + '&rand=' + Math.random());  

  return false;
}

// ==========================================================

function RemindTheAd(par_Request, par_ID) {
    
  if (g_CurrentlyPullingID > 0) {
     alert(QPL_STR_JS_PROCESS_REQ);
     setTimeout('ClearPullID()', 5000);
     return false;
  }

  g_CurrentlyPullingID = par_ID;
  l_URL = par_Request;
      
  $('please_wait').style.display= 'block';
  PullInfo(5, l_URL + '&rand=' + Math.random());  

  return false;
}

// ==========================================================

function LoadSendEmailForm(par_ID, pat_Path) {
  
  if ((m_IE) || (m_Opera)) {
     if (g_CurrentlyPullingID > 0) {
        alert(QPL_STR_JS_PROCESS_REQ);
        setTimeout('ClearPullID()', 5000);
        return false;
     }

     g_CurrentlyPullingID = par_ID;
     l_URL = par_Path + '/_index.php?qact=show_email_form&id=' + par_ID + '&ajax=1';
     $('please_wait').style.display= 'block';

     var obj = document.forms["email"];
     if (obj)
     {
       obj.parentNode.removeChild(obj);
     }
         
     PullInfo(2, l_URL + '&rand=' + Math.random());  

     return false;
  } else {
     window.location.href = pat_Path + '/_index.php?qact=show_email_form&id=' + par_ID + '&ajax=0';
  }
}

  // ===================================================

function sort(parCriteria) {
	var f = document.forms.advForm;
	f.SortBy.value = parCriteria;
	f.qact.value = 'search_adv';
	f.submit();

	return false;
}

  // ===================================================

function FindSimiliar(par_ID, pat_Path) {
	var f = document.forms.advForm;
	if ((f != null) && (f.OwnerAdvID != null)) {
                f.OwnerAdvID.value = par_ID;
                f.Folder.value = '-1';
        	f.qact.value = 'similiar';
        	f.submit();
        } else {
          window.location.href= pat_Path + '/_index.php?qact=similiar&Folder=-1&OwnerAdvID=' + par_ID;
        }
	
	return false;
}

  // ===================================================

function makesubmitadvForm(parActName) {
	var f = document.forms.advForm;
	f.qact.value = parActName;
	f.submit();
	return false;
}

  // ===================================================

function ChangeSort() {
	var f = document.forms.advForm;
	var value = f.sort_select.value;

	sort(value.substr(0, value.length-2));
	return false;
}

  // ===================================================

function ChangePage(parPageID) {

	var f = document.forms.advForm;
	f.SortBy.value = f.SortedBy.value;
	f.SortedBy.value = '';
	f.qact.value = 'search_adv';
	f.pg.value = parPageID;
	f.submit();	
	return false;
}

  // ===================================================

function ClearPullID() {
  g_CurrentlyPullingID = 0;
}

  // ===================================================
function ShowShortContent(par_Obj, par_ID, par_State) {
 l_Obj = $(par_ID);

 if (par_State)
   tooltip(par_Obj, l_Obj.innerHTML);
     else
   hide_info(par_Obj);
}

  // ===================================================

function ObtainAdFullContent(par_ID, par_URL) {
  l_Obj = document.getElementById('full' + par_ID);
  if (l_Obj.style.display == 'block') {
      l_Obj.style.display = 'none';

      return false;
  }

  l_Obj = document.getElementById('short' + par_ID);
  if (l_Obj != null) {
      l_Obj.style.display = 'none';
  }

  if (g_CurrentlyPullingID > 0) {
     alert(QPL_STR_JS_PROCESS_REQ);
     setTimeout('ClearPullID()', 5000);
     return false;
  }

  g_CurrentlyPullingID = par_ID;
  $('please_wait').style.display= 'block';
  PullInfo(1, par_URL + '&ajax=1&rand=' + Math.random());  

  return false;
}

  // ===================================================

  function ProcessData(type, reply) {
     $('please_wait').style.display = 'none';

     // show ad
     if (type == 1) {
       l_Obj = document.getElementById('full' + g_CurrentlyPullingID);

       l_Obj.innerHTML = reply;

       l_ListObj = document.getElementById("imglist_" + g_CurrentlyPullingID).innerHTML;

       l_ImgList = l_ListObj.split(",");
       m_ImgArray[g_CurrentlyPullingID] = new Array();

       for (i = 0; i < l_ImgList.length; i++) {
          m_ImgArray[g_CurrentlyPullingID][i] = l_ImgList[i];
       }

       l_Obj.style.display = 'block';
       window.location.href='#reflink' + g_CurrentlyPullingID;
     }

     // show send email form
     if (type == 2) {
       l_Obj = document.getElementById('email_sender' + g_CurrentlyPullingID);
       l_Obj.innerHTML = reply;
     }

     // show compliant result
     if (type == 3) {
       l_Obj = document.getElementById('compliant' + g_CurrentlyPullingID);
       l_Obj.innerHTML = reply;
     }

     // show request result
     if (type == 4) {
        alert(QPL_STR_JS_REQUEST_DONE);
     }

     // show request result
     if (type == 5) {
        alert(reply);
     }

     // show request result
     if (type == 6) {
        l_Obj = document.getElementById('city_list');
        l_Obj.innerHTML = reply;
        l_Obj.style.display = 'block'; 
     }

     g_CurrentlyPullingID = 0;
  }

  // ===================================================

  function ProcessError(type, reply) {
     $('please_wait').style.display = 'none';
     alert(QPL_STR_JS_ADV_ERROR + reply + QPL_STR_JS_ADV_ERROR_REPEAT);

     g_CurrentlyPullingID = 0;
  }


