$(document).ready(function(){ // This is inital values 
     
     
      try{
        $(".ajax-fc-container").captcha(); /* in this line note that ajax-fc-container is a class and we reference it with .(dot), if you want to change class to id, don't forget to replace the dot with # sign and also to describe it in css file. */
      }catch(ab){;}


    $("select[multiple]").asmSelect({
        sortable: false,
        animate: true,
        addItemTarget: 'top',
        highlight: true,
        debugMode:false, /* This is needed to check whether select multiple option is working properly or not */
        removeLabel:'<img src="images/Delete.png" alt="Remove" title="Remove" border=0 >'
    });
    if(msg != "")
    {
     Sexy.info(msg);
    }
});
var currentGallary = "" , inprocess = false;
function showTitle(index)
{
  $(".gallary img").each(function(i){
    if(i == index )
    {
      currentGallary = i ;  
      
      $(this).stop().fadeTo(200 , 1, function(){ 
        $("#title" + i).show();  
      })
    }
    else
    {
      $(this).stop().fadeTo(200 , 0.5)
      $("#title" + i).hide();      
    }
    
  })
}

function hideTitle()
{
  $(".gallary img").each(function(i){
    if(currentGallary != i)
    {
      $(this).stop().fadeTo(200,1);
      
      //$(".gallary-brandName").css('visibility','hidden');  
    }
  });
  $(".gallary-brandName").hide();
}
var currentPosition = 0 ;
function showNext()
{
  currentPosition = currentPosition - 942 ;
  
  if(currentPosition < (($(".gallary").width()  * -1)))
  {
    currentPosition =  currentPosition + 942 ;
  }
  
  $(".gallary").animate({left : currentPosition + 'px'},1000,'',function(){
    showYellowLink();
    
  });
  return false;
}

function showPrevious()
{
  currentPosition = currentPosition + 942 ;
  if(currentPosition >= 0)
  currentPosition = 0;
  $(".gallary").animate({left : currentPosition + 'px'},1000,'',function(){
    showYellowLink();
  });
  return false;
}

function showPage(id)
{
  $(".gallary1").animate({left : (id * -942) + 'px'},1000);
  $(".clsBrand a").each(function(i){
    if(i != id)
      $(this).removeClass("clsSelected");
    else
      $(this).addClass("clsSelected");
  });  
  return false;  
}
function moveNextSlide(currentId)
{
  var j = 0 ;
  $(".gallary1 li").each(function(i){j++;});
  if((j-1) == currentId)
  showPage(0);
  else
  showPage(currentId+1);
}

function showYellowLink()
{
    if($(".gallary").width() + currentPosition < 942)
      $(".clsNext > a").removeClass("exists");
    else
      $(".clsNext > a").addClass("exists");

    if(currentPosition >= 0)
      $(".clsPrevious > a").removeClass("exists");
    else
      $(".clsPrevious > a").addClass("exists");
}

function validateFuture()
{
  if(document.getElementById("txtcompany").value == "")
  {
    Sexy.error("Please Enter Company Name", { onComplete: function(returnVal){
      document.getElementById("txtcompany").focus();
    } });
    return false;
  }
  
   if(document.getElementById("txtlocation").value == "")
   {     
      Sexy.error("Please Enter Location", { onComplete: function(returnVal){
        document.getElementById("txtlocation").focus();
      } });
      return false;
   }
   
   if(document.getElementById("txtemail").value == "")
   {
     Sexy.error("Please Enter Email Address", {onComplete: function(returnval){
       document.getElementById("txtemail").focus();
     } });
     return false;
   }
   
   if (echeck(document.getElementById("txtemail").value)==false){
     Sexy.error("Existing Email address is not valid <br/>Please enter proper email address", {onComplete: function(returnval){
       document.getElementById("txtemail").value="";
       document.getElementById("txtemail").focus();
     } });
    
     return false;
   }
   
   if(document.getElementById("txtinquiry").value == "")
   {
     Sexy.error("Please enter information for which you are looking for it.", { onComplete: function(returnval){
       document.getElementById("txtinquiry").focus();
     } });
     return false;
   }   

   if(document.getElementById("txtinquiry").value == "")
   {
     Sexy.error("Please enter information for which you are looking for it.", { onComplete: function(returnval){
       document.getElementById("txtinquiry").focus();
     } });
     return false;
   }   
  if(document.getElementsByName("captcha")[0] == undefined)
  {
     Sexy.error("You have not dragged desired image on that box .", { onComplete: function(returnval){
       document.getElementById("txtinquiry").focus();
     } });
     return false;      
  }  

    return true;
}

echeck= function(e)
{
    if ( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/.test(e) )
      return true;
      return false;
}


