// JavaScript Document
//Global Variablesc
var intPwdLength = 6;
var arrCustomErrors = new Array();
arrCustomErrors["da"] = new Array();
arrCustomErrors["da"]["nick"] = "Nick";
arrCustomErrors["da"]["name"] = "Name";
arrCustomErrors["da"]["email"] = "Email";
arrCustomErrors["da"]["height"] = "Height";
arrCustomErrors["da"]["weight"] = "Weight";
arrCustomErrors["da"]["sexual"] = "Sexual Preferences";
arrCustomErrors["da"]["zipcode"] = "Zipcode";
arrCustomErrors["da"]["password"] = "Password";
arrCustomErrors["da"]["password2"] = "Password Confirmation";
arrCustomErrors["da"]["pwdlength"] = "must have at least "+ intPwdLength +"characters";
arrCustomErrors["da"]["empty"] = "is a required field";
arrCustomErrors["da"]["notvalid"] = "is not valid";
arrCustomErrors["da"]["title"] = "Story Title";
arrCustomErrors["da"]["content"] = "Story Text";
arrCustomErrors["da"]["gbcontent"] = "Guest Book Entrie";
arrCustomErrors["da"]["folder_name"] = "Folder Name";

var arrCustomMessages = new Array();
arrCustomMessages["da"] = new Array();
arrCustomMessages["da"]["delete_profile"] = "Are you sure you would like to delete your profile?";
arrCustomMessages["da"]["delete_folder"] = "Are you sure you would like to delete this folder?";
arrCustomMessages["da"]["delete_media"] = "Are you sure you would like to delete this media file?";
//Macromedia Functions
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

// Custom Functions
function trim(str) {
  str = str.replace (/\s/g, "");
  return str; 
}

function entsub(event,ourform) {
	if (event && event.which == 13)
		ourform.submit();
	else
		return true;
}
function resetForm() {
    objForm = document.forms[0];
	for (var i=0; i<objForm.elements.length; i++){
		var e = objForm.elements[i];
		if ((e.type == 'textarea') || (e.type == 'text')){
  		  e.value = "";
		}
	}
}

