﻿if (top == self) self.location.href = "default.asp";

function UserSearchEnter(e) {

  var iKeycode = null;
  if (e)
    iKeycode = e.keyCode;
  else
    iKeycode = event.keyCode;

  if (iKeycode == 13)
    UserSearch();
}

function UserSearch() {

  var searchItem = document.getElementById('uxUserSearchbox');
  if (searchItem) {

    var searchValue = searchItem.value;
    searchValue = searchValue.replace(/[^a-zA-Z0-9-_]/g, '');
    searchItem.value = searchValue;

    if (searchValue != '')
      parent.NavContent.document.location = '../searches/searches.aspx?searchtype=user&UserNameorID=' + searchValue;

  }
}

function QuickSearch() {

  Scrub();

  var ageLower = parseInt(document.getElementById('ucQuicksearch_ucFromAge_uxAges').value);
  var ageUpper = parseInt(document.getElementById('ucQuicksearch_ucToAge_uxAges').value);
  var heightLower = parseInt(document.getElementById('ucQuicksearch_ucFromHeight_uxHeights').value);
  var heightUpper = parseInt(document.getElementById('ucQuicksearch_ucToHeight_uxHeights').value);
  var weightLower = parseInt(document.getElementById('ucQuicksearch_ucFromWeight_uxWeights').value);
  var weightUpper = parseInt(document.getElementById('ucQuicksearch_ucToWeight_uxWeights').value);
  var reviewStatus = parseInt(document.getElementById('ucQuicksearch_uxReviewStatus').value);
  var beautyRating = parseInt(document.getElementById('ucQuicksearch_uxBeautyRating').value);
  var introSelect = parseInt(document.getElementById('ucQuicksearch_uxIntroSelect').value);
  var sortOrder = new String(document.getElementById('ucQuicksearch_uxSortOrder').value);

  if (isNaN(ageLower)) ageLower = -1;
  if (isNaN(ageUpper)) ageUpper = -1;
  if (isNaN(heightLower)) heightLower = -1;
  if (isNaN(heightUpper)) heightUpper = -1;
  if (isNaN(weightLower)) weightLower = -1;
  if (isNaN(weightUpper)) weightUpper = -1;
  if (isNaN(reviewStatus)) reviewStatus = 1;
  if (isNaN(beautyRating)) beautyRating = 0;
  if (isNaN(introSelect)) introSelect = -1;

  var submitForm = getNewSubmitForm();
  createNewFormElement(submitForm, "AgeLower", ageLower);
  createNewFormElement(submitForm, "AgeUpper", ageUpper);
  createNewFormElement(submitForm, "HeightLower", heightLower);
  createNewFormElement(submitForm, "HeightUpper", heightUpper);
  createNewFormElement(submitForm, "WeightLower", weightLower);
  createNewFormElement(submitForm, "WeightUpper", weightUpper);
  createNewFormElement(submitForm, "ReviewStatus", reviewStatus);
  createNewFormElement(submitForm, "BeautyRating", beautyRating);
  createNewFormElement(submitForm, "IntroSelect", introSelect);
  createNewFormElement(submitForm, "SortOrder", sortOrder);
  submitForm.action = "../searches/searches.aspx?searchtype=quick";
  submitForm.target = 'NavContent';
  submitForm.submit();

  setTimeout(function() { RemoveForm(submitForm) }, 500);
}

function RemoveForm(inputForm) {
  if (inputForm)
    document.body.removeChild(inputForm);
}

function getNewSubmitForm() {
  var submitForm = document.createElement("FORM");
  document.body.appendChild(submitForm);
  submitForm.method = "POST";
  submitForm.style.display = 'none';
  return submitForm;
}

function createNewFormElement(inputForm, elementName, elementValue) {
  var newElement = document.createElement("<input name='" + elementName + "' type='hidden' />");
  inputForm.appendChild(newElement);
  newElement.value = elementValue;
  return newElement;
}

function Scrub() {
  if (document.all || document.getElementById) {
    var objID = '';
    var tempobj = '';
    for (i = 0; i < document.forms[0].length; i++) {
      tempobj = document.forms[0].elements[i];
      cleanupscript(tempobj);
    }
  }
}

function cleanupscript(obj) {
  var the_value = new String(obj.value);
  if (the_value != '') {
    the_value = RemoveBad(the_value);
    obj.value = the_value;
  }
}

