var MainWindow=false;
Number.prototype.isInteger = function() {
  return this==Math.round(this);
} 

function EmailCheck(email)
{
  var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
  return emailfilter.test(email);
}

function AjaxResponse(text,exec)
{
  //alert(text);
  if (!exec) exec = false;
  var msg = text.substr(0,3);
  var textcut = text.substr(4);
  if (msg == 'OKE')
    eval(textcut);
  else
  if (msg == 'OKI');
  else
  if (msg == 'OKS')
    error(textcut,'OK');
  else
  if (msg == 'ERE')
    eval(textcut);
  else
  if (msg == 'OKM' && exec)
    eval (exec);
  else
  if (msg == 'ERR' && exec)
    eval (exec);
  else
    error(text);
}

function error(text,sign)
{
  if (!text)
    text ='ERROR! Please contact the administration';
  if (!sign) sign = 'error';
  //make_confirmation('<img src="/img/err.gif" style="float:left;">'+text+'</a>!',260,110,'','OK!');
  //alert(text);
  MakeConfirmation('<img src="/img/'+sign+'.gif" style="float:left;" width="48" height="48">'+text,400,300,'','OK');
}


function refresh_authcode()
{
  var seed = Math.random();
  seed = seed * 1000000;
  seed = Math.ceil(seed);
  document.getElementById('authimg').src='/authcode.php?seed='+seed;
}

function setWrong(obj,cls)
{
  obj.className = cls+' '+cls+'_wrong';
}

function setRight(obj,cls)
{
  obj.className = cls;
}

function incor_authcode()
{
  document.getElementById('posterror').style.visibility="visible";
  document.getElementById('posterror').innerHTML = 'Incorrect confirmation code!.';
  setWrong(document.getElementById('authcode'));
  document.getElementById('authcode').value = '';
  alert('Wrong Confrimation Code!\n\r Please Try Again!');
  refresh_authcode();
  document.getElementById('authcode').focus();
}


function ClassesDropDown(direction)
{
  if (!direction)
  {
    if (!ClassTree.folded)
    {
      if (ClassTree.folding == 'in')
        direction = 'out';
      else
        direction = 'in';
    }
    else
      direction = 'out';    
  }
  ClassTree.height = ClassTree.offsetHeight; 
  ClassTree.style.height = ClassTree.height+"px";
  clearTimeout(ClassTree.timer);
  ClassTree.style.overflow = "hidden";  
  if (direction == 'out')
  {
    //attEvt(document,'click',createMethodRef(window,'ClassesDropDown','in'));
    ClassTree.folded = false;
    ClassTree.folding = 'out';
    ClassTree.timer = setTimeout('ClassesFoldOut()',100);
    ClassTree.style.display = "block";
    ClassTree.style.top =  getposOffset(ClassesBox,'top')+ClassesBox.offsetHeight-2+"px";
    ClassTree.style.left = getposOffset(ClassesBox,'left')+7+"px";
  }
  else
  {
    ClassTree.folding = 'in';
    ClassTree.timer = setTimeout('ClassesFoldIn()',100);
  }
}

function ClassesFoldOut()
{
  if (ClassTree.height < ClassTree.scrollHeight)
  {
    ClassTree.height+=8;
    ClassTree.style.height = ClassTree.height+"px";
    ClassTree.timer = setTimeout('ClassesFoldOut()',10);
  }
  else
  {
    ClassTree.style.overflow = "visible";
    ClassTree.style.height = "auto";
    clearTimeout(ClassTree.timer);
  }
}

function ClassesFoldIn()
{  
  if (ClassTree.height > 8)
  {
    ClassTree.height-=8;
    ClassTree.style.height = ClassTree.height+"px";
    ClassTree.timer = setTimeout('ClassesFoldIn()',10);
  }
  else
  {
    //ClassTree.style.overflow = "hidden";
    ClassTree.style.display = "none";
    //ClassTree.style.height = "auto";
    clearTimeout(ClassTree.timer);
  }
}

function SelectClass(id,name)
{ 
  document.getElementById('srchbar_classfield').value = id
  document.getElementById('srchbar_classtext').innerHTML = name;
  setTimeout("ClassesDropDown('in');",50);
}

function setPickedColor(obj,color,input)
{
  var temp = false;
  if (input)
    if (temp = document.getElementById(input))
      temp.value = color;
     
  obj.style.backgroundColor = color;
  obj.setAttribute('pickedcolor',color);
}

function change_category(id,level)
{
  if (level)
    var level1 ='_'+level;
  else
    var level1 = '';
  //if (!document.getElementById('subcatcontainer'+level1)) return;
  var post_str = "&action=getcategories&id="+id+"&level="+level;
  AjaxRequest(post_str,'SetCategorySelector(text,'+level+');');
  var st = document.getElementById("subcat_b"+level1);  
  if (st)
  {
    var temp = st.nextSibling;
    while (temp)
    {
      if (temp.id == 'cat_last_node') break;
      temp.parentNode.removeChild(temp);
      temp = st.nextSibling;
    }
  }
  document.getElementById('maincategory').value = id;
  if (document.getElementById('subcatloader'+level1))
  {
    document.getElementById('subcatloader'+level1).style.visibility = 'visible';
    document.getElementById('subcatcontainer'+level1).innerHTML = '';
  }
}

function SetCategorySelector(text,level)
{
  if (level)
    var level1 ='_'+level;
  else
    var level1 = '';
  var st = document.getElementById("subcat_t"+level1);
  var sm = document.getElementById("subcat_m"+level1);
  var sb = document.getElementById("subcat_b"+level1);
  if (st)  st.parentNode.removeChild(st);
  if (sm)  sm.parentNode.removeChild(sm);
  if (sb)  sb.parentNode.removeChild(sb);
  delete st;
  delete sm;
  delete sb;
  if (text)
  {
    var lastnode = document.getElementById('cat_last_node');
    document.getElementById('bufferwindow').innerHTML = '<table>'+text+'</table>';
    var st = document.getElementById("subcat_t"+level1);
    var sm = document.getElementById("subcat_m"+level1);
    var sb = document.getElementById("subcat_b"+level1);
    lastnode.parentNode.insertBefore(st,lastnode);
    lastnode.parentNode.insertBefore(sm,lastnode);
    lastnode.parentNode.insertBefore(sb,lastnode);
  }
}

function change_country(id)
{
  var post_str = "&action=getstates&id="+id;
  AjaxRequest(post_str,'SetStateSelector(text);');
  document.getElementById('city_select').innerHTML = '<img src="/img/horizloader.gif" style="margin-top:4px;">';
  document.getElementById('state_select').innerHTML = '<img src="/img/horizloader.gif" style="margin-top:4px;">';
}

function change_state(id)
{
  post_str = "&action=getcities&id="+id;
  AjaxRequest(post_str,'SetCitySelector(text);');
  document.getElementById('city_select').innerHTML = '<img src="/img/horizloader.gif" style="margin-top:4px;">';
}

function SetStateSelector(text)
{
  document.getElementById('state_select').innerHTML = text;
  if (text.substr(1, 3) == 'inp')
    document.getElementById('city_select').innerHTML = '<input type="text" value="" style="border:0px;background:transparent;font-size:12px;width:224px;" name="custom_city">';
  else
    document.getElementById('city_select').innerHTML = '<select style="border:0px;background:transparent;font-size:12px;width:224px; name="city" disabled="true"></select>';
}