function valLogOn(objForm, strLang){
	
  if (trim(objForm.txtUser.value) == ""){
    alert (arrCustomErrors[strLang]["nick"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtUser.value = "";	
	objForm.txtUser.focus();
	return false;
  }		
	
  if (trim(objForm.txtPassword.value) == ""){
    alert (arrCustomErrors[strLang]["password"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtPassword.value = "";	
	objForm.txtPassword.focus();
	return false;
  }		  
}

function valAddGuestBook(objForm, strLang){
  if (trim(objForm.txtComment.value) == ""){
    alert (arrCustomErrors[strLang]["gbcontent"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtComment.value = "";	
	objForm.txtComment.focus();
	return false;
  }	
  
}

function valStory(objForm, strLang){

  if (trim(objForm.txtTitle.value) == ""){
    alert (arrCustomErrors[strLang]["title"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtTitle.value = "";	
	objForm.txtTitle.focus();
	return false;
  }	
  if (trim(objForm.txtContent.value) == ""){
    alert (arrCustomErrors[strLang]["content"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtContent.value = "";	
	objForm.txtContent.focus();
	return false;
  }	  
}

function valUserForm(objForm, strLang){
  if (trim(objForm.txtNick.value) == ""){
    alert (arrCustomErrors[strLang]["nick"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtNick.value = "";	
	objForm.txtNick.focus();
	return false;
  }	
  if (trim(objForm.txtName.value) == ""){
    alert (arrCustomErrors[strLang]["name"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtName.value = "";	
	objForm.txtName.focus();
	return false;
  }

  if (trim(objForm.txtPassword.value) == ""){
    alert (arrCustomErrors[strLang]["password"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtPassword.value = "";	
	objForm.txtPassword.focus();
	return false;
  }

/*  if (trim(objForm.txtPassword.value.length) < parseInt(intPwdLength)){
    alert (arrCustomErrors[strLang]["password"] + " " + arrCustomErrors[strLang]["pwdlength"]);
	objForm.txtPassword.value = "";	
	objForm.txtPassword.focus();
	return false;
  }  */
  if (trim(objForm.txtPassword.value) != trim(objForm.txtPassword2.value)){
    alert (arrCustomErrors[strLang]["password2"] + " " + arrCustomErrors[strLang]["notvalid"]);
	objForm.txtPassword2.value = "";	
	objForm.txtPassword2.focus();
	return false;
  }  
  if (trim(objForm.txtZipcode.value) == ""){
    alert (arrCustomErrors[strLang]["zipcode"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtZipcode.value = "";	
	objForm.txtZipcode.focus();
	return false;
  }  
  if (trim(objForm.txtEmail.value) == ""){
    alert (arrCustomErrors[strLang]["email"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtEmail.value = "";	
	objForm.txtEmail.focus();
	return false;
  }
  var val = trim(objForm.txtEmail.value);
  var p= val.indexOf('@');
  if (p<1 || p==(val.length-1)) {
	 alert(objForm.txtEmail.value + " " + arrCustomErrors[strLang]["notvalid"]);
	 objForm.txtEmail.select();
	 return false;
  }	
  if (trim(objForm.txtHeight.value) == ""){
    alert (arrCustomErrors[strLang]["height"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtHeight.value = "";	
	objForm.txtHeight.focus();
	return false;
  }  
  if (trim(objForm.txtWeight.value) == ""){
    alert (arrCustomErrors[strLang]["weight"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtWeight.value = "";	
	objForm.txtWeight.focus();
	return false;
  }  
  var cnt = 0;
  var i = 0;  
  for (i=0; i<objForm.rbSexualprefs.length; i++) {
    if (objForm.rbSexualprefs[i].checked) {
	   cnt++;
    }
  }
  if (cnt==0) {
    alert (arrCustomErrors[strLang]["sexual"] + " " + arrCustomErrors[strLang]["empty"]);
	return false;
  }   
  return true;
}

function setMailFocus(strMailType){
  switch (strMailType){
   case "REPLY": document.frmMail.txtText.focus();
                 break;
   case "WRITE": document.frmMail.txtTo.focus();
                 break; 
  }

}

function valDeleteProfile(strLang){
	var agree=confirm(arrCustomMessages[strLang]["delete_profile"]);
	if (agree){
		document.frmDeleteProfile.submit();
	} 
	
}

function valDeleteFolder(strLang){
	var agree=confirm(arrCustomMessages[strLang]["delete_folder"]);
	if (agree){
		//return true;
		document.frmFolder.submit()
	}
	
}

function valDeleteMedia(strLang){
	//alert("here");
	var agree=confirm(arrCustomMessages[strLang]["delete_media"]);
	if (agree){
		document.frmDeleteMediaContent.submit()
	} 
	
}


function valNewFolderForm(objForm, strLang){
  if (trim(objForm.txtFolderName.value) == ""){
    alert (arrCustomErrors[strLang]["folder_name"] + " " + arrCustomErrors[strLang]["empty"]);
	objForm.txtFolderName.value = "";	
	objForm.txtFolderName.focus();
	return false;
  }	
}


function popupLogin(username, password, lang) { // check to make sure a valid username has been entered

	// the size of the popup window
	var width = 700;
	var height = 525;

	// the x,y position of the popup window
	// NOTE: this formula will auto-center the popup on the screen
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;

	var url = 'chat/flashchat.php?username=' + username + '&password=' + password + '&lang=' + lang;
	var options = 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + '';

	// open the chat window as a popup, instead of embedded in webpage
	window.open( url, 'chat', options );
}

function reportUser(qsuser) { // check to make sure a valid username has been entered

	// the size of the popup window
	var width = 420;
	var height = 280;

	// the x,y position of the popup window
	// NOTE: this formula will auto-center the popup on the screen
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;

	var url = 'php/report_user.php?qsUser='+qsuser;
	var options = 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + '';

	// open the chat window as a popup, instead of embedded in webpage
	window.open( url, 'report', options );
}

function sendToFriend(qsuser) { // check to make sure a valid username has been entered

	// the size of the popup window
	var width = 420;
	var height = 359;

	// the x,y position of the popup window
	// NOTE: this formula will auto-center the popup on the screen
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;

	var url = 'php/sendtofriend.php?qsUser='+qsuser;
	var options = 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + '';

	// open the chat window as a popup, instead of embedded in webpage
	window.open( url, 'sendtofriend', options );
}

function player(clipid) { // check to make sure a valid username has been entered

	// the size of the popup window
	var width = 400;
	var height = 300;

	// the x,y position of the popup window
	// NOTE: this formula will auto-center the popup on the screen
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;

	var url = 'php/player.php?clip='+clipid;
	var options = 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + '';

	// open the chat window as a popup, instead of embedded in webpage
	window.open( url, 'sendtofriend', options );
}
function webcamchat(userid) { // check to make sure a valid username has been entered

	// the size of the popup window
	var width = 610;
	var height = 660;

	// the x,y position of the popup window
	// NOTE: this formula will auto-center the popup on the screen
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;

	var url = 'php/start_webcamchat.php?user='+userid;
	var options = 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + '';

	// open the chat window as a popup, instead of embedded in webpage
	window.open( url, 'webcamchat', options );
}

adTime=120;  // seconds ad reminder is shown
chanceAd=1; // ad will be shown 1 in X times (put 1 for everytime)

var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"
adCount=0;

function initAd(){
	if(!ns && !ie && !w3) return;
	if(ie)		adDiv=eval('document.all.sponsorAdDiv.style');
	else if(ns)	adDiv=eval('document.layers["sponsorAdDiv"]');
	else if(w3)	adDiv=eval('document.getElementById("sponsorAdDiv").style');
	randAd=Math.ceil(Math.random()*chanceAd);
        if (ie||w3)
        adDiv.visibility="visible";
        else
        adDiv.visibility ="show";
	if(randAd==1) showAd();
}
function showAd(){
if(adCount<adTime*10){adCount+=1;
	if (ie){documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
	documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;}	
	else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
	documentHeight=window.innerHeight/2+window.pageYOffset-20;} 
	else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
	documentHeight=self.innerHeight/2+window.pageYOffset-20;} 
	adDiv.left=documentWidth-200+calunit;adDiv.top =documentHeight-200+calunit;
	setTimeout("showAd()",100);}else closeAd();
}
function closeAd(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}



///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert("Du kan ikke klikke her");
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert('Du kan ikke klikke her');return false")