function validateRetailer()
{
  if(document.getElementById("txtEmail").value == "")
  {
    Sexy.error("Please Enter Email Address", {onComplete: function(returnval){
      document.getElementById("txtEmail").focus();
    } });
    return false;
  }
  
  if (echeck(document.getElementById("txtEmail").value)==false){
    Sexy.error("Existing Email address is not valid <br/>Please enter proper email address", {onComplete: function(returnval){
      document.getElementById("txtEmail").value="";
      document.getElementById("txtEmail").focus();
    } });
    return false;
  }
  if(document.getElementById("txtBName").value == "")
  {
    Sexy.error("Please Enter Buisness Name", { onComplete: function(returnVal){
      document.getElementById("txtBName").focus();
    } });
    return false;
  }
  if(document.getElementById("txtABN").value == "")
  {
    Sexy.error("Please Enter ABN ", { onComplete: function(returnVal){
      document.getElementById("txtABN").focus();
    } });
    return false;
  }
  if(document.getElementById("txtOwner").value == "")
  {
    Sexy.error("Please Enter Owner Name", { onComplete: function(returnVal){
      document.getElementById("txtOwner").focus();
    } });
    return false;
  }
  if(document.getElementById("txtWeb").value == "")
  {
    Sexy.error("Please Enter Your Website Name", { onComplete: function(returnVal){
      document.getElementById("txtWeb").focus();
    } });
    return false;
  }
  if(document.getElementById("txtContactNo").value == "")
  {
    Sexy.error("Please Enter Contact Number", { onComplete: function(returnVal){
      document.getElementById("txtContactNo").focus();
    } });
    return false;
  }
  if(document.getElementById("txtAdd1").value == "")
  {
    Sexy.error("Please Enter at Address1", { onComplete: function(returnVal){
      document.getElementById("txtAdd1").focus();
    } });
    return false;
  }
/*  if(document.getElementById("txtAdd2").value == "")
  {
    Sexy.error("Please Enter at Address2", { onComplete: function(returnVal){
      document.getElementById("txtAdd2").focus();
    } });
    return false;
  }
*/  
  if(document.getElementById("txtCity").value == "")
  {
    
    Sexy.error("Please Enter Name of City", { onComplete: function(returnVal){
      document.getElementById("txtCity").focus();
    } });
    return false;
  }
/*  if(document.getElementById("txtState").value == "")
  {
    Sexy.error("Please Enter Name of State", { onComplete: function(returnVal){
      document.getElementById("txtState").focus();
    } });
    return false;
  }
*/  
if(document.getElementById("txtZip").value == "" && document.getElementById("txtState").value == "")
  {
    Sexy.error("Please Enter either zipcode or state", { onComplete: function(returnVal){
      document.getElementById("txtZip").focus();
    } });
    return false;
  }
  if(document.getElementById("txtCountry").value == "")
  {
    Sexy.error("Please Enter Name of Country", { onComplete: function(returnVal){
      document.getElementById("txtCountry").focus();
    } });
    return false;
  }
  
/*  if(document.getElementById("txtPhone").value == "")
  {
    Sexy.error("Please Enter Your Phone Number", { onComplete: function(returnVal){
      document.getElementById("txtPhone").focus();
    } });
    return false;
  }
*/  
  if(document.getElementById("txtDesc").value == "")
  {
    Sexy.error("Please Enter Short Description of Your Buisness", { onComplete: function(returnVal){
      document.getElementById("txtDesc").focus();
    } });
    return false;
  }
  if(document.getElementById("cmbbrands").value == "")
  {
    Sexy.error("Please Enter Your Brands by Clicking on Dropdown Option", { onComplete: function(returnVal){
      document.getElementById("cmbbrands").focus();
    } });
    return false;
  }
  if($("#latitude").val() == "" || $("#longitude").val() == "")
  {
    Sexy.error("Please validate your address by click on earth. <br> As valid address will later plotted on google map. ", { onComplete: function(returnVal){
      document.getElementById("cmbbrands").focus();
    } });
    return false;
  }
  if(document.getElementsByName("captcha")[0] == undefined)
  {
     Sexy.error("You have not dragged desired image on that box .", { onComplete: function(returnval){
       
     } });
     return false;      
  }  


  
    return true;
}
function resetLan()
{
            $("#longitude").val("");
            $("#latitude").val(""); 
            $("#isvalid").html("Address need to validated"); 
}