function SetCitySelector(text)
{
  document.getElementById('city_select').innerHTML = text;
}

function save_first_step(obj)
{
  document.getElementById('formerror').style.visibility='hidden';
  var theForm = document.forms.mainstep;
  if (!theForm.maincategory) return;
  var post_str = "&user=1&action=setcategory&category="+theForm.maincategory.value+"&mainaction="+theForm.mainaction.value;
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(obj));
}

function save_main_step(obj)
{  
  //return;
  var theForm = document.forms.mainstep;
  var post_str = "&user=1&action=savemainstep";//+"&type="+theForm.type.value;//+"&category="+theForm.category.value+email+"&timeto="+theForm.timeto.value+"&price="+theForm.price.value+"&description="+encodeURI(getText('description1')).replace(/&/g, "%26")+"&title="+encodeURI(theForm.title.value).replace(/&/g, "%26")+"&authcode="+encodeURI(theForm.authcode.value).replace(/&/g, "%26");
  for (var i = 0; i < theForm.elements.length;i++)
  {
    if ((theForm.elements[i].name == 'type' && !theForm.elements[i].checked) || theForm.elements[i].name == 'description') continue;
    post_str+="&"+theForm.elements[i].name+"="+encodeURI(theForm.elements[i].value).replace(/&/g, "%26");
  }
  post_str+="&description="+encodeURI(getText('description1')).replace(/&/g, "%26");
  //post_str+="&authcode="+encodeURI(document.getElementById('authcodeinput').value).replace(/&/g, "%26")
  //var email = theForm.email ? "&email="+encodeURI(theForm.email.value).replace(/&/g, "%26") : '';
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(obj));
}

function formerror(text,obj)
{
  if (!obj) obj = 'formerror';
  var errbox = document.getElementById(obj);
  if (errbox)
  {
    errbox.style.visibility = 'visible';
    errbox.innerHTML = text;
  }
  else
    alert(text);
}

function save_ad(obj,id)
{
  //return;
  var theForm = document.forms.mainstep;
  var post_str = "&user=1&action=savead&id="+id;//+"&type="+theForm.type.value;//+"&category="+theForm.category.value+email+"&timeto="+theForm.timeto.value+"&price="+theForm.price.value+"&description="+encodeURI(getText('description1')).replace(/&/g, "%26")+"&title="+encodeURI(theForm.title.value).replace(/&/g, "%26")+"&authcode="+encodeURI(theForm.authcode.value).replace(/&/g, "%26");
  for (var i = 0; i < theForm.elements.length;i++)
  {
    if ((theForm.elements[i].name == 'type' && !theForm.elements[i].checked) || theForm.elements[i].name == 'description') continue;
    post_str+="&"+theForm.elements[i].name+"="+encodeURI(theForm.elements[i].value).replace(/&/g, "%26");
  }
  post_str+="&description="+encodeURI(getText('description1')).replace(/&/g, "%26");
  //var email = theForm.email ? "&email="+encodeURI(theForm.email.value).replace(/&/g, "%26") : '';
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(obj));
}

function loadstep(step)
{
  document.location.href = "step_"+step+".html";
}

function setSelector(sel,value)
{
  sel.selectedIndex = (value-1);
}

function save_step_data(obj,dir)
{  
  var theForm = document.forms.stepform;
  var post_str = '&user=1&action=savestepdata&dir='+dir;
  var SerArray = '';
  var j = 0;
  for (var i = 0; i < theForm.elements.length; i++)
  {
    var value = theForm.elements[i].value;
    if (theForm.elements[i].type == 'checkbox') value = (theForm.elements[i].checked ? 'yes' : 'no');    
    var name = theForm.elements[i].name.substr(6);
    SerArray+='i:'+name+';s:'+value.length+':"'+value+'";';
    j++;
  //post_str+='&fields[]='+theForm.elements[i].name.substr(6)+'&values[]='+value;
  }  
  SerArray = 'a:'+j+':{'+SerArray+'}';
  post_str+='&data='+encodeURI(SerArray).replace(/&/g, "%26");
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(obj));
}

function save_last_step(obj,dir)
{  
  var theForm = document.forms.stepform;
  var post_str = '&user=1&action=savelaststep&dir='+dir;
  var i = 1;
  var temp = false;
  post_str+="&timeto="+theForm.timeto.value+"&price="+theForm.price.value+"&description="+encodeURI(theForm.description.value).replace(/&/g, "%26");
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(obj));
}

function CatFold(obj,id)
{  
  var catcontainer = document.getElementById('catfolder_'+id);
  if (catcontainer.style.height == 'auto')
  {
    obj.innerHTML = 'More Categories <img src="/img/green_arrow.gif" style="vertical-align:middle;">';
    catcontainer.style.height = '96px';
  }
  else
  {
    obj.innerHTML = 'Fewer Categories <img src="/img/green_arrow.gif" style="vertical-align:middle;">';
    catcontainer.style.height = 'auto';
  }
}

function CatFold2(obj,id)
{  
  var catcontainer = document.getElementById('categoryhider_'+id);
  if (catcontainer.style.display == '')
  {
    obj.innerHTML = 'See More <img src="/img/green_arrow.gif" style="vertical-align:middle;">';
    catcontainer.style.display = 'none';
  }
  else
  {
    obj.innerHTML = 'See Fewer <img src="/img/green_arrow.gif" style="vertical-align:middle;">';
    catcontainer.style.display = '';
  }
}


function add_uploaded_pic(width,height,imgname)
{
  var piccont = document.getElementById('uploadedpiccontainer');
  var i = 1;
  var imgname2 = imgname.replace(/temp\//,'');
  var elem = '<div id="pic_'+imgname2+'" style="float:left;width:110px;height:105px;border:1px dashed #AAAAAA;margin:2px;padding:5px;text-align:center;"><img src="/thumb_image/'+imgname+'.jpg" onclick="ShowPic(this,\'Added Image\',\'/big_image/'+imgname+'.jpg\','+width+','+height+');" style="margin-bottom:3px;cursor:pointer;"><br><a href="#" onclick="del_pic(this,\''+imgname2+'\');return false;" style="font-size:14px"><img src="/img/del2.gif" style="vertical-align:top;"> Remove</a></div>';
  piccont.innerHTML+=elem;
}

function del_pic(obj,imgname)
{
  var piccont = obj.parentNode.parentNode
  var post_str = "&user=1&action=delpic&pic="+encodeURI(imgname).replace(/&/g, "%26");
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(piccont));  
}

function add_uploaded_pic2(width,height,imgname,id)
{
  var piccont = document.getElementById('uploadedpiccontainer');
  var elem = '<div id="pic_'+id+'" style="float:left;width:110px;height:105px;border:1px dashed #AAAAAA;margin:2px;padding:5px;text-align:center;"><img src="/img/records/thumb/'+imgname+'.jpg" width="110" height="85" onclick="ShowPic(this,\'Image\',\'/img/records/big/'+imgname+'.jpg\','+width+','+height+');" style="margin-bottom:3px;cursor:pointer;"><br><a href="#" onclick="del_pic(this,\''+id+'\');return false;" style="font-size:14px"><img src="/img/del2.gif" style="vertical-align:top;"> Remove</a></div>';
  piccont.innerHTML+=elem;
}

