var tip_visible = true;
var preloadFlag = false;

function preloadImages() {
  if (document.images) {
    preloadFlag = true;
  }
}

function show_edit_content_popup(id,x,y){
  document.getElementById('edit_content_popup').style.display = 'block';
  document.getElementById('edit_content_popup').style.top = y;
  document.getElementById('edit_content_popup').style.left = x;  
}
 
 
 
function CheckOrderForm() {

 if (!document.orderform.trnCardOwner.value) {
     alert("Please fill Name on Card!");
     document.orderform.trnCardOwner.focus();
     return false;
 }


 if (!document.orderform.trnCardType.value) {
     alert("Please fill Card Type!");
     document.orderform.trnCardType.focus();
     return false;
 }

 if (!document.orderform.trnCardNumber.value) {
      alert('Invalid Credit Card Number');
     return false;
 }

 
 /*
  if (PositiveInteger(document.orderform.trnCardNumber) == true) {
    if (CreditModCheck(document.orderform.trnCardNumber) == false) {
      alert('Invalid Credit Card Number');
      return false;
    }
  } 
  else{
    return false;
  } 
   */
   
  var nowDate = new Date();
  var nowYear = nowDate.getYear();
  var nowMonth = nowDate.getMonth() + 1;
  var expYear = document.orderform.trnExpYear.value;
  var expMonth = document.orderform.trnExpMonth.value;


  if (expYear == "05") {
     expYear = 2005;
  }

  if (expYear == "06") {
     expYear = 2006;
  }

  if (expYear == "07") {
     expYear = 2007;
  }

  if (expYear == "08") {
     expYear = 2008;
  }

  if (expYear == "09") {
     expYear = 2009;
  }


  if (expYear == "10") {
     expYear = 2010;
  }

  if (expYear == "11") {
     expYear = 2011;
  }

  if (expYear == "12") {
     expYear = 2012;
  }

  if (expYear == "13") {
     expYear = 2013;
  }

  if (expYear == "14") {
     expYear = 2014;
  }

  if (expYear == "15") {
     expYear = 2015;
  }
  
  if (expYear == "16") {
     expYear = 2016;
  }


  if (nowYear == 0)
  {
     nowYear = 2000;
  }

  if (nowYear < 1900)
  {
     nowYear = nowYear + 1900;
  }

  if (expYear <= nowYear)
  {
     if (expMonth < nowMonth)
     {
        alert("According to the date you have entered, your credit card has expired")
        document.orderform.trnExpMonth.focus();
        return false;
     }
  }

 return true;
}


function show_item_popup(id,tooltip_id){
  tmout = setTimeout("xajax_load_tooltip_content('"+id+"','var_tooltip_"+tooltip_id+"','tooltip_"+tooltip_id+"')",250);
}

function hide_item_popup(tooltip_id){
    setTimeout("hideTip('"+tooltip_id+"')",50);
    clearTimeout(tmout);  
}


function checkItAlphaNumeric(evt){
      
    evt = (evt) ? evt : window.event

    var who= evt.target || evt.srcElement;
    
    who.setAttribute('maxlength', who.value.length + 1);

    var charCode = (evt.which) ? evt.which : evt.keyCode

   if (charCode == 45) 
    return false; 
    
    if (charCode == 17) 
    return false; 
    
           
       
    return true;    
    
}

function checkItNoPaste(evt){
   evt = (evt) ? evt : window.event;
   input= evt.target || evt.srcElement;
   input.setAttribute('maxlength', input.value.length + 1); 
}

function checkItNumeric(evt){

    evt = (evt) ? evt : window.event

    var charCode = (evt.which) ? evt.which : evt.keyCode
    

    if (charCode > 31 && (charCode < 48 || charCode > 57)) {

        if((charCode >= 96) && (charCode <= 105))

           return true

        else

           return false

    }

    return true

}

function checkItSelected(evt){

   return false;  

    evt = (evt) ? evt : window.event

    var charCode = (evt.which) ? evt.which : evt.keyCode
    
    alert(charCode);

    if (charCode > 31 && (charCode < 48 || charCode > 57)) {

        if((charCode >= 96) && (charCode <= 105))

           return true

        else 
           return false

    }

    return false

}




function clear_advsearch_form(){
  if (document.advanced_search_form){
  elements = document.advanced_search_form.elements;
  for (i=0;i<elements.length; i++){
       if (document.advanced_search_form.elements[i].type == 'text')
       document.advanced_search_form.elements[i].value = '';
       if (document.advanced_search_form.elements[i].type == 'textarea')
       document.advanced_search_form.elements[i].value = '';
       if (document.advanced_search_form.elements[i].type == 'select-one')
       document.advanced_search_form.elements[i].value = '';
       if (document.advanced_search_form.elements[i].type == 'checkbox')
       document.advanced_search_form.elements[i].checked = false;
       if (document.advanced_search_form.elements[i].type == 'radio' && document.advanced_search_form.elements[i].value != 0)
       document.advanced_search_form.elements[i].checked = false;
       if (document.advanced_search_form.elements[i].type == 'radio' && document.advanced_search_form.elements[i].value == 0)
       document.advanced_search_form.elements[i].checked = true;
       if (document.advanced_search_form.elements[i].type == 'radio' && document.advanced_search_form.elements[i].value == 'and')
       document.advanced_search_form.elements[i].checked = true;
  }}
}

