/**
*
*  Javascript sprintf
*  http://www.webtoolkit.info/
*
*
**/

sprintfWrapper = {

  init : function () {

    if (typeof arguments == "undefined") { return null; }
    if (arguments.length < 1) { return null; }
    if (typeof arguments[0] != "string") { return null; }
    if (typeof RegExp == "undefined") { return null; }

    var string = arguments[0];
    var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g);
    var matches = new Array();
    var strings = new Array();
    var convCount = 0;
    var stringPosStart = 0;
    var stringPosEnd = 0;
    var matchPosEnd = 0;
    var newString = '';
    var match = null;

    while (match = exp.exec(string)) {
      if (match[9]) { convCount += 1; }

      stringPosStart = matchPosEnd;
      stringPosEnd = exp.lastIndex - match[0].length;
      strings[strings.length] = string.substring(stringPosStart, stringPosEnd);

      matchPosEnd = exp.lastIndex;
      matches[matches.length] = {
        match: match[0],
        left: match[3] ? true : false,
        sign: match[4] || '',
        pad: match[5] || ' ',
        min: match[6] || 0,
        precision: match[8],
        code: match[9] || '%',
        negative: parseInt(arguments[convCount]) < 0 ? true : false,
        argument: String(arguments[convCount])
      };
    }
    strings[strings.length] = string.substring(matchPosEnd);

    if (matches.length == 0) { return string; }
    if ((arguments.length - 1) < convCount) { return null; }

    var code = null;
    var match = null;
    var i = null;

    for (i=0; i<matches.length; i++) {

      if (matches[i].code == '%') { substitution = '%' }
      else if (matches[i].code == 'b') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2));
        substitution = sprintfWrapper.convert(matches[i], true);
      }
      else if (matches[i].code == 'c') {
        matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument)))));
        substitution = sprintfWrapper.convert(matches[i], true);
      }
      else if (matches[i].code == 'd') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 'f') {
        matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 'o') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 's') {
        matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length)
        substitution = sprintfWrapper.convert(matches[i], true);
      }
      else if (matches[i].code == 'x') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 'X') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
        substitution = sprintfWrapper.convert(matches[i]).toUpperCase();
      }
      else {
        substitution = matches[i].match;
      }

      newString += strings[i];
      newString += substitution;

    }
    newString += strings[i];

    return newString;

  },

  convert : function(match, nosign){
    if (nosign) {
      match.sign = '';
    } else {
      match.sign = match.negative ? '-' : match.sign;
    }
    var l = match.min - match.argument.length + 1 - match.sign.length;
    var pad = new Array(l < 0 ? 0 : l).join(match.pad);
    if (!match.left) {
      if (match.pad == "0" || nosign) {
        return match.sign + pad + match.argument;
      } else {
        return pad + match.sign + match.argument;
      }
    } else {
      if (match.pad == "0" || nosign) {
        return match.sign + match.argument + pad.replace(/0/g, ' ');
      } else {
        return match.sign + match.argument + pad;
      }
    }
  }
}

sprintf = sprintfWrapper.init;