function del_pic2(obj,id)
{
  var piccont = obj.parentNode.parentNode
  var post_str = "&user=1&action=delpic2&id="+id;
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(piccont));  
}

function remove_pic(id)
{
  var pic = document.getElementById('pic_'+id);
  pic.parentNode.removeChild(pic);
}

function setType(type)
{  
  document.getElementById('typesel_1').className='floatsel';
  document.getElementById('typesel_2').className='floatsel';
  document.getElementById('typesel_'+type).className='floatsel_lit';
  document.forms.mainstep.category.value = type;
}

function ImgDialog()
{
  var Imgfile = document.getElementById('fileimg');
  //Imgfile.focus();
  Imgfile.click();
  Imgfile.onclick();
  Imgfile.select();
//alert('a');  
}

function setFavorite(obj)
{
  var FavValue = obj.getAttribute('value');
  var FavCookies = readCookie('favorites');
  if (!FavCookies)
    FavCookies = [];
  else
    FavCookies = FavCookies.split(',');
  var FavIndex = FavCookies.indexOf(FavValue);
  var FavLen = FavCookies.length;
  
  if (FavIndex > -1)
  {
    obj.setAttribute('set',false);
    if (FavLen > 1)
    {
      for (var i = FavIndex; i < FavLen-1; i++)
        FavCookies[i] = FavCookies[i+1];      
    }
    FavCookies.pop();
    obj.src = "/img/favset.gif";
  }
  else
  {
    FavCookies.push(FavValue);
    obj.setAttribute('set',true);
    obj.src = "/img/favdel.gif";
  }
  var FavCount = document.getElementById('favcount');
  if (FavCount) FavCount.innerHTML = FavCookies.length;
  createCookie('favorites',FavCookies.join(','));
}

function DelFavorite(FavValue)
{
  var FavCookies = readCookie('favorites');
  if (!FavCookies) FavCookies = '';
  FavCookies = FavCookies.split(',');
  var FavIndex = FavCookies.indexOf(FavValue);
  var FavLen = FavCookies.length;
  
  if (FavIndex > -1)
  {
    if (FavLen > 1)
    {
      for (var i = FavIndex; i < FavLen-1; i++)
        FavCookies[i] = FavCookies[i+1];      
    }
    FavCookies.pop();
    var elem = document.getElementById('fav_'+FavValue);
    if (elem) elem.parentNode.removeChild(elem);
  }
  createCookie('favorites',FavCookies.join(','));
}

function scrolllocation(e)
{
  var keynum;
  if (e)
  {
    if(window.event) // IE
      keynum = e.keyCode;
    else if(e.which) // Netscape/Firefox/Opera
      keynum = e.which;        
  }  
  if (keynum == 38 && LOCATION_INDEX>1) //up
  {
    var obj1 = false;
    var obj2 = false;
    if (obj2 = document.getElementById('location_option_'+(LOCATION_INDEX-1)))
    {
      if (obj1 = document.getElementById('location_option_'+LOCATION_INDEX))
      {
        obj1.className = '';
      }
      LOCATION_INDEX--;
      obj2.className = 'selected';
    }
  }
  else if (keynum == 40) //down
  {
    var obj1 = false;
    var obj2 = false;
    if (obj2 = document.getElementById('location_option_'+(LOCATION_INDEX+1)))
    {
      if (obj1 = document.getElementById('location_option_'+LOCATION_INDEX))
      {
        obj1.className = '';
      }
      LOCATION_INDEX++;
      obj2.className = 'selected';
    }
  }
  else if (keynum == 13)
  {
    if (LOCATION_INDEX)
    {
      if (obj1 = document.getElementById('location_option_'+LOCATION_INDEX))
      {
        setlocation(obj1.innerHTML,obj1.getAttribute('location'));
        hidelocationlist();
      }
      return false;
    }
    else
      return keynum;
  }
  return keynum;
}

var LOCATION_INDEX = 1;

function checklocation(e,obj)
{
  var keynum;
  if (e)
  {
    if(window.event) // IE
      keynum = e.keyCode;
    else if(e.which) // Netscape/Firefox/Opera
      keynum = e.which;

    if (obj.value.length < 3)
    {
      document.forms.searchform.location.value = '';
      hidelocationlist();
      return;
    }
    //console.log(keynum);
    if ((!(keynum>31 && keynum<127) && keynum!=8) || (keynum>36 && keynum<41)) return;
  }

  var text = document.getElementById('whereinput').value;
  if (isInteger(text))
  {
    document.forms.searchform.zipcode.value = trim(text);
    document.forms.searchform.location.value = '';
    return;
  }
  else
    document.forms.searchform.zipcode.value = '';
  var post_str = "&action=getlocations&text="+encodeURI(document.getElementById('whereinput').value).replace(/&/g, "%26");
  AjaxRequest(post_str,'parselocationresponse(text);',false);
  LOCATION_INDEX = 1;
}

function parselocationresponse(text)
{
  //alert(text);
  var delim = text.indexOf('|');
  if (delim == -1)
  {
    alert('err');
    return;
  }
  var set = text.substr(0,delim);
  var text = text.substr(delim+1);
  eval("setlocation(false,"+set+");");
  showlocationlist(text);
}

function hidelocationlist(ev)
{
  //var locationlist = document.getElementById('locationlist');  
  setTimeout("document.getElementById('locationlist').style.display = 'none';LOCATION_INDEX = 0;",20);
  return true;
}

function showlocationlist(text)
{
  var locationlist = document.getElementById('locationlist');
  var whereinput = document.getElementById('whereinput');
  var left = getposOffset(whereinput,'left');
  var top = getposOffset(whereinput,'top');
  locationlist.style.left=left+"px";
  locationlist.style.top=top+25+"px";
  if (text != '')
    locationlist.style.display = 'block';
  locationlist.innerHTML = text;
  document.onmouseup  = hidelocationlist;
}

function setlocation(settext,locid)
{
  var whereinput = document.getElementById('whereinput');
  document.forms.searchform.location.value = locid;
  if (settext)
  {
    whereinput.value = settext;
    whereinput.focus();
    document.onmouseup = null;
  }
}

function del_ad(id)
{
  MakeConfirmation('<img src="/img/question.gif" style="float:left;padding-right:5px;width:48px;height:48px;" width="48" height="48">Are you sure you want to remove this ad?',300,115,'go_del_ad('+id+')','yes','','no');
}

function go_del_ad(id)
{
  document.location.href="/viewmyads.html?removead="+id;
}

function setpricefrom(value)
{
  document.forms.searchform.pricefrom.value = value;
}

function setpriceto(value)
{
  document.forms.searchform.priceto.value = value;
}

function removeuriparams(href,params)
{
  if (!params) return href;
  var Reg = null;
  for (var i = 0; i < params.length; i++)
  {
    Reg = new RegExp('(^|/)'+params[i]+"-([^\./]{0,})","g");
    href = href.replace(Reg,'');
  }
  return href;
}


/*function getPriceFilter()
{
  var TheForm = document.forms.searchform
  if (TheForm)
  {
    var price = ''
    if (TheForm.pricefrom.value && TheForm.pricefrom.value!='Low')
      price +='pricefrom-'+encodeURI(TheForm.pricefrom.value).replace(/&/g, "%26")+'/';
    if (TheForm.priceto.value && TheForm.priceto.value!='High')
      price +='priceto-'+encodeURI(TheForm.priceto.value).replace(/&/g, "%26")+'/';
    return price;
  }
  return '';
}*/

