// JavaScript Document
var check=0;

//------------------------------------------------------------------------------
function changeArrow()
{
  var cond1 = document.getElementById("arrow-r").style.visibility;
  
  if(cond1 == "visible")
  {
    document.getElementById("category_block").style.visibility = "hidden";
    document.getElementById("arrow-r").style.visibility = "hidden";
    document.getElementById("arrow-b").style.visibility = "visible";
  }
  if(cond1 == "" || cond1 == "hidden")
  {
    document.getElementById("category_block").style.visibility = "visible";
    document.getElementById("arrow-r").style.visibility = "visible";
    document.getElementById("arrow-b").style.visibility = "hidden";
  }
}

//------------------------------------------------------------------------------
function pickCategory()
{
  var cond1 = document.getElementById("category_search_block").style.visibility;
  
  if(cond1 == "visible")
  {
    document.getElementById("category_search_block").style.visibility = "hidden";
    document.getElementById("category_search_close").style.visibility = "hidden";
  }
  if(cond1 == "" || cond1 == "hidden")
  {
    document.getElementById("category_search_block").style.visibility = "visible";
    document.getElementById("category_search_close").style.visibility = "visible";
  }
}

//------------------------------------------------------------------------------
function changeCat(catname,catid)
{
  document.getElementById("search_tab").innerHTML = catname;
  document.getElementById("category_search_block").style.visibility = "hidden";
  document.getElementById("category_search_close").style.visibility = "hidden";
  document.getElementById("cat_id").value = catid;
}

//------------------------------------------------------------------------------
function change(div)
{
  var changemode = document.getElementById(div).style.visibility;
  
  if(changemode == "hidden" || changemode == "")
  {
    document.getElementById(div).style.visibility = "visible";
  }
  if(changemode == "visible")
  {
    document.getElementById(div).style.visibility = "hidden";
    if(div == "region_more")document.getElementById(div).style.position = "absolute";
  }
}
//------------------------------------------------------------------------------
function checkIt(div)
{
  if(div != ""){
    if(check == 1)
    {
      if(document.getElementById(div).style.visibility == 'visible'){document.getElementById(div).style.visibility = 'hidden';check=0;}
    }
    if(document.getElementById(div).style.visibility == 'visible') check=1;
  }
}

//------------------------------------------------------------------------------enable submit when terms are accepted
function comanda_go()
{
  var checksubmit = document.getElementById("s").disabled;
  if (checksubmit == true)document.getElementById("s").disabled = false;
  if (checksubmit == false)document.getElementById("s").disabled = true;
}
//------------------------------------------------------------------------------
function more(div_m,m_view,m_pos)
{
  var more_m = document.getElementById(div_m);
  var m_status = document.getElementById(div_m).style.visibility;
  
  if(m_status == "visible" || m_status == ""){
    more_m.style.visibility = m_view;
    more_m.style.position = m_pos;
  }
  if(m_status == "hidden"){
    more_m.style.visibility = "visible";
    more_m.style.position = "relative";
  }
}
//------------------------------------------------------------------------------
function scrollToSelection(country_code)
{
  var myList = document.getElementById("country");
  var c_code = "";
   
  for (var i=0; i< myList.options.length; i++)
  {
    c_code = myList.options[i].value;
    if(c_code.indexOf(country_code) == 0)myList.options[i].selected = i;
  }
}
//------------------------------------------------------------------------------
function getField(getfield,fieldname)
{
  var w = document.getElementById(getfield).selectedIndex;
  var selected_text = document.getElementById(getfield).options[w].text;
  if(w != '')document.getElementById(fieldname).value = selected_text;
  else document.getElementById(fieldname).value = "";
}
//------------------------------------------------------------------------------
function getFieldValue(getfield,fieldname)
{
  var w = document.getElementById(getfield).selectedIndex;
  var selected_text = document.getElementById(getfield).options[w].value;
  if(selected_text != '')document.getElementById(fieldname).value = selected_text;
}
//------------------------------------------------------------------------------
function change_Value(v,fieldname)
{
  document.getElementById(fieldname).value = v;
}
//------------------------------------------------------------------------------
function change_visibility(v,fieldname)
{
  document.getElementById(fieldname).style.visibility = v;
}
//------------------------------------------------------------------------------
function load_data(a,fieldname)
{
  var d = document.getElementById(fieldname);
  var gourl = d.options[d.selectedIndex].value;
  if ((gourl != null) && (gourl != '') )
  {
    window.location = a + gourl;
  }
}
//------------------------------------------------------------------------------ajax GET
function ajaxFunction(dvx,url,param1,param2,param3,param4,param5,param6,param7,param8,param9)
{ 
  var w_addr = get_url();
  if (url == "start")urlx = w_addr + "user_page.php?p1="+param1+"&p2="+param2+"&p3="+param3+"&p4="+param4+"&p5="+param5+"&p6="+param6+"&p7="+param7+"&p8="+param8+"&p9="+param9;
  if (url == "city")urlx = w_addr + "sell_bid_city.php?p1="+param1;
  if (url == "currency")urlx = w_addr + "sell_bid_currency.php?p1="+param1+"&p2="+param2;
  if (url == "flag")urlx = w_addr + "sell_bid_flag.php?p1="+param1;
  if (url == "subcategory")urlx = w_addr + "sell_bid_category.php?p1="+param1+"&p2="+param2;
  if (url == "subcategory_data")urlx = w_addr + "sell_bid_subcategory_data.php?p1="+param1+"&p2="+param2+"&p3="+param3+"&p4="+param4+"&p5="+param5+"&p6="+param6;
  if (url == "post_modify")urlx = w_addr + "sell_bid.php?p1="+param1+"&p2="+param2;
  if (url == "change_pass")urlx = w_addr + "change_pass.php?p1="+param1+"&p2="+param2+"&p3="+param3;
  if (url == "cat_modify")urlx = w_addr + "cat_modify.php?p1="+param1+"&p2="+param2+"&p3="+param3+"&p4="+param4;
  if (url == "add_cat")urlx = w_addr + "add_cat.php?p1="+param1+"&p2="+param2+"&p3="+param3;
  if (url == "cat_data")urlx = w_addr + "cat_data.php?p1="+param1+"&p2="+param2+"&p3="+param3;
  if (url == "view_foto")urlx = w_addr + "view_foto.php?p1="+param1+"&p2="+param2+"&p3="+param3;
  if (url == "rate")urlx = w_addr + "rate.php?p1="+param1+"&p2="+param2;
  if (url == "company_contact")urlx = w_addr + "company_contact.php?p1="+param1+"&p2="+param2;
  if (url == "security_check")urlx = w_addr + "security_check.php?p1="+param1;
  
  //alert(urlx);
  
  var xmlHttp;
  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 AJAX!");
        return false;
        }
      }
    }
    
    xmlHttp.onreadystatechange=function()
    {
      if(xmlHttp.readyState==4)
      {
        if (document.getElementById(dvx)){document.getElementById(dvx).innerHTML=xmlHttp.responseText;}
      }
      if(xmlHttp.readyState < 4)
      {
        if (document.getElementById(dvx))
        {
          if(url != "security_check")document.getElementById(dvx).innerHTML = "<img src=\'" + w_addr + "images/ajax-loader.gif\' border=\'0\'>";
          if(url == "view_foto")urlx = "<img src=\'" + param4 + "/images/ajax-loader.gif\' border=\'0\'>";
        }
      }
    }   
    xmlHttp.open("GET",urlx,true);
    xmlHttp.send(null);
}
//------------------------------------------------------------------------------end ajax function