function checkItNumeric(evt) {

    evt = (evt) ? evt : window.event

    var charCode = (evt.which) ? evt.which : evt.keyCode

    if (charCode > 31 && (charCode < 48 || charCode > 57)) {

        if((charCode >= 96) && (charCode <= 105))

           return true

        else

           return false

    }

    return true

}

function show_div(id){
    divname = eval(id);
    if (divname.style.display == 'block') {
       divname.style.display = 'none';
    } else
       divname.style.display = 'block';
  }

  function show_div_if_hidden(id){
    divname = eval(id);
    if (divname.style.display == 'none') {
       divname.style.display = 'block';
    } 
  }
  
function hide_div(id){
    divname = eval(id);
    divname.style.display = 'none';
}

  
  function show_div2(id){
    divname = eval(id);
    if (divname.style.display == 'none') {
       divname.style.display = '';
    } else
       divname.style.display = 'none';
  }
  
  function enter_click(event){
  if(event.keyCode==13){ 
        return true;
    } 
  else return false;
}
  
  
 function show_div_only(id){
 
    for (i=0;i<=4;i++){
     divname = eval('div_'+i);
     divname.style.display = 'none'; 
    }
    
 
    divname = eval('div_'+id);
    if (divname.style.display == 'none') {
       divname.style.display = 'block';
    } 
    
    divname = eval('div_back');     
    

    if (id > 0) {
       divname.style.display = 'block';
    } else {
    divname.style.display = 'none';
    }  
       
}
  
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);

// Image Overload
function onover(img, img_file) {
   img.src = img_file;
   return false;
}

// Image Overload
function onmenuover(img) {
   img.src = img.src.replace(/\.gif/, "_a.gif")
   return false;
}

function onmenuout(img) {
   img.src = img.src.replace(/\_\a\.gif/, ".gif") 
   return false;
}


function check_review(review){
  if (review.length < 30){
  alert("Your review must be at least 30 characters in length!");
  return false;
  }
  if (review.length > 6400){
  alert("Your review is too long. It should be maximum 6400 characters in length!");
  return false;
  }
  return true;
}


function hide_long_reviews(){
   
}




var imageoff = new Image();
var imageon  = new Image();/*
imageoff.src = "images/arrow_n.gif";
imageon.src  = "images/arrow_a.gif";   */

function onImageOn(img) {
   img.src = imageon.src;
}

function onImageOff(img) {
   img.src = imageoff.src;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}



function checkCCInfo() {

 if (!document.ccform.get_cc_type.value) {
      alert("Please enter Card Type!");
      document.ccform.get_cc_type.focus();
     return false;
  }


 if (!document.ccform.get_cc_num.value) {
      alert("Please enter Card #!");
      document.ccform.get_cc_num.focus();
     return false;
  }

 if (!document.ccform.get_month.value) {
      alert("Please enter Card Expire Date!");
      document.ccform.get_month.focus();
     return false;
  }

 if (!document.ccform.get_cc_code.value) {
      alert("Please enter Verification Code!");
      document.ccform.get_cc_code.focus();
     return false;
  }



  return true;
}



function QuickLogin() {

   if (!document.loginform.username.value) {
      alert("Please enter user name!");
      document.loginform.username.focus();
     return false;
  }


   if (!document.loginform.password.value) {
      alert("Please enter password!");
      document.loginform.password.focus();
     return false;
  }

  return true;
}

 
function confirm_del() {
  var reply = confirm("This will permanantly delete this record!");

  if(reply) {
     return true;
   } else {
     return false;
   }
}

  
function AutoFillBilling(act) {

  if ( document.UserForm.get_auto_fill_shipping.checked) {
       document.UserForm.get_address.value = document.UserForm.get_shipping_address.value;
       document.UserForm.get_address2.value = document.UserForm.get_shipping_address2.value;
       document.UserForm.get_city.value =  document.UserForm.get_shipping_city.value;
       document.UserForm.get_ref_country.value =  document.UserForm.get_shipping_ref_country.value;
       
       
       document.UserForm.get_ref_state.options.length = 0; 
       
       states = document.UserForm.get_shipping_ref_state.options;
       states_count = document.UserForm.get_shipping_ref_state.options.length;  
       for (i=0;i<states_count;i++){
          document.UserForm.get_ref_state.options[i] =  new Option(states[i].text,states[i].value);   
       }
       
       
       
       document.UserForm.get_ref_state.value =  document.UserForm.get_shipping_ref_state.value;
       document.UserForm.get_postal_code.value = document.UserForm.get_shipping_postal_code.value;
       document.UserForm.get_ref_country.value = document.UserForm.get_shipping_ref_country.value;

  } else {
       document.UserForm.get_address.value ="";
       document.UserForm.get_address2.value ="";
       document.UserForm.get_city.value = "";
       document.UserForm.get_ref_country.value = "";
       document.UserForm.get_postal_code.value = "";
       document.UserForm.get_ref_state.value = "";
  }

}