function AccuracyStr(id)
{
  switch(id)
  {
    case 0 : return 'Unknown Location';
    case 1 : return 'Country level accuracy.';
    case 2 : return 'Region (state, province, prefecture, etc.) level accuracy';
    case 3 : return 'Sub-region (county, municipality, etc.) level accuracy.';
    case 4 : return 'Town (city, village) level accuracy.';
    case 5 : return 'Post code (zip code) level accuracy.';
    case 6 : return 'Street level accuracy.';
    case 7 : return 'Intersection level accuracy. ';
    case 8 : return 'Address level accuracy';
    case 9 : return 'Premise (building name, property name, shopping center, etc.) level accuracy. ';
  }
}
function validateAddress()
{
// Finding Longitude and Latitude
//-----------------------------------
    var address ;
    address = $("#txtAdd1").val() != "" ? $("#txtAdd1").val() : "";
    address += $("#txtAdd2").val() != "" ? (address != ""?", ":"") + $("#txtAdd2").val() : "";
    address += $("#txtCity").val() != "" ? (address != ""?", ":"") + $("#txtCity").val()  : "";
    
    address += $("#txtState").val() != "" ? (address != ""?", ":"") + $("#txtState").val()  : "";
    address += $("#txtCountry").val() != "" ? (address != ""?", ":"") + $("#txtCountry").val()  : "";
    address += $("#txtZip").val() != "" ? (address != ""?" ":"") + $("#txtZip").val()  : "";
   //alert(address);
    var map = new GMap2(document.getElementById("map"));
    var geocoder = new GClientGeocoder();

    geocoder.getLocations(address , function(response){
        if(response.Status.code == G_GEO_SUCCESS)
        {
          $("#longitude").val(response.Placemark[0].Point.coordinates[0]);
          $("#latitude").val(response.Placemark[0].Point.coordinates[1]);
          
          $("#isvalid").html("Address is valid with " + AccuracyStr(response.Placemark[0].AddressDetails.Accuracy) );
          $("#isvalid").removeClass("invalid");
          $("#isvalid").addClass("valid");
          return true;
        }
        else
        { // Unable to find co-ordinates
            Sexy.error("<h3>Wrong Address </h3><p>Unable to find address on google location. <p>Please correct your address and validate it by click on globe.", { onComplete: function(returnVal){
              $("#txtAdd1").focus();
            } });
            $("#isvalid").html("Address is invalid");
            $("#isvalid").addClass("invalid");
            $("#isvalid").removeClass("valid");
            $("#longitude").val("");
            $("#latitude").val("");
            return false;
        }
      }); // Ajax closure
      //-----------------------------------
}

function validateGeneralInfo()
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.getElementById("txtmailid").value;
   if(document.getElementById("txtmailid").value == "")
  {
    Sexy.error("Please Enter Email Address", { onComplete: function(returnVal){
      document.getElementById("txtmailid").focus();
    } });
    return false;
  }
  if(reg.test(address) == false) 
	{
		Sexy.alert('Invalid Email formate entered.');
		document.getElementById("txtmailid").focus();
		return false;
	}
  if(document.getElementById("txtSubject").value == "")
  {
    Sexy.error("Please Enter Name of Subject", { onComplete: function(returnVal){
      document.getElementById("txtSubject").focus();
    } });
    return false;
  }
  if(document.getElementById("txtDesc").value == "")
  {
    Sexy.error("Please enter information for which you are looking for it.", { onComplete: function(returnVal){
      document.getElementById("txtDesc").focus();
    } });
    return false;
  }
  
  if(document.getElementsByName("captcha")[0] == undefined)
  {
     Sexy.error("You have not dragged desired image on that box .", { onComplete: function(returnval){
       
     } });
     return false;      
  }  
  
  return true;
}


function validateBrand()
{
  if(document.getElementById("txtName").value == "")
  {
    Sexy.error("Please Enter Name", { onComplete: function(returnVal){
      document.getElementById("txtName").focus();
    } });
    return false;
  }
  if(document.getElementById("txtEmail").value == "")
  {
    Sexy.error("Please Enter Email Address", {onComplete: function(returnval){
      document.getElementById("txtEmail").focus();
    } });
    return false;
  }
  
  if (echeck(document.getElementById("txtEmail").value)==false){
    Sexy.error("Existing Email address is not valid <br/>Please enter proper email address", {onComplete: function(returnval){
      document.getElementById("txtEmail").value="";
      document.getElementById("txtEmail").focus();
    } });
    return false;
  }
  if(document.getElementById("txtContactNo").value == "")
  {
    Sexy.error("Please Enter your Contact Number", { onComplete: function(returnVal){
      document.getElementById("txtContactNo").focus();
    } });
    return false;
  }
 /* if(document.getElementById("cmbbrands").value == "")
  {
    Sexy.error("Please Enter Your Brands by Clicking on Dropdown Option", { onComplete: function(returnVal){
      document.getElementById("cmbbrands").focus();
    } });
    return false;
  }*/
  if(document.getElementsByName("captcha")[0] == undefined)
  {
     Sexy.error("You have not dragged desired image on that box .", { onComplete: function(returnval){
       
     } });
     return false;      
  }  
  
  return true;
}

function changePage()
{
   window.location = $("#cmdPage").val();
}