function getLocationFilter()
{
  var TheForm = document.forms.searchform;
  /*var countryLoc = document.getElementById('searchcountry_sel').value.split('|');
  countryLoc = countryLoc[0];*/
  /*if (document.getElementById('searchlocation').value=='City, State or ZIP')
    TheForm.location.value = countryLoc;*/
  if (TheForm)
  {
    if ((TheForm.location.value))
      return TheForm.location.value;
  }
  return '';
}

/*function getCustomFilters()
{
  //alert(document.forms[3].name);
  var TheForm = document.forms.customfilterform;
  //alert(TheForm);
  var uri = '';
  var temp = '';
  var element = null
  for (var i=0;i < TheForm.elements.length; i++)
  {
    element = TheForm.elements[i];
    if (!element.name || !element.value) continue;
    if ((temp = element.getAttribute('boundword')) && temp == element.value) continue;
    uri+=element.name+'-'+encodeURI(element.value).replace(/&/g, "%26")+'/';
  }
  //alert(uri);
  return uri;
}

function getCustomFilterNames()
{
  var TheForm = document.forms.customfilterform;
  var uri = '';
  var temp = [];
  var element = null
  var j = 0;
  for (var i=0;i < TheForm.elements.length; i++)
  {
    element = TheForm.elements[i];
    if (!element.name) continue;
    temp[j]=element.name;
    j++;
  }
  //alert(uri);
  return temp;
}*/

function setSearchFilter()
{
  var uri = '';
  var element = '';
  var ElArray = [];
  var TheForm  = document.forms.searchform;
  var searchTerm = encodeURI(TheForm.search.value).replace(/&/g, "%26");
  if (searchTerm=='')
    return false;

  ElArray.push('search');
  uri+= 'search-'+searchTerm+'/'+TheForm.location.value;

  var href = document.location.href;
  var lastslash = href.lastIndexOf('/');
  var afteruri = href.substr(lastslash+1);
  if ((afteruri.indexOf('order')== -1 || afteruri.indexOf('page')== -1))
  {
    if (afteruri.indexOf('.') != -1)
    {
      lastslash = href.lastIndexOf('.');
      afteruri = href.substr(lastslash);
    }
  }
  var filterstart = href.indexOf('/f/');
  uri = '/'+uri.substr(0,uri.length-1);
  uri = removeuriparams(uri,['entirecountry']);    
  if (filterstart > -1)
  {
    var filterhref = removeuriparams(href.substring(filterstart+2,lastslash), ElArray);
    uri=filterhref+=uri;
    lastslash = filterstart;
  //href = href.substring(0,filterstart+2)+uri+filterhref+afteruri;
  }
  //var filteruri = href.substring(0,lastslash)+(uri ? '/f'+uri : '');
  var filteruri = 'http://www.yadsi.in'+(uri ? '/f'+uri : '');
  if (!afteruri) afteruri = '.html';
  if (afteruri != '.html') afteruri = '/'+afteruri;
  if (filteruri == 'http://www.yadsi.in') afteruri = '';
  href = filteruri+afteruri;
  href = href.replace(/page-([0-9]{1,})/,'page-1');
  document.location.href = href;
  return false;
}

function setFilter(ignore)
{
  var href = document.location.href;
  //var Price  = getPriceFilter();
  //var Location = getLocationFilter();
  //var CustomFilters = getCustomFilters();

  var TheForm = document.forms.filterform;
  var uri = '';
  var temp = '';
  var element = null
  var ElArray = [];
  for (var i=0;i < TheForm.elements.length; i++)
  {
    element = TheForm.elements[i];
    if (!element.name || !element.value) continue;
    if (ElArray.indexOf(element.name)==-1)
      ElArray.push(element.name);
    if ((temp = element.getAttribute('boundword')) && temp == element.value) continue;
    if (element.type=='checkbox' && !element.checked) continue;
    uri+=element.name+'-'+element.value.urlencode()+'/';
  }

  if (ignore)
  {
    IgnoreArray = [];
    IgnoreArray = IgnoreArray.concat(ignore);
    uri =  removeuriparams(uri,IgnoreArray);
  }
  //uri =  removeuriparams(uri,ignore);
  //if (uri == '/') uri = '';
 
  href = href.replace(/page-([0-9]{1,})/,'page-1');
  var lastslash = href.lastIndexOf('/');
  var afteruri = href.substr(lastslash+1);
  if ((afteruri.indexOf('order')== -1 || afteruri.indexOf('page')== -1))
  {
    if (afteruri.indexOf('.') != -1)
    {
      lastslash = href.lastIndexOf('.');
      afteruri = href.substr(lastslash);
    }
  }
  var filterstart = href.indexOf('/f/');
  uri = '/'+uri.substr(0,uri.length-1);
  if (uri=='/') uri = '';  
  if (filterstart > -1)
  {
    var filterhref = removeuriparams(href.substring(filterstart+2,lastslash), ElArray);
    uri= filterhref+uri;
    lastslash = filterstart;
    var beforefilter = href.substr(0,filterstart);
  }
  else
    var beforefilter = href.substr(0,lastslash);
  //var filteruri = href.substring(0,lastslash)+(uri ? '/f'+uri : '');
  if (uri=='/') uri = '';
  var filteruri = beforefilter+(uri ? '/f'+uri : '');
  if (!afteruri) afteruri = '.html';
  if (afteruri != '.html') afteruri = '/'+afteruri;
  if (filteruri == 'http://www.yadsi.in') afteruri = '';
  href = filteruri+afteruri;
  //if (console && console.log) console.log(href);
  document.location.href = href
  return false;
}



function showlogin()
{
  show_window('loginwindow');
  document.getElementById('loginerrorbox').style.visibility="hidden";
  if (document.forms.loginform.login.focus)  document.forms.loginform.login.focus();
}

function closelogin()
{
  close_window('loginwindow');
}


var Windows = [];
var Timers = [];
var WindowCount = 0;

function relocate_win(id)
{
  var Window = Windows[id];
  var height = Window.offsetHeight;
  var width = Window.offsetWidth;
  X = Math.floor((document.body.scrollWidth-width)/2);
  var top = 0;

  if (window.pageYOffset)
    top = window.pageYOffset;
  else
  if (document.documentElement)
    top = document.documentElement.scrollTop;
  else
    top = document.body.scrollTop;

  var FHeight = 0;
  if (window.innerHeight) FHeight = window.innerHeight;
  else
  if (document.documentElement) FHeight = document.documentElement.clientHeight;
  else
    FHeight = document.body.clientHeight;

  var top2 = Window.offsetTop - top;

  var diff = (top2+FHeight-height)*0.3;


  Y = (top + diff);// +
  if (Y<0) Y = 0;
  if (height+20 > FHeight+top) Y = 0;
  //document.title = top2+FHeight;
  Window.style.left=X+"px";
  Window.style.top=Y+"px";
}

