// JavaScript Document
var spu_timeout;
var spu_still_loading=true;

page_url=location.href;
if (page_url.indexOf("?")!=-1){
	var arr = window.location.href.split('?');
	page_url=arr[0];	
}
if (page_url.indexOf("#")!=-1){
	var arr = window.location.href.split('#');
	page_url=arr[0];	
}


var spu_prescriptload = window.onload;
window.onload = function() {
	if (typeof (spu_prescriptload) == 'function') {
		spu_prescriptload();
	}
	write_spu_div();
};


function write_spu_div(){
	document.body.innerHTML+="<div id='clicktosharediv' style='width:298px;z-index:101; position:absolute; left:0px; top:0px; display:none;height:236px; font-weight:bold; color:#4b4b4b'><iframe id='spuiframe' style='width:1px; height:1px; display:none'></iframe><iframe id='spuiframe3' style='width:1px; height:1px; display:none'></iframe><iframe id='spuiframe2' style='width:1px; height:1px; display:none'></iframe><div id='spuimage' style='position:absolute'></div><div id='spu_main_contents'><div style='position:absolute;width:298px;'><p style='margin-left:16px; line-height:12px; margin-bottom:6px;  margin-top:17px; color:#222222; font-family:Arial; font-size:12px; font-weight:bold'>Share This Video</p><div style='overflow:hidden; background-color:#AAAAAA; height:1px; width:280px; margin-left:9px; margin-top:0px; margin-bottom:10px'></div><div id='sendpanel'><div style='position:relative; width:260px; margin-left:19px; margin-bottom:0px'><form action='javascript:void(0);' id='meform' style='margin:0px' name='meform' method='post' onSubmit='sendform()'>To:<div style='position:relative;height: 20px;'><input style='font-family:Arial; font-size:12px;width:257px; position:absolute; height:15px;left:0px; top:0px; border-width:1px; border-color:#AAAAAA; border-style:solid' type='text' id='to' value='' name='to'></div>From: <div style='position:relative;height: 20px;'><input style='font-family:Arial; font-size:12px;width:257px; position:absolute; height:15px;left:0px; top:0px; border-width:1px; border-color:#AAAAAA; border-style:solid' type='text' id='from' onFocus='javascript:checkReceipt()' value='' name='from'> </div><input type='radio' checked='checked' onClick='javascript:carrierToggle()' name='sendtype' value='email'>Send via e-mail<input onClick='javascript:carrierToggle()' type='radio' name='sendtype' value='phone'>Smartphone<select name='carrier' id='carrier' style='display:none; font-family:Arial; font-size:12px;width:257px;  border-width:1px; border-color:#AAAAAA; border-style:solid'><option selected value='carrier'>Carrier...</option><option value='att'>ATT (Cingular)</option><option value='tmobile'>T-Mobile</option><option value='sprint'>Sprint</option><option value='verizon'>Verizon</option></select><div style='float:left; margin-right:7px'><input name='netrec' type='checkbox' id='netrec' value='1' style='margin-left:0px; margin-top:3px;'> Request NetReceipt&#8482; </div><div style='float:left'><input name='cc_biz' title='Send a copy to site owner' type='checkbox' id='cc_biz' value='1' checked='checked' style='margin-left:0px; margin-top:3px;'> CC: "+cc_name+"</div><div style='clear:both'></div><div style='height:10px'></div><input type='hidden' id='addt_qstring' name='addt_qstring' value=''/><input type='hidden' id='enctcid' name='enctcid' value='"+encoded_tid+"'/><input type='hidden' id='encpid' name='encpid' value='"+encoded_pid+"'/><input type='hidden' id='typeofplayer' name='typeofplayer' value=''/><input type='hidden' id='mid_to_play' name='mid_to_play' value=''/><input type='hidden' name='page_url' value='"+page_url+"'/><input type='hidden' name='ccemail' value='"+cc_email+"'> <input type='hidden' name='sponid' value='"+spon_id+"'><input type='hidden' name='ccbus' value='"+cc_bus+"'></form></div><div onclick='javascript:spu_call_now()' style='cursor:pointer; width:110px; height:32px; position:relative; margin:0px auto 0px auto' ><div id='spubutton' style='position:absolute; left:0px; top:0px'></div><div  style=' position:absolute; width:110px; text-align:center; top:9px; left:0px; font-size:12px; font-weight:bold; font-family:Arial; color:#2c7afa'><span style='font-size:12px; font-weight:bold; font-family:Arial; color:#2c7afa; text-decoration:none'>Send Now</span></div></div></div><div id='sentpanel' style='margin-top:80px; font-size:13px; display:none; text-align:center'>Sent</div></div></div><div id='spu_calling_div' style='display:none; position:absolute; width:248px;left:25px;top:80px; text-align:center;line-height:12px; color:#222222; font-family:Arial; font-size:12px; font-weight:bold'>Now Sending<br/><br/><span style='font-size:11px'>Thank you for your message. If you've requested a response, we'll get back to you as soon as possible.</span></div><a href='javascript:spu_close()'><img style='position:absolute; left:260px; border-width:0px; top:10px' src='http://www.elocallink.tv/sandbox2/modules/click_to_text/ctt_close.jpg'/></a></div>"
	writeImageToDiv("http://www.elocallink.tv/sandbox2/modules/click_to_text/cttbackground.png", 298, 236, 0, 0, "spuimage", "");
	writeImageToDiv("http://www.elocallink.tv/sandbox2/modules/click_to_text/cttbutton.png", 110, 32, 0, 0, "spubutton", "");

	spu_still_loading=false;
}

