﻿function UpdateVideo(result){
    $("#webtv").html(result);

        var d = 'webtvitems';
        var d2 = "currentid";

        $("#"+d+" img").removeClass("webtvselected");
        $("#small"+currentid).addClass("webtvselected");
}

function UpdateVideos(result){
    $("#webtvitems").html(result);

        var d = 'webtvitems';
        var d2 = "currentid";
        $("#"+d+" img").removeClass("webtvselected");
        $("#small"+currentid).addClass("webtvselected");
}

function UpdateVideoBorder(){
    $(document).ready(function(){
        $("#small"+currentid).addClass("webtvselected"); })
}

function bannerChecker()
{
	var topbanner = document.getElementById("topbanner"); 
	var bannerHeight = topbanner.offsetHeight;
	if(bannerHeight < 50)
		topbanner.className = "noBanner";
}

function UpdateFullPhoto(itemid, result){
    $("#fullPhoto").html(result);

    $("img").css("border","");
    $("#small"+currentid).css("border","2px solid black"); 
}

function UpdateThumbnails(position, max, result, gdc){
    $("#fotoGal"+gdc).html(result); 

    $("#small"+currentid).css("border","2px solid black"); 
}

function UpdateGallery(result){
    $("#fotoItems").html(result);
}

function UpdateBorder(){
    $("#small"+currentid).css("border","2px solid black");  
}

function UpdateSearch(result){
    $("#fotoItems").html(result);

    $("#small"+currentid).css("border","2px solid black"); 
}

function UpdatePhotoVideo(result){
    $("#galleries").html(result);

    $("#small"+currentid).css("border","2px solid black"); 
}

function UpdateFullVideo(itemid, result){
    $("#fullPhoto").html(result);

    $("img").css("border","");
    $("#small"+currentid).css("border","2px solid black");   
}

function UpdateRateButton(result){
    $("#rateButtons").html(result);
}

function UpdateRateButtons(result,gdc){
    $("#rateButtons"+gdc).html(result);
}
function SubmitSearch1(searchWords)
	{

		if (searchWords.length != 0)
		{	
			//document.forms[0].method = "post";
			document.forms[0].action = "http://"+location.hostname+ "/SearchResults.aspx?q=" + encodeURI(searchWords);
			document.forms[0].submit();
		
		}
		return false;
	}
	
function IsValidEmail(val)
{
    var rx = new RegExp("^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$");
    var matches = rx.exec(val);                     
    return (matches != null && val == matches[0]);
}
	
function checkEnter(e,caller) //e is event object passed from function invocation
{

 var characterCode //literal character code will be stored in this variable
 

 if(e && e.which ||e.which == 0)
 { //if which property of event object is supported (NN4)

 e = e
 characterCode = e.which //character code is contained in NN4's which property
 }
else
{
 e = event
 characterCode = e.keyCode //character code is contained in IE's keyCode property
 }

 if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
 {
	
	 if(document.getElementById('querySearch') != "")
	{
		SHSearch();
     } 
 }
 }
 

function openPopUp(pUrl,w,h) {	
	var l= getWindowPosition("width")-(w/2);
	var t= getWindowPosition("height")-(h/2);
	window.open(pUrl, 'popUp', 'width='+w+',height='+h+',left='+l+',top='+t+',resizable=yes');
}

function openPopUp(pUrl,w,h, title) {	
	var l= getWindowPosition("width")-(w/2);
	var t= getWindowPosition("height")-(h/2);
	window.open(pUrl, title, 'width='+w+',height='+h+',left='+l+',top='+t+',resizable=yes');
}
function getWindowPosition(dim){
  var myWidth = 0, myHeight = 0;
// a little check cos IE doens't support window innerWidth

  if(typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
 
    theTop = document.documentElement.scrollTop;
    theHeight = window.innerHeight/2;
  
	theLeft = document.documentElement.scrollLeft;
    theWidth  = window.innerWidth/2;
    
    myWidth = theLeft+theWidth;
    myHeight = theTop+theHeight;

  }
  else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) {
    //IE 6+ in 'standards compliant mode'
    theTop = document.documentElement.scrollTop;
    theHeight = document.documentElement.clientHeight/2;
  
	theLeft = document.documentElement.scrollLeft;
    theWidth  = document.documentElement.clientWidth/2;
       
    myWidth = theLeft+theWidth;
    myHeight = theHeight+theTop;

  } else if( document.body && (document.body.clientWidth || document.body.clientHeight )) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  if(dim == 'width'){
	return myWidth;
  }
  else{
	return myHeight;
  }

}