function show_window(win,text)
{
  var Window = null;
  if (win.isInteger)
  {
    win = parseInt(win);
    Window = Windows[win];
  }
  else
  {
    Window = document.getElementById(win);
    if (!Window) {
      alert("Window Error! Object doesnt exist! ("+win+")");
      return false
    }
    win = 0;
    while (Windows[win] && (Windows[win]!=Window)) win++;
    Windows[win] = Window;
  }
  //alert(Window.style.visiblity);
  if (Window.style.visibility!='hidden') return win;

  //ShowGreyScreen();
  if (text)
  {
    text = text.replace(/#thiswin#/g,win);
    Window.innerHTML = text;
  }
  else
    Window.innerHTML = Window.innerHTML.replace(/#thiswin#/g,win);

  WindowCount++;
  Window.style.zIndex = 21+2*WindowCount;
  relocate_win(win);
  //setTimeout('relocate_win('+ win+');', 1);
  Timers[win] = setInterval('relocate_win('+ win+');', 50);
  relocate_win(win);
  Window.style.visibility="";
  //Window.style.display="";
  //delete Window.style.visibility;
  return win;
}

function close_window(win)
{
  var Window = null;
  if (win.isInteger)
  {
    win = parseInt(win);
    Window = Windows[win];
  }
  else
  {
    Window = document.getElementById(win);
    if (!Window) {
      alert("Window Error! Object doesnt exist! ("+win+")");
      return false
    }
    win = 0;
    while (Windows[win] && (Windows[win]!=Window)) win++;
    Windows[win] = Window;
  }
  clearInterval(Timers[win]);
  WindowCount--;
  //HideGreyScreen();
  //FadeOut(Window,false,true);
  Window.style.visibility="hidden";
//Window.style.display="none";
}

function pricekeypress()
{
  var priceto = document.getElementById('priceto');
  var pricefrom = document.getElementById('pricefrom');
  var btn = document.getElementById('pricefilterbtn');
  //alert(priceto.value+'-'+pricefrom.value);
  //if (pricefrom.value == 'Low' && priceto.value == 'High')
  //  FadeOut(btn,false,true);
  //else
  FadeOut(btn,true,false);
}

function searchkeypress()
{
  var val = document.getElementById('searchbox_input').value;
  var btn = document.getElementById('searchboxbtn');
  //alert(priceto.value+'-'+pricefrom.value);
  if (val == '' || val == 'Type keyword')
    FadeOut(btn,false,true);
  else
    FadeOut(btn,true,false);
}

function customfieldkeypress(field)
{
  var valf = document.getElementById(field+'from_input').value;
  var valt = document.getElementById(field+'to_input').value;
  var btn = document.getElementById(field+'_btn');
  //if (valf == 'Low' && valt == 'High')
  //    FadeOut(btn,false,true);
  //  else
  FadeOut(btn,true,false);
}

function customfieldkeypress2(field)
{
  var btn = document.getElementById(field+'_btn');
  FadeOut(btn,true,false);
}

function customfieldsuncheck(field)
{
  var TheForm  = document.forms['filterwindow'];
  for (var i=0;i < TheForm.elements[field].length; i++)
    TheForm.elements[field][i].checked = false;
}

function showhideforgotyourpass()
{
  var passretrcont = document.getElementById('forgotyourpass');
  if (passretrcont.style.display=='none')
  {
    passretrcont.style.display='block';
    FadeOut(passretrcont,true,false);
  }
  else
  {
    //passretrcont.style.display='none';
    FadeOut(passretrcont,false,true,false,false,'document.getElementById("forgotyourpass").style.display="none";');
  }
}

function foldunfold(obj1,obj2name)
{
  var obj2 = document.getElementById(obj2name).style;
  if (obj2.display=="none")
  {
    obj2.display = "block";
    obj1.className = "overclass4 unfolded";
  }
  else
  {
    obj2.display = "none";
    obj1.className = "overclass4 folded";
  }
  createCookie(obj2name,obj2.display,365);
}

function go_login(ret)
{
  if (ret)
    ret = '&return=1'
  else
    ret = '';
  var theForm = document.forms.loginform;
  FadeOut(document.getElementById('loginerrorbox'),false,true);
  //document.getElementById('loginerrorbox').style.visibility="hidden";
  var post_str = "&action=login&email="+encodeURI(theForm.login.value).replace(/&/g, "%26")+"&pass="+encodeURI(theForm.password.value).replace(/&/g, "%26")+ret;
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(theForm));
  ShowGreyScreen();
//theForm.password.value = '';
}

function loginerror(text)
{
  var loginerror = document.getElementById('loginerrorbox');
  //loginerror.style.visibility="visible";
  FadeOut(loginerror,true,false);
  HideGreyScreen();
  loginerror.innerHTML = text;
}

function go_retrievepass()
{
  var theForm = document.forms.passretrieveform;
  FadeOut(document.getElementById('loginerrorbox'),false,true);
  //document.getElementById('loginerrorbox').style.visibility="hidden";
  var post_str = "&action=retrievepassword&email="+encodeURI(theForm.email.value).replace(/&/g, "%26");
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(theForm));
  ShowGreyScreen();
//theForm.pass.value = '';
}

function shownewpass()
{
  show_window('loginwindow');
  ShowGreyScreen();
  document.forms.newpassform.pass.focus();
}

function go_setnewpass()
{
  var theForm = document.forms.newpassform;
  FadeOut(document.getElementById('loginerrorbox'),false,true);
  //document.getElementById('loginerrorbox').style.visibility="hidden";  
  var post_str = "&action=setnewpassword&pass="+encodeURI(theForm.pass.value).replace(/&/g, "%26")+"&pass2="+encodeURI(theForm.pass2.value).replace(/&/g, "%26");
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(theForm));
  //ShowGreyScreen();
//theForm.pass.value = '';
}

function newpasserror(text)
{
  var loginerror = document.getElementById('loginerrorbox');
  //loginerror.style.visibility="visible";  
  FadeOut(loginerror,true,false);
  loginerror.innerHTML = text;
}

function checklocation2(e,obj)
{
  var keynum;
  if (e)
  {
    if(window.event) // IE
      keynum = e.keyCode;
    else if(e.which) // Netscape/Firefox/Opera
      keynum = e.which;

    if (obj.value.length < 3)
    {
      document.forms.searchform.location.value = '';
      hidelocationlist2();
      return;
    }
    if (!(keynum>31 && keynum<127) && keynum!=8) return;
  }
  var country = document.getElementById('searchcountry_sel').value.split('|');
  country = country[1];
  var text = document.getElementById('searchlocation').value;
  if (isInteger(text))
  {
    document.forms.searchform.zipcode.value = trim(text);
    document.forms.searchform.location.value = '';
    return;
  }
  else
    document.forms.searchform.zipcode.value = '';

  var post_str = "&action=getlocations2&country="+country+"&text="+encodeURI(document.getElementById('searchlocation').value).replace(/&/g, "%26");
  AjaxRequest(post_str,'parselocationresponse2(text);',false);
}

function parselocationresponse2(text)
{
  //alert(text);
  var delim = text.indexOf('|');
  if (delim == -1)
  {
    alert('err');
    return;
  }
  var set = text.substr(0,delim);
  var text = text.substr(delim+1);
  eval("setlocation2(false,"+set+");");
  showlocationlist2(text);
}

function hidelocationlist2(ev)
{
  //var locationlist = document.getElementById('locationlist');
  setTimeout("document.getElementById('locationlist2').style.display = 'none'",20);
  return true;
}

