function CheckEMail(str_email) {
          
        t = str_email.indexOf("@");
        if ((str_email.indexOf(".") == -1) || (t == -1) || (t < 1) || (t > str_email.length - 5) || (str_email.charAt(t - 1) == '.') || (str_email.charAt(t + 1) == '.'))  {
        alert('Enter Valid Email Adress!');
        return false;
        }
        return true;
    }



function CheckEMail2(str_email) {
          if(str_email == null)
            return false;
          else {
            t = str_email.indexOf("@");
            if ((str_email.indexOf(".") == -1) || (t == -1) || (t < 1) || (t > str_email.length - 5) || (str_email.charAt(t - 1) == '.') || (str_email.charAt(t + 1) == '.'))  {
    //         alert('Enter Valid Email Adress!');
            return false;
            }
            return true;
        }
    }

//Main page effects
    $(function() {
        $('a[@rel*=gallery]').lightBox();
    });

    $(function() {
        $('a.gallery').lightBox();
    });

//Form Functions
    function CheckForm(style) {
      if (style == undefined) {style = 'font_red_color';}
      var error = 0;
      for(i=0;i<mandatory_fields.length;i++) {
        if($("#"+mandatory_fields[i]).val() == "") {
          error = 1
          $("#check_"+mandatory_fields[i]).addClass(style);
        } else {
          $("#check_"+mandatory_fields[i]).removeClass(style);
        }
      }

      if(error == 1) {
        if (style != undefined)
           alert("Fill all marked fields");
        return false;
      }
      else
        return true;
    }

    function CheckFormInput(ref) {
      var error = 0;
      var message = "Please fill in:\n";
      var add = "";
      if(ref == 1)
        add = "#";
      else
        add = "#check_";
      for(i=0;i<mandatory_fields.length;i++) {
        if($("#"+mandatory_fields[i]).val() == "" && mandatory_fields[i] != 'email' && mandatory_fields[i] != 'smail' && mandatory_fields[i] != 'mail' && mandatory_fields[i] != 'register_email' && mandatory_fields[i] != 'contact_email' && mandatory_fields[i] != 'cc_number' && mandatory_fields[i] != 'agree') {
          error = 1;
          $(add+mandatory_fields[i]).addClass('font_red_color');

            message += ' - '+window[mandatory_fields[i]]+'\n';


        } else {
          $(add+mandatory_fields[i]).removeClass('font_red_color');
        }

        if(mandatory_fields[i] == 'email' || mandatory_fields[i] == 'smail' || mandatory_fields[i] == 'mail' || mandatory_fields[i] == 'register_email' || mandatory_fields[i] == 'contact_email' || mandatory_fields[i] == 'semail') {

          if(CheckEMail2($("#"+mandatory_fields[i]).val()) == false) {
            error = 1;

            message += ' - '+window[mandatory_fields[i]]+'\n';


            $(add+mandatory_fields[i]).addClass('font_red_color');
          } else {
            $(add+mandatory_fields[i]).removeClass('font_red_color');
          }
        }

    if(mandatory_fields[i] == 'code') {
          if($("#"+mandatory_fields[i]).val() == "Enter Code") {
              $(add+mandatory_fields[i]).addClass('font_red_color');
              message += ' - '+code+'\n';
              error = 1;
            }
            else
             $(add+mandatory_fields[i]).removeClass('font_red_color');
       }
        
        if(mandatory_fields[i] == 'agree') {
          if(!(document.getElementById('agree').checked)) {
              $(add+mandatory_fields[i]).addClass('font_red_color');
              message += ' - '+agree+'\n';
              error = 1;
            }
            else
             $(add+mandatory_fields[i]).removeClass('font_red_color');
       }

        if(mandatory_fields[i] == 'cc_number') {
          if(document.getElementById('cc_typea').value != "") {
            var art_cc = CheckCardNumber(document.forms.registration_form);
            if(art_cc != true) {
              error = 1;
  
              message += ' - '+art_cc+'\n';
  
  
              $(add+mandatory_fields[i]).addClass('font_red_color');
            } else {
              $(add+mandatory_fields[i]).removeClass('font_red_color');
            }
          }
        }
      }

      if(error == 1) {
            alert(message+"field(s)!");
        if(ref == 1)
          RefillAll();

        return false;
      } else
        return true;

    }

    function CustomCheckForm(c_form, c_mandatory_fields) {

      var error = 0;
      for(i=0;i<c_mandatory_fields.length;i++) {
        if($("#"+c_form+"_"+c_mandatory_fields[i]).val() == "") {
          error = 1;
          $("#check_"+c_form+"_"+c_mandatory_fields[i]).addClass('font_red_color');
        } else {
          $("#check_"+c_form+"_"+c_mandatory_fields[i]).removeClass('font_red_color');
        }
        if(c_mandatory_fields[i] == 'confirm_password') {

          if($("#"+c_form+"_confirm_password").val() != $("#"+c_form+"_password").val()) {
            error = 1;
            $("#check_"+c_form+"_"+c_mandatory_fields[i]).addClass('font_red_color');
          }
        }
        if(c_mandatory_fields[i] == 'email') {
          if(CheckEMail($("#"+c_form+"_email").val()) == false) {
            error = 1;
            $("#check_"+c_form+"_"+c_mandatory_fields[i]).addClass('font_red_color');
          }
        }
	if(c_mandatory_fields[i] == 'semail') {
          if(CheckEMail($("#"+c_form+"_semail").val()) == false) {
            error = 1;
            $("#check_"+c_form+"_"+c_mandatory_fields[i]).addClass('font_red_color');
          }
        }
        if(c_mandatory_fields[i] == 'mail') {
          if(CheckEMail($("#"+c_form+"_mail").val()) == false) {
            error = 1;
            $("#check_"+c_form+"_"+c_mandatory_fields[i]).addClass('font_red_color');
          }
        }
	if(c_mandatory_fields[i] == 'code') {
          if($("#"+c_form+"_code").val() != "Enter Code") {
            error = 1;
            $("#check_"+c_form+"_"+c_mandatory_fields[i]).addClass('font_red_color');
          }
        }
      }      
      if(error == 1)
        return false;
      else  {

        return true;
      }
    }

