document.onmousemove = mouseMove;

var mouseObject = null;
var serverRoot = "http://" + window.location.hostname + "/";
var timestampObject = new Date();
var uploadField;
var ie = false;
var currentImage = "";

function sendEmailLink()
{
	
	var senderEmail = document.getElementById("emailLinkSEmail");
	var friendName = document.getElementById("emailLinkFName");
	var friendEmail = document.getElementById("emailLinkEmail");
	
	var sEmail = encode64(senderEmail.value);
	
	var fName = encode64(friendName.value);
	var fEmail = encode64(friendEmail.value);
	
	var key = trim(sendAjaxGetResponse("POST", "index.php?page=func&&func=ajaxMD5&&data="+ fName + fEmail + sEmail));
	var xmlData = sendAjax("POST", "index.php?page=func&&func=ajaxSendLink&&senderEmail="+sEmail+"&&friendName="+fName+"&&friendEmail="+fEmail+"&key="+ key);
	
	
	senderEmail.value = "";
	friendName.value = "";
	friendEmail.value = "";
	
	closeEmailLink();


}
function displayEmailLink(product)
{
	var emailDiv = document.getElementById("emailLinkDiv");
	emailDiv.style.top = parseInt(document.documentElement.scrollTop + 250) + 1 + "px";
	emailDiv.style.display = "";		
}
function closeEmailLink()
{
	
	var senderEmail = document.getElementById("emailLinkSEmail").value = "";
	var friendName = document.getElementById("emailLinkFName").value = "";
	var friendEmail = document.getElementById("emailLinkEmail").value = "";
	
	var emailDiv = document.getElementById("emailLinkDiv").style.display = "none";
	
}
function bookmarkLink() {

 title = "AdvancedEscort.com"; 
  url = "http://www.advancedescort.com";
  	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }

function closeImage()
{
		var overLay = document.getElementById("modelImageOverlay");
		var imageDiv = document.getElementById("modelImageDiv");
		
		if(overLay && imageDiv)
		{
			clearInnerHTML(overLay);
			clearInnerHTML(imageDiv);
			
			document.body.removeChild(overLay);
			document.body.removeChild(imageDiv);
		
		}
}
function viewImage(image,id)
{
		var nImage = document.getElementById(id);
		if(!empty(currentImage))
		{
			var cImage = document.getElementById(currentImage);
			
			
			if(currentImage && nImage)
			{
				
				cImage.className = "albumImage";
				nImage.className = "selectedImage";
				
				currentImage = id;
			}
		
		}
		else
		{
			nImage.className = "selectedImage";
			currentImage = id;
		}
		var imageDiv = document.getElementById("imageDiv")
		clearInnerHTML(imageDiv);
		var img = document.createElement("img");
		img.src = image;
		img.align = "center";
		imageDiv.appendChild(img);
		
	}
function formatField(field,formatting,additionalValue,callBack)
{
	
	var fieldObj = document.getElementById(field);
	if(fieldObj)
	{
		switch(formatting)
		{
			case 0: if(fieldObj.style.fontWeight == "bold") fieldObj.style.fontWeight = ""; else fieldObj.style.fontWeight = "bold";
				break;
			case 1: if(fieldObj.style.fontStyle == "italic") fieldObj.style.fontStyle = ""; else fieldObj.style.fontStyle = "italic";
				break;
			case 2: fieldObj.style.textDecoration = additionalValue;
				break;
			case 3: fieldObj.style.color = additionalValue;
				break;
		}
	
		if(callBack){eval(callBack);}
	}
	fieldObj = null;
	

}

function locationRedirect(url){setTimeout(function(){window.location = url;},0);}

function toggleFieldsWithCheckBox(checkBox,fieldArray,direction)
{
	if(direction != false && empty(direction)){direction = true;}
	for(var x=0;x<fieldArray.length;x++)	
	{
		var element = document.getElementById(fieldArray[x]);
		
		if(checkBox.checked)
		{
			
			if(direction){element.disabled = true;}
			else{element.disabled = false;}
		}
		else
		{
			if(direction){element.disabled = false;}
			else{element.disabled = true;}
		}
		
		element = null;
	}

}