function showlocationlist2(text)
{
  var locationlist = document.getElementById('locationlist2');
  var searchloc = document.getElementById('searchlocation');
  var left = getposOffset(searchloc,'left');
  var top = getposOffset(searchloc,'top');
  locationlist.style.left=left+"px";
  locationlist.style.top=top+22+"px";
  if (text != '')
    locationlist.style.display = 'block';
  locationlist.innerHTML = text;
  document.onmouseup  = hidelocationlist2;
}

function setlocation2(settext,locid)
{
  var searchloc = document.getElementById('searchlocation')
  document.forms.searchform.location.value = locid;
  if (settext)
  {
    searchloc.value = settext;
    searchloc.focus();
  }
}

function showactivator(id)
{
  show_window('loginwindow');
  document.forms.publishform.record_id.value = id;
/*loginwin = document.getElementById('loginwindow');
  if (!loginwin) return;
  loginwin.style.visibility = "visible";
  //ShowGreyScreen();
  //loginwin.style.zIndex='21';
  relocateloginwin();
  loginwintimer = setInterval(relocateloginwin,40);*/
}

function go_publish()
{
  var TheForm = document.forms.publishform;
  AjaxRequest("&user=1&action=publish&id="+TheForm.record_id.value+"&dateto="+TheForm.dateto.value, "AjaxResponse(text)",showloadbox());
}

function edit_comment(obj,id)
{
  var comment = '';
  if (document.getElementById('reccomment_'+id)) comment = document.getElementById('reccomment_'+id).innerHTML;
  ShowInfoBox('<div style="padding:3px;"><textarea id="comment_editor_'+id+'" style="margin-bottom:2px;width:286px;height:60px;border:1px solid #cccdcc;padding:3px;color:#666666;font-size:11px;overflow:hidden;" onkeyup="recountSymbols(this);" onkeypress="return LimitInput(this,event,128);">'+comment+'</textarea><div class="small_link" style="float:left;color:#666666;padding-left:5px;">128 symbols left</div><div class="small_link" style="text-align:right;"><a href="" onclick="save_comment(#thisbox#,'+id+');return false;">Save</a> | <a href="" onclick="cancel_comment(#thisbox#,'+id+');return false;">Cancel</a></div></div>',obj,300,90,true,10);
  setTimeout("recountSymbols(document.getElementById('comment_editor_"+id+"'))",50);
}

function edit_comment2(obj,id)
{
  var comment = '';
  if (document.getElementById('reccomment_'+id)) comment = document.getElementById('reccomment_'+id).innerHTML;
  SetInfoBoxText2(obj,'<div style="padding:3px"><textarea id="comment_editor_'+id+'" style="margin-bottom:2px;width:286px;height:60px;border:1px solid #cccdcc;padding:3px;color:#666666;font-size:11px;overflow:hidden;" onkeyup="recountSymbols(this);" onkeypress="return LimitInput(this,event,128);">'+comment+'</textarea><div class="small_link" style="float:left;color:#666666;padding-left:5px;">128 symbols left</div><div class="small_link" style="text-align:right;"><a href="" onclick="save_comment('+obj+','+id+');return false;">Save</a> | <a href="" onclick="cancel_comment('+obj+','+id+');return false;">Cancel</a></div></div>');
  setTimeout("recountSymbols(document.getElementById('comment_editor_"+id+"'))",50);
}

function save_comment(obj,id)
{
  var text = document.getElementById('comment_editor_'+id).value;
  var post_str = "&user=1&action=savecomment&record="+id+"&text="+encodeURI(text).replace(/&/g, "%26");
  SetInfoBoxText2(obj,'<div style="margin:10px;padding:13px;border:1px solid #cccdcc;text-align:center;background-color:#ffffff">Saving<br><img src="/img/design/2ndloader.gif" width="24" height="24"></div>');
  AjaxRequest(post_str,"AjaxResponse(text,'update_comment("+obj+","+id+",textcut)');");
}

function cancel_comment(objid,id)
{
  var text = '';
  if (document.getElementById('reccomment_'+id)) text = document.getElementById('reccomment_'+id).innerHTML;
  eval("update_comment(objid,id,text)");
}

function update_comment(objid,id,textcut)
{
  HideInfoBox(objid);
  var thediv = document.getElementById('notediv_'+id)
  if (textcut)
  {
    thediv.className= 'hidingdiv2';
    thediv.innerHTML = '<span onmouseover="view_comment(this,\''+id+'\');" onmouseout="InfoBoxTimeout2(this);"><img src="/img/design/noteicon2.gif" style="cursor:pointer;" onclick="view_comment(this,\''+id+'\');return false;"></span><span id="reccomment_'+id+'" style="display:none;">'+textcut+'</span>';
  }
  else
  {
    thediv.className= 'hidingdiv';
    thediv.innerHTML = '<span onmouseover="show_hint(this,\'Add a note\');" onmouseout="InfoBoxTimeout2(this);"><img src="/img/design/noteicon1.gif" style="cursor:pointer;" onclick="edit_comment(this,\''+id+'\');return false;"></span>';
  }
}

function view_comment(obj,id)
{
  var comment = '';
  if (document.getElementById('reccomment_'+id)) comment = document.getElementById('reccomment_'+id).innerHTML;
  ShowInfoBox('<div style="padding:3px 7px 3px 7px;"><div style="width:100%;margin-bottom:3px;padding:3px;color:#666666;font-size:11px;">'+comment+'</div><div class="small_link" style="text-align:right;"><a href="" onclick="edit_comment2(#thisbox#,'+id+');return false;">Edit</a> | <a href="" onclick="HideInfoBox(#thisbox#);return false;">Cancel</a></div></div>',obj,300,false,true,10,true);
}

function show_hint(obj,text)
{
  ShowInfoBox('<div style="padding:3px 7px 3px 7px;color:#666666;font-size:11px;"><center>'+text+'</center></div>',obj,false,false,true,10,true);
}

function show_hint2(obj,id)
{
  if (document.getElementById('reccomment_'+id)) comment = document.getElementById('reccomment_'+id).innerHTML;
  ShowInfoBox('<div style="padding:3px 7px 3px 7px;color:#666666;font-size:11px;"><center>'+comment+'</center></div>',obj,false,false,true,10,true);
}

function edit_mark(obj,id)
{
  ShowInfoBox('<div style="padding:3px 7px 3px 7px;color:#666666;font-size:11px;width:75px;"><img src="/img/design/mark_grey.gif" style="cursor:pointer;" onclick="set_mark('+id+',0);HideInfoBox(#thisbox#);"><img src="/img/design/mark_blue.gif" style="margin-left:5px;cursor:pointer;" onclick="set_mark('+id+',1);HideInfoBox(#thisbox#);"><img src="/img/design/mark_green.gif" style="margin-left:5px;cursor:pointer;" onclick="set_mark('+id+',2);HideInfoBox(#thisbox#);"><img src="/img/design/mark_orange.gif" style="margin-left:5px;cursor:pointer;" onclick="set_mark('+id+',3);HideInfoBox(#thisbox#);"></span></div>',obj,false,false,true,3,true,15);
}

/*var img = new Image();
img.se*/

function set_mark(id,mark)
{
  var obj = document.getElementById("markdiv_"+id)
  obj.className = 'hidingdiv2';
  obj.innerHTML = '<img src="/img/design/mark_load.gif">';
  var post_str = "&user=1&action=setmark&record="+id+"&mark="+mark
  AjaxRequest(post_str,"AjaxResponse(text,'update_mark("+id+",textcut)');");
}

