
function makecall(thepersona){
	if (alreadymadecall) {
		alert ( "You have already pressed the 'Call Me' button, please wait ");
		return;
	}
	alreadymadecall = true;

	var thelocation = "agree_to_payment?persona=" + thepersona
	document.location = (thelocation);
}


if(! typeof getUrl == 'function'){
	function getUrl(url) {
		var xmlrpc_obj
		try {
			xmlrpc_obj = new XMLHttpRequest;
		} catch(e) {
			try {
				xmlrpc_obj = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					xmlrpc_obj = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					alert("Your web browser does not support this feature. Please upgrade your web browser.");
				}
			}
		}

		xmlrpc_obj.open("GET", url, false);
		xmlrpc_obj.send(null);
		if (xmlrpc_obj.status == 200)   {
			return xmlrpc_obj.responseText;
		} else {
			return false;
		}
	}
}


function brb() {
	var xmlrpc_obj
		try {
			xmlrpc_obj = new XMLHttpRequest;
		} catch(e) {
			try {
				xmlrpc_obj = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					xmlrpc_obj = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					alert("Your web browser does not support this feature. Please upgrade your web browser.");
				}
			}
		}

		xmlrpc_obj.open("GET", "/xmlrpc/xmlrpc_seller_pause?act=pause", false);
		xmlrpc_obj.send(null);
		if (xmlrpc_obj.status == 200)   {
         resp = xmlrpc_obj.responseText;

			if(resp.substring(0, 2) == "NO") {
				alert(resp.substring(2));
			} else {
	         document.getElementById('seller_imback').style.display='block';
				document.getElementById('seller_brb').style.display='none';
			}
		} else {
			return false;
		}
}

function imback() {
	var xmlrpc_obj
		try {
			xmlrpc_obj = new XMLHttpRequest;
		} catch(e) {
			try {
				xmlrpc_obj = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					xmlrpc_obj = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					alert("Your web browser does not support this feature. Please upgrade your web browser.");
				}
			}
		}

		xmlrpc_obj.open("GET", "/xmlrpc/xmlrpc_seller_pause?act=unpause", false);
		xmlrpc_obj.send(null);
		if (xmlrpc_obj.status == 200)   {
			document.getElementById('seller_brb').style.display='block';
			document.getElementById('seller_imback').style.display='none';
		} else {
			return false;
		}
}

function logout() {
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		if(confirm("You havent logged out. You will still receive calls unless you logout. Click 'Ok' to logout now.")) {
			window.open("/action/logout", "logout", "height=600,width=600");
		}
	}
}


/**************************************************
	POPUP CONTROL
**************************************************/
var my_width = 0, my_height = 0;

function client_height(){
	
	if (typeof(window.innerWidth) == "number"){
		my_height = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		my_height = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)){
		my_height = document.body.clientHeight;
	}
	
	return my_height;
}

function client_width(){
	
	if (typeof(window.innerWidth) == "number"){
		my_width = window.innerWidth;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		my_width = document.documentElement.clientWidth;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)){
		my_width = document.body.clientWidth;
	}
	
	return my_width;
}

function create_popup(popup){
	if (document.getElementById('popup_container') == null){
		launch_popup('popup_container', popup);
		hideflash();
	} else {
		
		document.getElementById("popup_container").style.display = "block";
		document.getElementById(popup).style.display = "block";
		hideflash();
	}
}

function popup_close(){
	document.getElementById("popup_container").style.display = "none";
	document.getElementById("popup_login_box").style.display = "none";
	
	showflash();
	
	return false;
}

function launch_popup(id, popup){
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute(id, id);
	newdiv.id = id;
	
	newdiv.style.width = client_width();
	newdiv.style.height = client_height();
	newdiv.style.height = document.body.scrollHeight + 20;

	newdiv.style.position = "absolute";
       
	newdiv.style.left = 0;
    newdiv.style.top = 0;

	newdiv.style.backgroundImage="url('/generic/css/fone-me.com/images/popup/black_50.png')"; 
	
	switch (popup){
		case "popup_login_box":
			var objHTML = '<div id="popup_login_box" style="margin-top: ' + (document.documentElement.scrollTop + 50) + 'px;">';
				objHTML += '<h1>Login</h1>';
				objHTML += '<form name="popup_login_box">';
				objHTML += '<div id="popup_login_box_error"></div>';
				objHTML += '<label>Username:</label>';
				objHTML += '<input name="username" id="username">';
				objHTML += '<label>Password:</label>';
				objHTML += '<input name="password" id="password" type="password">';
				objHTML += '<input type="submit" name="Submit" value="Send" class="button" onClick="return check_form(\'/api/acs_login?send=true\',\'popup_login_box\', 270);">';
				objHTML += '<input type="submit" name="Submit" value="Cancel" class="button" onClick="return popup_close();">';
				objHTML += '<a href="/action/signup_new">Create a new account - <span class="red">ITS FREE!</span></a>';
				objHTML += '</form>';
				objHTML += '</div>';
			break;
	}

	newdiv.innerHTML = objHTML;
   
	document.body.appendChild(newdiv);
}