function showGirlContent(chActive)
                        {
                            var tabArray = new Array;
                            tabArray[0] = 'pigerne';
                            tabArray[1] = 'maend';      
                            for (i=0; i<2; i++)
                            {
                                if (tabArray[i]==chActive)
                                {
                                    document.getElementById(tabArray[i]+'_header').className='item active';
	                                document.getElementById('girlsteaser-'+tabArray[i]).style.visibility="";
                                }
                                else
                                {
                                    document.getElementById(tabArray[i]+'_header').className='item';
	                                document.getElementById('girlsteaser-'+tabArray[i]).style.visibility="hidden";
                                }
                            }
                            return true;
                        }

//081208 mrr trim spaces
//Removes leading whitespaces
function LTrim( value ) {

var re = /\s*((\S+\s*)*)/;
return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim( value ) {

var re = /((\s*\S+)*)\s*/;
return value.replace(re, "$1");

}

// Removes leading and ending whitespaces
function trim( value ) {

return LTrim(RTrim(value));

}  

//081209 mrr check if a value is empty
function IsEmpty(id){
var obj = document.getElementById(id);
return (obj && trim(obj.value) == "");
}
//081209 mrr validate phone number
  function isInteger(s)
  {   
  for (var i = 0; i < s.length; i++)
  {
  //Check that current character is number.
  var c = s.charAt(i);
  if (((c < "0") || (c > "9")))
  return false;
  }
  //All characters are numbers
  return true;
  }
  
  function trim(s)
  {
  var returnString = "";
  //Search through string's characters one by one.
  //If character is not a whitespace, append to returnString.
  for (var i = 0; i < s.length; i++)
  {
  //Check that current character isn't whitespace.
  var c = s.charAt(i);
  if (c != " ") returnString += c;
  }
  return returnString;
  }
  
  function stripCharsInBag(s, bag)
  {   var i;
  var returnString = "";
  //Search through string's characters one by one
  //If character is not in bag, append to returnString.
  for (var i = 0; i < s.length; i++)
  {
  //Check that current character isn't whitespace.
  var c = s.charAt(i);
  if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
  }

  function checkInternationalPhone(strPhone){
   //non-digit characters which are allowed in phone numbers
  var phoneNumberDelimiters = "()- ";
  //characters which are allowed in international phone numbers
  //(a leading + is OK)
  var validWorldPhoneChars = phoneNumberDelimiters + "+";
  //Minimum no of digits in an international phone no.
  var minDigitsInIPhoneNumber = 8;
  var bracket=3
  strPhone=trim(strPhone)
  if(strPhone.indexOf("+")>1) return false
  if(strPhone.indexOf("-")!=-1)bracket=bracket+1
  if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")> bracket)return false
  var brchr=strPhone.indexOf("(")
  if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
  if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
  s=stripCharsInBag(strPhone,validWorldPhoneChars);
  return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
  }

  function ValidateNumber(phone){
  var Phone=phone;
  if ((Phone.value==null)||(Phone.value=="")){
  alert("Angiv dit telefonnummer.")
  Phone.focus()
  return false
  }
  if (checkInternationalPhone(Phone.value)==false){
  alert("Angiv et gyldigt telefonnummer.")
  Phone.value=""
  Phone.focus()
  return false
  }
  return true
  }  
  
  
/* Page counter functions */   
var Base64 = {

          // private property
          _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

          // public method for encoding
          encode : function (input) {
          var output = "";
          var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
          var i = 0;

          input = Base64._utf8_encode(input);

          while (i < input.length) {

          chr1 = input.charCodeAt(i++);
          chr2 = input.charCodeAt(i++);
          chr3 = input.charCodeAt(i++);

          enc1 = chr1 >> 2;
          enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
          enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
          enc4 = chr3 & 63;

          if (isNaN(chr2)) {
            enc3 = enc4 = 64;
          } else if (isNaN(chr3)) {
            enc4 = 64;
          }

          output = output +
          this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
          this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

          }

          return output;
      },

      // public method for decoding
      decode : function (input) {
          var output = "";
          var chr1, chr2, chr3;
          var enc1, enc2, enc3, enc4;
          var i = 0;

          input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

          while (i < input.length) {

          enc1 = this._keyStr.indexOf(input.charAt(i++));
          enc2 = this._keyStr.indexOf(input.charAt(i++));
          enc3 = this._keyStr.indexOf(input.charAt(i++));
          enc4 = this._keyStr.indexOf(input.charAt(i++));

          chr1 = (enc1 << 2) | (enc2 >> 4);
          chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
          chr3 = ((enc3 & 3) << 6) | enc4;

          output = output + String.fromCharCode(chr1);

          if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
          }
          if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
          }

          }

          output = Base64._utf8_decode(output);

          return output;

      },

      // private method for UTF-8 encoding
      _utf8_encode : function (string) {
          string = string.replace(/\r\n/g,"\n");
          var utftext = "";

          for (var n = 0; n < string.length; n++) {

          var c = string.charCodeAt(n);

          if (c < 128) {
          utftext += String.fromCharCode(c);
          }
          else if((c > 127) && (c < 2048)) {
          utftext += String.fromCharCode((c >> 6) | 192);
          utftext += String.fromCharCode((c & 63) | 128);
          }
          else {
          utftext += String.fromCharCode((c >> 12) | 224);
          utftext += String.fromCharCode(((c >> 6) & 63) | 128);
          utftext += String.fromCharCode((c & 63) | 128);
          }

          }

          return utftext;
      },

      // private method for UTF-8 decoding
      _utf8_decode : function (utftext) {
          var string = "";
          var i = 0;
          var c = c1 = c2 = 0;

          while ( i < utftext.length ) {

          c = utftext.charCodeAt(i);

          if (c < 128) {
          string += String.fromCharCode(c);
          i++;
          }
          else if((c > 191) && (c < 224)) {
          c2 = utftext.charCodeAt(i+1);
          string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
          i += 2;
          }
          else {
          c2 = utftext.charCodeAt(i+1);
          c3 = utftext.charCodeAt(i+2);
          string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
          i += 3;
          }

          }

          return string;
      }
}