function checkReceipt(){
		document.forms["meform"].netrec.checked=true;
	}

function carrierToggle(){
	
		if(document.forms["meform"].sendtype[0].checked==true){
			document.getElementById("carrier").style.display="none";
		}
		else document.getElementById("carrier").style.display="block";
	}

function spu_call_now(){
	
	var emailRE = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var tomail=document.forms["meform"].to.value;
	var frommail=document.forms["meform"].from.value;
	
	if(!tomail.match(emailRE)){
		alert("Please enter e-mail address in the 'To' field in the format recipient@domain.com");
	}
	else
	{
		
		document.getElementById('spuiframe').src="http://www.smartsite.tv/scripts/share_video_with_mid.php?"+Form.serialize(document.meform);
		document.getElementById('spuiframe2').src="http://www.smartsite.tv/tracking/universal_tracking.php?insert_type=sharewebvideo&pid="+encoded_pid+"&from_email="+document.forms["meform"].from.value+"&to_email="+document.forms["meform"].to.value+"&etx="+lastVideoTitlePlayedEncoded+"&cc="+document.forms["meform"].cc_biz.checked;
		
		document.getElementById("sentpanel").style.display="block";
		document.getElementById("sendpanel").style.display="none";
		setTimeout(spu_close, 2000);
	}
}

function click_to_share(num){
	if(spu_still_loading==true) return;
	spu_close();
	
	spu_screenWidth=document.documentElement.clientWidth;
	
	spu_offsetX=20;
	if(tempX+spu_offsetX+300>spu_screenWidth){
			spu_offsetX=-280;
	}
	
	document.getElementById("clicktosharediv").style.left=(tempX+spu_offsetX)+'px';
	document.getElementById("clicktosharediv").style.top=(tempY+20)+'px';
	document.getElementById("clicktosharediv").style.display="block";
	document.getElementById("sentpanel").style.display="none";
	document.getElementById("sendpanel").style.display="block";
	
}

function click_to_share_with_offsets(xoff, yoff){
	if(spu_still_loading==true) return;
	spu_close();
	
	spu_screenWidth=document.documentElement.clientWidth;
	
	document.getElementById("clicktosharediv").style.left=(tempX+xoff)+'px';
	document.getElementById("clicktosharediv").style.top=(tempY+yoff)+'px';
	document.getElementById("clicktosharediv").style.display="block";
	
}

function spu_close(){
	document.getElementById("sentpanel").style.display="none";
	document.getElementById("sendpanel").style.display="block";
	clearTimeout(spu_timeout);
	document.getElementById("clicktosharediv").style.display="none";
	document.getElementById("spu_main_contents").style.display="block";	
    document.getElementById("spu_calling_div").style.display="none";	
}