function hideflash(){

	var flash = document.getElementsByTagName('object');
	//var flash = document.getElementsByTagName('embed');

	for (var i = 0; i < flash.length; i++){
		//flash[i].style.display = "none";
		flash[i].style.visibility = 'hidden';
	} 

}

function showflash(){

	var flash = document.getElementsByTagName('object');
	//var flash = document.getElementsByTagName('embed');

	for (var i = 0; i < flash.length; i++){
		//flash[i].style.display = "none";
		flash[i].style.visibility = 'visible';
	} 

}

var x;
var popup_login_box = new Array("username", "password");

function check_form(url, form_name, height){
	error_message = "";
	url_string = "";

	for (x in this[form_name]){
		if (document[form_name][x].value != ""){
			url_string += "&" + this[form_name][x] + "=" + document[form_name][x].value;
		} else {
			switch (this[form_name][x]){
				case "name":
					if (form_name == "right_callback"){
						error_message += "<p>Please enter your name</p>\n";
					} else {
						error_message += "<p>Sorry you need to enter your name</p>\n";
					}
					break;
				case "from":
					error_message += "<p>Sorry you need to enter your email address</p>\n";
					break;    
				case "username_login":
					error_message += "<p>Sorry you need to enter your Username</p>\n";
					break;
				case "password_login":
					error_message += "<p>Sorry you need to enter your Password</p>\n";
					break;    
				case "company":
					break;
				case "phone":
					if (form_name == "callback"){
						error_message += "<p>Sorry you need to enter your " + this[form_name][x] + " number</p>\n";
					} else if (form_name == "right_callback"){
						error_message += "<p>Enter your phone number</p>\n";
					}
					break;    
				default:
					error_message += "<p>Sorry you didn't enter your " + this[form_name][x] + "</p>\n";
				}
		}
	}

	if(error_message != ""){
		//alert(error_message);
		document.getElementById(form_name + "_error").style.display = "block";
		document.getElementById(form_name + "_error").innerHTML = error_message;
	} else {
		
		
		
		login_request(url, url_string, form_name, height);
		//alert(url + url_string, form_name, height);	
	}

	return false;
}

function login_request(url, url_string, div, height){
	
	var params = url_string;
		
	if (document.getElementById){
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}

	if (x){
		x.onreadystatechange = function() {
		if (x.readyState == 4 && x.status == 200) {
			//el = document.getElementById(div);
			//el.innerHTML = x.responseText;
			//if (x.responseText == 
			string = x.responseText;
			//alert(string);
			valid = string.slice(string.indexOf("&valid=") + 7,  string.indexOf("&valid=") + 8);
			if (valid.toString() == "1"){
				reload();
			} else {
				message = string.slice(string.indexOf("&message=") + 9, string.indexOf("&", string.indexOf("&message=") + 9));
				replace_string = "+";
				
				document.getElementById(div + "_error").style.display = "block";
				document.getElementById(div + "_error").innerHTML = message.replace(/replace_string/, " ");
				
			}
		}
    }
    x.open("POST", "http://www.fone-me.com" + url, true);
	
	x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	x.setRequestHeader("Content-length", params.length);
	x.setRequestHeader("Connection", "close");
	
    x.send(params);
	}
}

function reload(){
	window.location.href = window.location.href;
}

/**************************************************
	
**************************************************/