function update_mark(id,mark)
{
  var obj = document.getElementById("markdiv_"+id)
  if (mark == 'grey')
    obj.className = 'hidingdiv';
  else
    obj.className = 'hidingdiv2';
  obj.innerHTML = '<img src="/img/design/mark_'+mark+'.gif" width="12" height="12" style="cursor:pointer;margin-top:1px;" onmouseout="InfoBoxTimeout2(this)" onmouseover="edit_mark(this,'+id+');">';
}


function recountSymbols(obj)
{
  if (!obj.nextSibling) return;
  obj.nextSibling.innerHTML = (128-obj.value.length)+' symbols left';
}

function LimitInput(obj,event,limit)
{
  var e = window.event || event;
  var keyunicode=e.charCode || e.keyCode || e.which;
  var uncheckedkeycodes = /^((8)|(13)|(16)|(17)|(18))$/;
  if (console && console.log) console.log(keyunicode);
  if (obj.value.length>=128 && !uncheckedkeycodes.test(keyunicode))
  {
    obj.value = obj.value.substr(0, 128);
    recountSymbols(obj);
    return false;
  }
  recountSymbols(obj);
  return true;
}

var LastOpenFilter = null

function show_filters(cat,filter)
{
  var href = document.getElementById('searchlocationhref').value;
  show_filter_window();
  if (LastOpenFilter && LastOpenFilter!=filter)
  {
    document.getElementById('filter_content_'+LastOpenFilter).style.display = 'none';
    document.getElementById('filter_filter_'+LastOpenFilter).className = '';
  }
  document.getElementById('filter_content_'+filter).style.display = '';
  document.getElementById('filter_filter_'+filter).className = 'selected';
  if (document.getElementById('filter_content_'+filter).innerHTML=='')
  {
    document.getElementById('filter_content_'+filter).innerHTML = '<img src="/img/design/2ndloader.gif" style="margin-left:210px;;margin-top:150px;">'
    var post_str = '&action=getfiltercontent&category='+cat+'&filter='+filter+href; //(document.location.search).replace(/\?/,'&');
    AjaxRequest(post_str, 'set_filter_content(\''+filter+'\',text);');
  }
  document.getElementById('filterwinheader').innerHTML = document.getElementById('filter_filter_'+filter).innerHTML;
  LastOpenFilter = filter;
//document.location.
}

function set_filter_content(filter,text)
{
  document.getElementById('filter_content_'+filter).innerHTML = text;
}

function show_filter_window()
{
  show_window('filterwindow');
}

function showhidecities(obj)
{
  var elems = document.getElementsByName('citiescont');
  var display = '';
  if (obj.getAttribute('citieshidden'))
  {
    obj.setAttribute('citieshidden','');
    obj.innerHTML = '<img src="/img/design/arrow_d.gif"> Hide Cities';
  }
  else
  {
    display = 'none';
    obj.setAttribute('citieshidden','1');
    obj.innerHTML = '<img src="/img/design/arrow_a.gif"> Show Cities';
  }
  
  for (var i=0; i<elems.length;i++)
  {
    //alert(elems.item(i).getAttribute('atre'));
    elems.item(i).style.display = display;
  }
}

function set_window_filters(obj)
{
  //showloadbox(obj);
  var TheForm  = document.forms.filterwindow;
  var uri = '';
  var element = '';
  var ElArray = [];
  //ElArray.push('entirecountry\\[\\]');

  for (var i=0;i < TheForm.elements.length; i++)
  {
    element = TheForm.elements[i];
    if (!element.name || !element.value) continue;
    //if ((temp = element.getAttribute('boundword')) && temp == element.value) continue;
    if (element.getAttribute('type')=='checkbox')
    {
      if (ElArray.indexOf(element.name)==-1)
        ElArray.push(element.name);
      if (element.checked)
        uri+= element.name+'-'+encodeURI(element.value).replace(/&/g, "%26")+'/';
    }
    else
    {
      ElArray.push(element.name);
      if (element.value!='Low' && element.value!='High')
        uri+= element.name+'-'+encodeURI(element.value).replace(/&/g, "%26")+'/';
    }
  }
  var href = document.location.href;
  var lastslash = href.lastIndexOf('/');
  var afteruri = href.substr(lastslash+1);
  if ((afteruri.indexOf('order')== -1 || afteruri.indexOf('page')== -1))
  {
    if (afteruri.indexOf('.') != -1)
    {
      lastslash = href.lastIndexOf('.');
      afteruri = href.substr(lastslash);
    }
  }
  var filterstart = href.indexOf('/f/');
  uri = '/'+uri.substr(0,uri.length-1);
  uri = removeuriparams(uri,['entirecountry']);
  if (filterstart > -1)
  {
    var filterhref = removeuriparams(href.substring(filterstart+2,lastslash), ElArray);
    uri=filterhref+=uri;
    lastslash = filterstart;
  //href = href.substring(0,filterstart+2)+uri+filterhref+afteruri;
  }
  if (!uri) uri = '/';
  var filteruri = href.substring(0,lastslash)+(uri!='/' ? '/f'+uri : '')
  if (!afteruri) afteruri = '.html';
  if (afteruri != '.html') afteruri = '/'+afteruri;
  if (filteruri == 'http://www.yadsi.in') afteruri = '';
  href = filteruri+afteruri;
  //console.log(afteruri);
  document.location.href = href;
}

function reset_locations()
{
  var TheForm  = document.forms.filterwindow;
  for (var i=0;i < TheForm.city.length; i++)
    TheForm.city[i].checked = false;
  for (var i=0;i < TheForm.state.length; i++)
    TheForm.state[i].checked = false;
}

function send_email(form)
{
  var btn = document.getElementById('emailform_submit');
  var post_str='action=sendemail&to=admin&email='+encodeURI(form.email.value).replace(/&/g, "%26")+'&text='+encodeURI(form.text.value).replace(/&/g, "%26")+'&subject='+encodeURI(form.subject.value).replace(/&/g, "%26")
  AjaxRequest(post_str, 'AjaxResponse(text);', showloadbox());
}

function specialpassbeh(obj)
{
  /*  if (ie) return true;
  //if (console && console.log) console.log(obj.value.length);
  if (obj.value.length == 0 && obj.getAttribute('type')!='text')
    obj.setAttribute('type','text');
  else if (obj.value.length > 3 && obj.getAttribute('type')!='password')
    obj.setAttribute('type','password');*/
  return true;
}

function go_suggest_cat()
{
  var theForm = document.forms.suggestcatform;
  FadeOut(document.getElementById('suggestcaterrorbox'),false,true);
  var post_str = "&action=suggestcategory&email="+encodeURI(theForm.email.value).replace(/&/g, "%26")+"&text="+encodeURI(theForm.text.value).replace(/&/g, "%26");
  AjaxRequest(post_str,'AjaxResponse(text);',showloadbox(theForm));
//ShowGreyScreen();
//theForm.password.value = '';
}

function SetMinPrice(x)
{
  var pricefrom = document.getElementById('pricefrom');
  if (x < 1)
  {
    pricefrom.value='Low';
    pricefrom.style.color='#bdbdbd';
    pricedrag.style.marginLeft='0px';
  }
  else
  {
    pricefrom.style.color='#000000';
    pricefrom.value = Math.round(x / PRICECOEF);
    pricedrag.style.marginLeft=x-1+'px';
  }
//pricekeypress();

}