function RemoveBad(strTemp) {
  strTemp = strTemp.replace(/\<|\>|\%|\(|\)|&|#|;/g, '');
  return strTemp;
}

function GetGallery(gallery) {
  var url = '../photogallery/featuregallery.aspx?gallery=' + gallery;
  document.location = url;
}

function Resize() {

  var w = ReturnWindowWidth();

  Gallery(w);

  var label = document.getElementById('uxMemberlevel');
  var ml = 0;

  if (label.innerText)
    ml = parseInt(label.innerText);
  else if (label.textContent)
    ml = parseInt(label.textContent);

  if (ml > 0) {

    var narrow;
    var wide;

    switch (ml) {
      case 1: narrow = document.getElementById('bronzechartnarrow'); wide = document.getElementById('bronzechartwide');
        break;
      case 2: narrow = document.getElementById('silvernarrow'); wide = document.getElementById('silverwide');
        break;
      case 3: narrow = document.getElementById('goldnarrow'); wide = document.getElementById('goldwide');
        break;
      case 4: narrow = document.getElementById('platinumnarrow'); wide = document.getElementById('platinumwide');
        break;
    }

    if (wide && narrow) {
      if (w < 910) {
        wide.style.display = 'none';
        narrow.style.display = 'block';
      } else {
        wide.style.display = 'block';
        narrow.style.display = 'none';
      }
    }
  }

}

function Gallery(w) {

  var galleryphotodiv = document.getElementById('galleryphotodiv');
  divW = w - 275;
  galleryphotodiv.style.width = divW + 'px';

}

function GetPic(testimonial, pic) {
  ClosePic();
  var picDiv = document.getElementById('testimonialpicdiv');
  var picImg = document.getElementById('picImg');
  var url = '../scripts/testimonialimage.aspx?img=' + pic + '&testimonial=' + testimonial;
  picImg.src = url;

  var t = document.getElementById('TestimonialPanel').offsetTop;
  picDiv.style.top = t - 200 + 'px';

  picDiv.style.display = 'block';
}

function ClosePic() {
  var picDiv = document.getElementById('testimonialpicdiv');
  picDiv.style.display = 'none';
}

function GetTestimonials() {
  top.document.location = '../pub/testimonials.aspx';
}

function Join() {
  //top.document.location = 'https://secure.hotrussianbrides.com/membership/default.aspx';
  top.document.location = '../profile/join.aspx';
}

function FeaturedLady() {
  var label = document.getElementById('uxFeaturedLady');
  if (label) {
    var featuredLady = 0;

    if (label.innerText)
      featuredLady = parseInt(label.innerText);
    else if (label.textContent)
      featuredLady = parseInt(label.textContent);

    if (featuredLady > 0) {
      var seenit = GetCookieValue('FeaturedLady');
      if (seenit != featuredLady) {
        var featuredLadyDiv = document.getElementById('FeaturedLadyDiv');
        var url = '../profile/featuredladypop.aspx';
        var newFrame = '<iframe src="' + url + '" id="flFrame" name="flFrame" frameborder="0" width="420" height="310" scrolling="no"></iframe>';
        featuredLadyDiv.innerHTML = newFrame;
        featuredLadyDiv.style.display = 'block';
        setTimeout("CloseFeaturedLady()", 90000);
      }
    }
  }
}

function CloseFeaturedLady() {
  var label = document.getElementById('uxFeaturedLady');
  if (label) {
    var featuredLady = 0;

    if (label.innerText)
      featuredLady = parseInt(label.innerText);
    else if (label.textContent)
      featuredLady = parseInt(label.textContent);

    if (featuredLady > 0) {
      document.getElementById('FeaturedLadyDiv').style.display = 'none';
      CreateCookie('FeaturedLady', featuredLady, 1);
    }
  }
}

function AutoCloseAd() {
  var adPanel = document.getElementById('PopupAdPanel');
  if (adPanel) {
    setTimeout(function() { CloseAd() }, 9000);
  }
}

function CloseAd() {
  var adPanel = document.getElementById('PopupAdPanel');
  if (adPanel) {
    adPanel.style.display = 'none';
    CreateCookie('Ad', 'sSdA142-z', 1);
  }
}

function NoProfile() {
  var oops = GetQueryStringItem('oops');
  if (oops == 'p') {
    var newDiv = document.createElement('div');
    newDiv.id = "Oops";
    newDiv.innerHTML = 'The profile you were trying to view is no longer active<br/>or is invalid.';

    document.body.appendChild(newDiv);
    setTimeout(function() { HideOops() }, 5000);
  }
}

function HideOops() {
  var newDiv = document.getElementById('Oops');
  if (newDiv) {
    document.body.removeChild(newDiv);
  }
}

var OnResize = "Resize()";
window.onresize = function() { eval(OnResize); };