function AutoFillShipping(act) {

  if ( document.UserForm.get_auto_fill_shipping.checked) {
  
       if (document.UserForm.get_shipping_address) 
       document.UserForm.get_shipping_address.value = document.UserForm.get_address.value;
       
       if (document.UserForm.get_shipping_address2)
       document.UserForm.get_shipping_address2.value = document.UserForm.get_address2.value;
       
       if (document.UserForm.get_shipping_city)
       document.UserForm.get_shipping_city.value =  document.UserForm.get_city.value;
       
       if (document.UserForm.get_shipping_ref_country)
       document.UserForm.get_shipping_ref_country.value =  document.UserForm.get_ref_country.value;
       
       document.UserForm.get_shipping_ref_state.options.length = 0; 
       states = document.UserForm.get_ref_state.options;
       states_count = document.UserForm.get_ref_state.options.length;  
       for (i=0;i<states_count;i++){
          document.UserForm.get_shipping_ref_state.options[i] =  new Option(states[i].text,states[i].value);   
       }
       
       if (document.UserForm.get_shipping_ref_state) 
       document.UserForm.get_shipping_ref_state.value =  document.UserForm.get_ref_state.value;
       
       if (document.UserForm.get_shipping_postal_code)  
       document.UserForm.get_shipping_postal_code.value = document.UserForm.get_postal_code.value;
       
       if (document.UserForm.get_shipping_ref_country) 
       document.UserForm.get_shipping_ref_country.value = document.UserForm.get_ref_country.value;
       
       if (document.UserForm.get_shipping_phone)  
       document.UserForm.get_shipping_phone.value = document.UserForm.get_phone.value; 
       
       if (document.UserForm.get_shipping_fax) 
       document.UserForm.get_shipping_fax.value = document.UserForm.get_fax.value; 
       

  } else {
       if (document.UserForm.get_shipping_address) 
       document.UserForm.get_shipping_address.value ="";
       
       if (document.UserForm.get_shipping_address2) 
       document.UserForm.get_shipping_address2.value ="";
       
       if (document.UserForm.get_shipping_city) 
       document.UserForm.get_shipping_city.value = "";
       
       if (document.UserForm.get_shipping_ref_country)
       document.UserForm.get_shipping_ref_country.value = "";
       
       if (document.UserForm.get_shipping_postal_code)   
       document.UserForm.get_shipping_postal_code.value = "";
       
       if (document.UserForm.get_shipping_ref_state)  
       document.UserForm.get_shipping_ref_state.value = "";
       
       if (document.UserForm.get_shipping_phone) 
       document.UserForm.get_shipping_phone.value =  "";
       
        if (document.UserForm.get_shipping_fax) 
       document.UserForm.get_shipping_fax.value = "";
  }

}

function onCountryChange(act) {
  document.UserForm.act.value=act;
  document.UserForm.submit();
  return true;
}
  
function viewform2(m, w, h) {
   alter=(settings);
   var scroll = 'yes';
   var settings;
   var LeftPosition;
   var TopPosition;
   var win;

   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

   settings = 'height='+h+', width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
   settings = settings + ', resizable=yes, maximize=yes, status=no,toolbar=no,directories=no,menubar=no,location=no';

   win = window.open(m, 'pre', settings);
   win.name = 'name';
   win.focus();
}


function doPreview(param1, param2)
{

  if (dom) {
    var src = document.getElementById(param1).value;
  } else if (ie) {
    var src = document.all[param1].value;
  }

  if (src.charAt(1)==":") src = "file:/" + src;

  if (dom) {
    document.getElementById(param2).src=src;
  } else if (ie) {
    document.all[param2].src = src;
  }

}

opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
ie = (document.all && !opera)? true : false;
dom = (document.getElementById && !ie && !opera)? true : false;

var expiration = new Date();
expiration.setTime(expiration.getTime() + 3600*3600*3600);


function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

var preloadFlag = false;
function preloadImages() {
  if (document.images) {
    preloadFlag = true;
  }
}

function changeImages() {
  if (document.images && (preloadFlag == true)) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    }
  }
}
 
function CheckAdvancedSearch() {
  if (
      !document.left_advanced_search_form.get_name.value 
     ) 
  {
      alert("Please select search criteria!");
      document.left_advanced_search_form.get_name.focus();
      return false;
  }


  if (document.left_advanced_search_form.get_name.value.indexOf("%") != -1) {
      alert("Delete symbol % from title");
      return false;
  }

  return true;
}