function SetMaxPrice(x)
{
  var priceto = document.getElementById('priceto');
  if (x > 225)
  {
    priceto.value='High';
    priceto.style.color='#bdbdbd';
    pricedrag.style.marginRight='0px';
  }
  else
  {
    priceto.style.color='#000000';
    priceto.value = Math.round(x / PRICECOEF);
    pricedrag.style.marginRight=(225-x)+'px';
  //document.title = x+'-'+priceto.value;
  }
}

function SetMinPriceReverse(price)
{
  if (price == 'Low')
  {
    pricedrag_low.style.left = '-1px';
    pricedrag.style.marginLeft='0px';
  }
  else
  {
    var price2 = parseInt(document.getElementById('priceto').value);
    if (price > price2)
    {
      var x = Math.round(PRICECOEF * price2)-1;
      document.getElementById('pricefrom').value = price2;
      SetMinPriceReverse(price2);
      return;
    }
    var x = Math.round(PRICECOEF * price)-1;
    pricedrag_low_handle.lastnx = x;
    pricedrag.style.marginLeft=x-5+'px';
    pricedrag_low.style.left = x+'px';
  }
}

function SetMaxPriceReverse(price)
{
  if (price == 'High')
  {
    pricedrag_high.style.left = '225px';
    pricedrag.style.marginRight='0px';
  }
  else
  {
    var price2 = parseInt(document.getElementById('pricefrom').value);
    if (price < price2)
    {
      var x = Math.round(PRICECOEF * price2)-1;
      document.getElementById('priceto').value = price2;
      SetMaxPriceReverse(price2);
      return;
    }
    var x = Math.round(PRICECOEF * price)-1;
    if (x>256) x = 256;
    pricedrag_high_handle.lastnx = x;
    pricedrag.style.marginRight=(225-x)+'px';
    pricedrag_high.style.left = x+'px';
  }
}

function ShowHidePassword(hide)
{
  var obj = document.getElementById('loginpasswordfield');
  if (hide)
    obj.setAttribute('type','password');
  else
    obj.setAttribute('type','text');
}


function record_view_change(type,id)
{
  /*document.getElementById('tab_ad_'+id).className = 'choosetab';
  document.getElementById('tab_ps_'+id).className = 'choosetab';
  document.getElementById('tab_ct_'+id).className = 'choosetab';*/
  document.getElementById('record_view_ad_'+id).style.display = 'none';
  document.getElementById('record_view_ps_'+id).style.display = 'none';
  document.getElementById('record_view_ct_'+id).style.display = 'none';

  /*document.getElementById('tab_'+type+'_'+id).className = 'choosetab_chosen';*/
  document.getElementById('record_view_'+type+'_'+id).style.display = '';
}

var lastimg = null;
var lastimgA = null;
var imgarray = null;
var curimg = 0;
var curimgA = 0;

function view_imageA(obj)
{
  if (lastimgA == obj.getAttribute('imgid')) return;
  obj.setAttribute('oldClassName', 'rwinfloatimg_selected');
  obj.className = 'rwinfloatimg_selected';
  var lastimg2 = document.getElementById('floatimg_'+lastimgA+'A');
  lastimg2.setAttribute('oldClassName', 'rwinfloatimg_out');
  lastimg2.className = 'rwinfloatimg_out';
  lastimgA = obj.getAttribute('imgid');
  curimgA = imgarray.indexOf(lastimgA);
  var width = obj.getAttribute('wth2');
  var height = obj.getAttribute('hth2');
  var src = obj.getAttribute('imgname');
  var ImgPrel = new ImgPreloader();
  ImgPrel.PreloadImg('/img/records/big/'+src+'.jpg','fade_imageA(\''+src+'\','+showloadbox(document.getElementById('bigimage'))+','+width+','+height+')');
}

function fade_imageA(src,loadbox,w,h)
{
  hidebox(loadbox);
  var obj = document.getElementById('bigimage');
  FadeOut(obj,true,true,'','','set_imageA(\''+src+'\','+w+','+h+')');
}

function set_imageA(src,w,h)
{
  var timg = document.getElementById('bigimage')
  timg.width = w+'px';
  timg.height = h+'px';
  timg.style.width = w+'px';
  timg.style.height = h+'px';
  timg.src = '/img/records/big/'+src+'.jpg';
  document.getElementById('bigimg_prev').setAttribute('coords','0,0,'+parseInt(w/2)+','+h);
  document.getElementById('bigimg_next').setAttribute('coords',parseInt(w/2)+',0,'+w+','+h);
}

function view_image(obj)
{
  if (lastimg == obj.getAttribute('imgid')) return;
  obj.setAttribute('oldClassName', 'rwinfloatimg_selected');
  obj.className = 'rwinfloatimg_selected';
  var lastimg2 = document.getElementById('floatimg_'+lastimg);
  lastimg2.setAttribute('oldClassName', 'rwinfloatimg_out');
  lastimg2.className = 'rwinfloatimg_out';
  lastimg = obj.getAttribute('imgid');
  curimg = imgarray.indexOf(lastimg);
  var width = obj.getAttribute('wth');
  var height = obj.getAttribute('hth');
  var src = obj.getAttribute('imgname');
  var ImgPrel = new ImgPreloader();
  ImgPrel.PreloadImg('/img/records/big/'+src+'.jpg','fade_image(\''+src+'\','+showloadbox(document.getElementById('overview_bigimage'))+','+width+','+height+')');
}

function fade_image(src,loadbox,w,h)
{
  hidebox(loadbox);
  var obj = document.getElementById('overview_bigimage');
  FadeOut(obj,true,true,'','','set_image(\''+src+'\','+w+','+h+')');
}

function set_image(src,w,h)
{
  var timg = document.getElementById('overview_bigimage')
  timg.width = w+'px';
  timg.height = h+'px';
  timg.style.width = w+'px';
  timg.style.height = h+'px';
  timg.src = '/img/records/big/'+src+'.jpg';
//document.getElementById('ov_bigimg_prev').setAttribute('coords','0,0,'+parseInt(w/2)+','+h);
//document.getElementById('ov_bigimg_next').setAttribute('coords',parseInt(w/2)+',0,'+w+','+h);
}

function setimgover(obj)
{
  obj.setAttribute('oldClassName', obj.className);
  obj.className = 'rwinfloatimg_over';
}

function setimgout(obj)
{
  obj.className = obj.getAttribute('oldClassName');
}

function nextimg()
{
  var len = imgarray.length;
  var index = 0;
  if (curimg+1 < len)
    index = curimg+1;
  view_image(document.getElementById('floatimg_'+imgarray[index]));
}

function previmg()
{
  var len = imgarray.length;
  var index = len-1;
  if (curimg-1 > -1)
    index = curimg-1;
  view_image(document.getElementById('floatimg_'+imgarray[index]));
}

function nextimgA()
{
  var len = imgarray.length;
  var index = 0;
  if (curimgA+1 < len)
    index = curimgA+1;
  view_imageA(document.getElementById('floatimg_'+imgarray[index]+'A'));
}

function previmgA()
{
  var len = imgarray.length;
  var index = len-1;
  if (curimgA-1 > -1)
    index = curimgA-1;
  view_imageA(document.getElementById('floatimg_'+imgarray[index]+'A'));
}