function checkboxBoolValue(checkbox)
{
	if(checkbox.checked){return true;}
	else{return false;}

}

function showHideElement(obj)
{
	var element  = document.getElementById(obj);
	if(element.style.display == ""){element.style.display = "none";}
	else{element.style.display = "";}
	element = null;
}

function showHideField(obj,changeField)
{
	var element  = document.getElementById(obj);
	var changeField = document.getElementById(changeField);
	
	if(changeField){clearInnerHTML(changeField);}
	
	if(element.style.display == "")
	{
		element.style.display = "none";
		if(changeField){changeField.appendChild(document.createTextNode("+"));}
		
	}
	else
	{
		element.style.display = "";
		if(changeField){changeField.appendChild(document.createTextNode("-"));}
	}
	element = null;
}

function uploadFile(fileFolder,fileUpload,waitingElement,generateFolder,encodeFilename,callBackFunction,returnData,generateDataFile,fileName)
{
	
	var timestamp = timestampObject.getTime();
	var uploadWindow = window.open('','uploadWindow'+timestamp,'height=100,width=100');
	
	if(uploadWindow && !uploadWindow.closed)
	{
		var oldFileUpload = document.getElementById(fileUpload);
		var windowDocument = uploadWindow.document;
		var submitForm = uploadWindow.document.createElement("Form");
		
		windowDocument.body.appendChild(submitForm);
		
		if(submitForm)
		{
			if(!empty(callBackFunction)){callBackFunction = "&&callback=" + callBackFunction;}
			else{callBackFunction = "";}
			
			if(generateFolder==true){generateFolder = "&&generateFolder=1";}
			else{generateFolder = "";}
			
			if(encodeFilename==true){encodeFilename = "&&encodeFilename=1";}
			else{encodeFilename = "";}
			
			if(returnData==true){encodeFilename = "&&returnData=1";}
			else{returnData = "";}
			
			if(generateDataFile==true){generateDataFile = "&&generateDataFile=1";}
			else{generateDataFile = "";}
			
			if(!empty(fileName)){fileName = "&&filename="+fileName;}
			else{fileName = "";}
			
			submitForm.action = serverRoot + "upload.php?uploadFile=1&&folder="+ fileFolder + callBackFunction + generateFolder + encodeFilename + returnData + generateDataFile + fileName;
			submitForm.encoding = "multipart/form-data";
			submitForm.method = "POST";
			submitForm.target = "uploadWindow"+timestamp;
			
			var newFileUpload = oldFileUpload.cloneNode(true);
			newFileUpload.name = "uploadFile" + timestamp;
			submitForm.appendChild(newFileUpload);
			if(!empty(waitingElement))
			{
				waitingElement = document.getElementById(waitingElement);
				if(waitingElement){waitingElement.innerHTML = "Uploading file<img src=\"skins/default/images/ajax-loader.gif\" style=\"vertical-align: middle;\">";}
			}
			
			submitForm.submit();
			
			newFileUpload = null;
			
			
		}
		else{alert("Could not find upload form");}
		
		oldFileUpload = null;
		windowDocument = null;
		submitForm = null;
	}
	else{alert("Please disable popup blockers to upload");}
	
	timestamp = null;
	uploadWindow = null;
	waitingElement = null;
	
	
}

function uploadFailed()
{
	
}

function mouseMove(e)
{
	mouseObject = e;

}


function getTopPos(inputObj)
	{
	
		var returnValue = inputObj.offsetTop;
		while((inputObj = inputObj.offsetParent) != null){
			returnValue += inputObj.offsetTop;
		}
		return returnValue;
	}
function setMoveableObject(obj)
{
	WindowDrag.init(obj);
	return false;

}

function ObjectPosition(obj) {
    var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
      return [curleft,curtop];
      curleft = null;
      curtop = null;
}