function start_voice_player(babenumber, anim){
	
	if(parseFloat(document.getElementById("voice_player").style.height.slice(0, document.getElementById("voice_player").style.height.indexOf("px"))) >= 60){
		clearInterval(animate_div_height_timer);
		document.getElementById("voice_player").style.display = "none";
		document.getElementById("voice_player").style.height = "0px";
		
	} else {
		
		/*if(navigator.appName == "Netscape"){
			var obj_html = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="450" height="44">';
				obj_html += '<param name="autoStart" value="true">';
				obj_html += '<embed src="http://www.fone-me.com/action/play_voice?babe=' + babenumber + '" width="450" height="44" autostart="true"></embed>';
				obj_html += '</object>';
		}*/
		
		if(FlashDetect.installed){
			var obj_html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="368" height="44">';
				obj_html += '<param name="movie" value="/action/audio/player.swf?autoStart=true&src=http://www.fone-me.com/action/play_voice?babe=' + babenumber + '">';
				obj_html += '<embed src="/action/audio/player.swf?autoStart=true&src=http://www.fone-me.com/action/play_voice?babe=' + babenumber + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="368" height="44"></embed>';
				obj_html += '</object>';
		} else if(!!(document.createElement('audio').canPlayType)){
			var obj_html = '<audio autoplay controls preload="auto" autobuffer>';
				obj_html += '<source src="http://www.fone-me.com/action/play_voice?babe=' + babenumber + '" type="audio/mp3" />';
				obj_html += 'Your browser does not support the audio element';
				obj_html += '</audio>';
		} else {
			var obj_html = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="368" height="44">';
				obj_html += '<param name="FileName" value="http://www.fone-me.com/action/play_voice?babe=' + babenumber + '" id=\'myParam\'>';
				obj_html += '<param name="autoStart" value="true">';
				obj_html += '<embed type="application/x-mplayer2" src="http://www.fone-me.com/action/play_voice?babe=' + babenumber + '" name="MediaPlayer" width="368" height="44"></embed>';
				obj_html += '</object>';
		}		
		
		document.getElementById("voice_player").innerHTML = obj_html;
		animate_div_height_timer = setInterval("animate_div_height('voice_player', 60)", 50);
		
	}
	
}

function SMSAlertsGetUrl(url){
	var xmlrpc_obj
	
	try {
		xmlrpc_obj = new XMLHttpRequest;
	} catch(e){
		try {
			xmlrpc_obj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
			xmlrpc_obj = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
				alert("Your web browser does not support this feature. Please upgrade your web browser.");
				}
			}
	}

	xmlrpc_obj.open("GET", url, false);
	xmlrpc_obj.send(null);
		
	if (xmlrpc_obj.status == 200){
		var responsimo = xmlrpc_obj.responseText;
		if (responsimo == 'LOGIN'){
			document.location.href = '/action/login_or_register'
			return '<div class="failure_notice">You must be logged in to set up notifications <a href="/action/login_or_register">click here</a> to continue.</div>';
		}
		return responsimo;
	} else {
		return false;
	}
}

function SMS_Subscribe_Clicked(babenumber){
	
	document.getElementById("sms_alerts_container").innerHTML = SMSAlertsGetUrl('/xmlrpc/xmlrpc_alertadd?show=yes&babenumber=' + babenumber);

	if(parseFloat(document.getElementById("sms_alerts_container").style.height) >= 220){
		clearInterval(animate_div_height_timer);
		document.getElementById("sms_alerts_container").style.display = "none";
		document.getElementById("sms_alerts_container").style.height = "0px";
		
	} else {
		
		
		if(typeof(window["sms_alerts_container_animate"]) == "undefined" || sms_alerts_container_animate != true){
			
			animate_div_height_timer = setInterval("animate_div_height('sms_alerts_container', 220)", 50);
			
		} else {
			clearInterval(animate_div_height_timer);
			sms_alerts_container_animate = false;
			document.getElementById("sms_alerts_container").style.display = "none";
			document.getElementById("sms_alerts_container").style.height = "0px";
		}

		
	}
	
}

function animate_div_height(div, aim){
	
	this [div + "_animate"] = true;
	document.getElementById(div).style.display = "block";
	
	if(document.getElementById(div).style.height == ""){
		document.getElementById(div).style.height = "20px";
	}
	
	document.getElementById(div).style.height = parseFloat(document.getElementById(div).style.height) + 20 + "px";
	
	if(parseFloat(document.getElementById(div).style.height) >= aim){
		clearInterval(animate_div_height_timer);
		scroll_body_calculate(div);
		this [div + "_animate"] = false;
	}
}

function scroll_body_calculate(div){
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0){

		if (window.pageYOffset){
			ScrollTop = window.pageYOffset;
		} else {
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	
	var browserName=navigator.appName; 

	if (browserName=="Microsoft Internet Explorer"){
		offset = 100;
	} else {
		offset = -300;
	}
	
	end_position = ((Math.round(document.getElementById(div).offsetTop / 100) * 100) + offset) - ScrollTop;
	
	if((end_position - ScrollTop) > 100){
		animation_timer = setInterval("scroll_body(" + end_position + ")", 10);
	}
	
}

var scroll = 0;

function scroll_body(end_position){
	
	scroll = scroll + 20;
	
	if(scroll < end_position){
		window.scrollBy(0, 20);
	} else {
		scroll = 0;
		clearInterval(animation_timer);
	}
	
}

//http://www.featureblend.com/license.txt
// flash detect
var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";