//solutiob ajax content
function GET_SOL_DATA(get_vals) {
  $('#content').DropOutRight(500);
  GetContent(get_vals);
  return false;
}

function Reinit_Thikbox() {
  tb_init('a.thickbox, area.thickbox, input.thickbox');
    imgLoader = new Image();// preload image
    imgLoader.src = tb_pathToImage;
}

function GetContent(get_vals) {
  $.ajax({
      url: _base_url + "get_content.php"+get_vals,
      cache: false,
      success: function(html){
        $("#content").empty();
        $("#content").append(html);
        $("#breadcrumb").empty();
        $("#breadcrumb").append($("#breadcrumb_backup").html());
        $('#content').DropInRight(500, null, 'easeout');
    Reinit_Thikbox();
    $(function() {
        $('a[@rel*=gallery]').lightBox();
        $('a.gallery').lightBox();
    });

    }
  });
}


function switch_divs(div_to_hide, div_to_show) {
  $('#'+div_to_hide).BlindUp(500);
  $('#'+div_to_hide).hide();
  $('#'+div_to_show).BlindDown(500, null, 'easeout');
  $('#'+div_to_show).show();
}

// function GetOptions(this_id, change_next, sections){
//   $.ajax({
//       url: _base_url + "get_select.php?id="+$(this_id).val()+"&section="+sections,
//       cache: false,
//       success: function(html){
//       $(change_next).empty();
//     $(change_next).html(html);
//     }
// });
// }


/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Mr J | http://www.huntingground.net/ */

scrollStep=3

timerLeft=""
timerRight=""

function toLeft(id){
  document.getElementById(id).scrollLeft=0
}

function scrollDivLeft(id){
  clearTimeout(timerRight) 
  document.getElementById(id).scrollLeft+=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10)
}

function scrollDivRight(id){
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft-=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10)
}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}

function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}
// PRODUCT_DIVS
function ShowDiv(id){
  document.getElementById(id).style.display = 'block';
}
function HidesDiv(id){
  document.getElementById(id).style.display = 'none';
}

  var keywords =  "Search";
  var semail =  "Email";
  var code =  "Enter Code";
  var full_name =  "Name";

function make_blank(name1){
  if(document.getElementById(name1).value != window[name1]) { }
  else { document.getElementById(name1).value =""; }
}
function refill(name1){
  if(document.getElementById(name1).value != "") { }
  else { document.getElementById(name1).value = window[name1]; }
}

function GetOptions(this_id, change_next, sections){

  if(sections == 'state'){
    if($(this_id).val() == 'USA' || $(this_id).val() ==  'Canada'){
      document.getElementById('state_select_block').style.display = 'block'; 
    }
    else{
      document.getElementById('state_select_block').style.display = 'none'; 
    }
  }
  $.ajax({
      url: _base_url + "get_select.php?id="+$(this_id).val()+"&section="+sections,
      cache: false,
      success: function(html){
      $(change_next).empty();
    $(change_next).html(html);
    }
});
}

function GetMethod(id){
$("#PayPal").removeClass('img_border');
$("#Visa").removeClass('img_border');
$("#MasterCard").removeClass('img_border');
$("#AmericanExpress").removeClass('img_border');
$("#"+id).addClass('img_border');
//  alert(_base_url + "get_select.php?id="+id+"&section=method_layout");
  $.ajax({
      url: _base_url + "get_select.php?id="+id+"&section=method_layout",
      cache: false,
      success: function(html){
// alert(html);
      $('#card_data').empty();
    $('#card_data').html(html);
      $('#pay_hidden_data').empty();
$('#pay_hidden_data').html("<input type=\"hidden\" name=\"payment_method\" id=\"payment_method\" value=\""+id+"\">");
    }
});
}