var WindowDrag = 
	{
		windowObj : null,
		
		init : function(obj,minX,minY,maxX,maxY)
		{
			
			obj = document.getElementById(obj);
			
			obj.minX = empty(minX) ? minX : null;
			obj.maxX = empty(maxX) ? maxX : null;
			obj.minY = empty(minY) ? minY : null;
			obj.maxY = empty(maxY) ? maxY : null;
			
			obj.onMoveEnd = new Function();
			obj.onMove = new Function();
			obj.style.position = "absolute";
			
			
			//console.debug("%s",obj.style.left);
			obj.style.left = obj.offsetLeft + "px";
			obj.style.top = obj.offsetTop + "px";
			
			var objOffset = ObjectPosition(obj);
			obj.parentOffsetLeft = objOffset[0];// - obj.offsetWidth;
			obj.parentOffsetTop = objOffset[1];// - obj.offsetHeight;
			
			document.onmousemove = WindowDrag.windowMove;	
			document.onmouseup = WindowDrag.end;
			windowObj = obj;
			
			document.body.style.cursor = "move";
			return false;
		
		},
		
		windowMove : function(e)
		{
			
			windowObj.style.top = ((e.clientY - windowObj.parentOffsetTop)) + "px";
			windowObj.style.left = (e.clientX - windowObj.parentOffsetLeft) + "px";
			windowObj.onMove(windowObj.style.top,windowObj.style.left);
			return false;
		},
		
		
		end : function()
		{
		
			document.onmousemove = null;
			document.onmouseup = null;
			document.body.style.cursor = "default";
			return false;
			
		}
		
		
		
		
	
	
	}
	
function strtolower( str ) {return (str+'').toLowerCase();}
function empty( mixed_var ) {
    var key;
    
    if (mixed_var === "" || mixed_var === null || mixed_var === false || mixed_var === undefined){key = null; return true;}
 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var){key = null; return false;}
        key = null; return true;
    }
    key = null;
    return false;
}
function clearInnerHTML(obj){while(obj.firstChild) obj.removeChild(obj.firstChild);}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
	 
	f = null;
	ra = null;	 
    return sa ? s : s[0];
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) 
  {
	var match = regex.exec(clearString.substr(x));
	if (match != null && match.length > 1 && match[1] != '') 
    	{
		output += match[1];
    		x += match[1].length;
    	} 
	else 
	{
      		if (clearString[x] == ' '){output += '+';}
      		else 
      		{
        		var charCode = clearString.charCodeAt(x);
        		var hexVal = charCode.toString(16);
        		output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
        		
        		charCode = null;
        		hexVal = null;
      		}
      		x++;
    	}
  }
  
  x = null;
  regex = null;
  
  return output;
}

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}


function trim(stringValue){return stringValue.replace(/(^\s*|\s*$)/, "");}
	
 var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";

function encode64(input) 
{
      var output = "";

	if(!empty(input))
	{
		input = escape(input);
	
		var chr1, chr2, chr3 = "";
		var enc1, enc2, enc3, enc4 = "";
		var i = 0;
		
		do {
			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 +
			keyStr.charAt(enc1) +
			keyStr.charAt(enc2) +
			keyStr.charAt(enc3) +
			keyStr.charAt(enc4);
			chr1 = chr2 = chr3 = "";
			enc1 = enc2 = enc3 = enc4 = "";
		} while (i < input.length);
		
		chr1 = null;
		chr2 = null;
		chr3 = null;
		enc1 = null;
		enc2 = null;
		enc3 = null;
		enc4 = null;
		i = null;
	}
	
	return output;
}
  
function decode64(input) 
{
	var output = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;
	
	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	var base64test = /[^A-Za-z0-9\+\/\=]/g;
	if (base64test.exec(input)) 
	{
		alert("There were invalid base64 characters in the input text.\n" +
		"Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
		"Expect errors in decoding.");
	}
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	
	do {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = 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);
		}
	
		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";
	
	} while (i < input.length);
	
	chr1 = null;
	chr2 = null;
	chr3 = null;
	enc1 = null;
	enc2 = null;
	enc3 = null;
	enc4 = null;
	i = null;
	
	return unescape(output);
}
   
   
   
