
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){
	
	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 {
		
		var obj_html = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="450" height="44">';
			obj_html += '<param name="FileName" value="/action/play_voice?babe=' + babenumber + '" id=\'myParam\'  standby=\'loading\'>';
			obj_html += '<param name="autoStart" value="false">';
			obj_html += '<param name="Showcontrols" value="True">';
			obj_html += '<param name="volume" value="-300">';
			obj_html += '<embed type="application/x-mplayer2" src="/action/play_voice?babe=' + babenumber + '" name="MediaPlayer" width="450" height="44" volume="-300"></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);
	}
	
}