/**
*
*  Javascript sprintf end
*  
*
**/


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(LANG_ERROR_CC_NAME);
     document.orderform.trnCardOwner.focus();
     return false;
 }

 if (!document.orderform.trnCardType.value) {
     alert(LANG_ERROR_CC_TYPE);
     document.orderform.trnCardType.focus();
     return false;
 }

 if (!document.orderform.trnCardNumber.value) {
      alert(LANG_ERROR_CC_NUM);
     return false;
 }
 
 if (!document.orderform.trnCardCvd.value) {
     alert(LANG_ERROR_CC_CODE);
    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(LANG_ERROR_CC_EXPIRE);
        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.orderform.trnCardOwner.value) {
	     alert(LANG_ERROR_CC_NAME);
	     document.orderform.trnCardOwner.focus();
	     return false;
 }
	 
  if (!document.ccform.get_cc_type.value) {
      alert(LANG_ERROR_CC_TYPE);
      document.ccform.get_cc_type.focus();
     return false;
  }


 if (!document.ccform.get_cc_num.value) {
      alert(LANG_ERROR_CC_NUM);
      document.ccform.get_cc_num.focus();
     return false;
  }

 if (!document.ccform.get_month.value) {
      alert(LANG_ERROR_CC_MONTH);
      document.ccform.get_month.focus();
     return false;
  }
 if (!document.ccform.get_year.value) {
     document.ccform.get_year.focus();
    return false;
 }
 
 if (!document.ccform.get_cc_code.value) {
      alert(LANG_ERROR_CC_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_colonia.value =  document.UserForm.get_shipping_colonia.value;
       document.UserForm.get_city.value =  document.UserForm.get_shipping_city.value;
       document.UserForm.get_postal_code.value = document.UserForm.get_shipping_postal_code.value;

//       document.UserForm.get_apt_number.value = document.UserForm.get_shipping_apt_number.value;
       document.UserForm.get_ref_state.value = document.UserForm.get_shipping_ref_state.value;
       document.UserForm.get_cell_num.value = document.UserForm.get_shipping_cell_num.value;
       document.UserForm.get_home_num.value = document.UserForm.get_shipping_home_num.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_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_colonia.value = "";
       document.UserForm.get_postal_code.value = "";
//       document.UserForm.get_apt_number.value = "";
       document.UserForm.get_ref_state.value = "";
       document.UserForm.get_cell_num.value = "";
       document.UserForm.get_home_num.value = "";       
       
/*       document.UserForm.get_ref_state.value = "";
       document.UserForm.get_ref_country.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_apt_number)
           document.UserForm.get_shipping_apt_number.value = document.UserForm.get_apt_number.value;
*/
       if (document.UserForm.get_ref_state)
           document.UserForm.get_shipping_ref_state.value = document.UserForm.get_ref_state.value;

       if (document.UserForm.get_shipping_cell_num)
           document.UserForm.get_shipping_cell_num.value = document.UserForm.get_cell_num.value;
       if (document.UserForm.get_shipping_home_num)
           document.UserForm.get_shipping_home_num.value = document.UserForm.get_home_num.value;
      
       if (document.UserForm.get_shipping_city)
       document.UserForm.get_shipping_city.value =  document.UserForm.get_city.value;

       if (document.UserForm.get_shipping_colonia)
       document.UserForm.get_shipping_colonia.value =  document.UserForm.get_colonia.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_apt_number) 
           document.UserForm.get_shipping_apt_number.value ="";
*/
       if (document.UserForm.get_shipping_ref_state) 
           document.UserForm.get_shipping_ref_state.value ="";
       
       if (document.UserForm.get_shipping_cell_num) 
           document.UserForm.get_shipping_cell_num.value ="";
       
       if (document.UserForm.get_shipping_home_num) 
           document.UserForm.get_shipping_home_num.value ="";
       
       if (document.UserForm.get_shipping_city) 
       document.UserForm.get_shipping_city.value = "";

       if (document.UserForm.get_shipping_colonia) 
       document.UserForm.get_shipping_colonia.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)
{
  return "";
  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_keyword.value == '' || document.left_advanced_search_form.get_keyword.value == 'Search Game') 
  {
      alert("Please select search criteria!");
      document.left_advanced_search_form.get_keyword.focus();
      return false;
  }


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

  return true;

}

function SetCookie(name, value, expires, path, domain, secure) {

	  var mycookie = name + "=" + escape(value);
	  var myexpires = new Date();
	  myexpires.setTime(myexpires.getTime() + 5000);
	  mycookie = mycookie + "; myexpires=" + myexpires.toGMTString();
	  document.cookie = mycookie;
	}

function GetCookie(name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;

	  while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg)
	      return getCookieVal(j);
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0)
	      break;
	  }

	  return null;
}

var img_i = 1;
var video_timeout;
function changeImages(id, imagesCount, images_dir) {
  i = img_i;
  video_timeout = setTimeout("changeImages2("+id+", "+imagesCount+", '"+images_dir+"',"+ i+");", 1000);
}

function changeImages2(id, imagesCount,images_dir, i)
{
  el = document.getElementById(id); 
  el.src = images_dir + sprintf("%08.0d", i) + ".jpg";  
  img_i = i + 1;
  if (img_i == imagesCount){
    clearTimeout(video_timeout);
    return "false";  
  }  
  changeImages(id, imagesCount, images_dir, i);
  return "false";
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