function pcAddLoadEvent(func){
      var onLoad = window.onload;
      if (typeof window.onload != 'function')
        window.onload = func;
      else
      {
        window.load = function(){
            if (onLoad) onLoad();
            func();
        }
      }
}
function CallPageCounter(counterUrl, id, url, title, host, publishDate){
      var pc = new Image();

      var da= new Date();
      //compose manually ISO date
      dy = da.getFullYear() // Get full year (as opposed to last two digits only)
      dm = da.getMonth() + 1 // Get month and correct it (getMonth() returns 0 to 11)
      dd = da.getDate() // Get date within month
      dh= da.getHours()  //Get hours
      dmi = da.getMinutes() //Get minutes
      dmm = da.getMilliseconds() //Get miliseconds
      ys = new String(dy) // Convert year, month and date to strings
      ms = new String(dm)
      ds = new String(dd)
      if ( ms.length == 1 ) ms = "0" + ms; // Add leading zeros to month,day,hour, minutes and milliseconds if required
      if ( ds.length == 1 ) ds = "0" + ds;
      if ( dh.length == 1 ) dh = "0" + dh;
      if ( dmi.length == 1 ) dmi = "0" + dmi;
      if ( dmm.length == 1 ) dmm = "0" + dmm;
      ys = ys + "-" + ms + "-" + ds + " " + dh + ":" + dmi + ":" + dmm ;
      var dateEncoded = Base64.encode(ys);
      var publishD=Base64.encode(publishDate);
      
      pc.src = counterUrl + '?hn='+host+'&pi=' +id + '&pt=' + publishD+ '&rt='+ dateEncoded + '&u='+url + '&t='+title;
      
}
/* End of page counter*/
      