//------------------------------------------------------------------------------check file ext
function check_ext(f){
  var ext_char1 = ".jpg";
  var ext_char2 = ".gif";
  var ext_char3 = ".png";
  
  var get_ext1 = f.split(ext_char1);
  var get_ext2 = f.split(ext_char2);
  var get_ext3 = f.split(ext_char3);
  
  if(get_ext1 == f & get_ext2 == f & get_ext3 == f)alert("File extension is not supported!");
}
//------------------------------------------------------------------------------check file ext
function check_video_ext(f){
  var ext_char1 = ".swf";var ext_char11 = ".SWF";
  var ext_char2 = ".flv";var ext_char22 = ".FLV";
  var ext_char3 = ".mp4";var ext_char33 = ".MP4";
  
  var get_ext1 = f.split(ext_char1);
  var get_ext2 = f.split(ext_char2);
  var get_ext3 = f.split(ext_char3);
  var get_ext11 = f.split(ext_char11);
  var get_ext22 = f.split(ext_char22);
  var get_ext33 = f.split(ext_char33);
  
  if(get_ext1 == f & get_ext2 == f & get_ext3 == f & get_ext33 == f & get_ext11 == f & get_ext22 == f)alert("File extension is not supported!");
}
//------------------------------------------------------------------------------
function go_page(w,p,l){
  window.location = w + "/" + p + "/" + l;
}
//------------------------------------------------------------------------------
function empty_search(t){
  if(t == "Caut...")document.getElementById("search_box").value="";
  document.getElementById("search_box").style.color="#000";
}

function send_msg(){
  var err = 0;
  if(document.getElementById("feedback_nume").value == ""){alert("Please fill your name");err = 1;}
  if(document.getElementById("feedback_email").value == "" & err == 0){alert("Please fill your email address");err = 1;}
  
  var email_str=document.getElementById("feedback_email").value;
  var the_length=email_str.length;
  var email_format_monky = 1;
  for(var i=1;i<=the_length;i++){
    var last_char = email_str.charAt(the_length-i);
    if(email_format_monky == 1 & last_char == "@")email_format_monky = 0;
  }
  var email_format_dot = 1;
  for(var i=1;i<=the_length;i++){
    var last_char = email_str.charAt(the_length-i);
    if(email_format_dot == 1 & last_char == ".")email_format_dot = 0;
  }
  if(email_format_monky == 1 & err == 0){alert("Invalid email address!");err = 1;}
  if(email_format_dot == 1 & err == 0){alert("Invalid email address!");err = 1;}
  
  if(document.getElementById("feedback_text").value == "" & err == 0){alert("Please fill your message");err = 1;}
  if(document.getElementById("feedback_security").value == "" & err == 0){alert("Please fill security code");err = 1;}
  if(err == 0){
    document.contact.submit();
  }
}
//------------------------------------------------------------------------------
function fade(element,t){
  window.setTimeout("more('"+element+"','hidden','absolute')",t);
}
