
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() {
      var l_Obj = document.getElementById('city_list');

          if (l_Obj != null) {
             if (l_Obj.style.display != 'block') { 
                l_Obj.style.display = 'block'; 
             } else {
                l_Obj.style.display = 'none'; 
             }
          }  
   }
// =======================================================
   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, pat_Path) {
    
  if (g_CurrentlyPullingID > 0) {
     alert(QPL_STR_JS_PROCESS_REQ);
     setTimeout('ClearPullID()', 5000);
     return false;
  }

  g_CurrentlyPullingID = par_ID;
  l_URL = pat_Path + '/_index.php?qact=send_complaint&id=' + par_ID;
      
  $('please_wait').style.display= 'block';
  PullInfo(3, 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 = pat_Path + '/_index.php?qact=show_email_form&id=' + par_ID + '&ajax=1';
     $('please_wait').style.display= 'block';
         
     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_ID, par_State) {
 l_Obj = $(par_ID);
 if (l_Obj != null) {
   if (par_State) {
      l_Obj.style.display = 'block';
   }
        else {
      l_Obj.style.display = 'none';
   }
 }
  
}

  // ===================================================

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;
     }

     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;
  }


