//<script language="JScript">

var objHttp = null;

//document.oncontextmenu = function()
//{
//	return (window.event.srcElement && window.event.srcElement.tagName=='INPUT');
//}

function openGlossary()
{
  var sFeatures = "resizable:1;dialogWidth:500px;dialogHeight:" + 
                  (3*screen.availHeight/4) + "px;dialogLeft:" + 
                  (screen.availWidth - 510) + 
                  "px;dialogTop:30px;help:0;edge:sunken;center:0;status:0";
                  
  window.showModalDialog("glossary.asp", null, sFeatures);
  window.event.cancelBubble = true;
  window.event.returnValue = false;
  return false;	
}

function securityError()
{
	window.navigate("/web/config/configure.asp?error=true");
}

function openFlash(sURL)
{
  var sFeatures = "resizable:1;dialogWidth:1299px;dialogHeight:1050px;dialogLeft:0px;dialogTop:0px;help:0;center:1;status:0";
  window.showModalDialog("/web/includes/runflash.asp", sURL, sFeatures);
  window.event.cancelBubble = true;
  window.event.returnValue = false;
  return false;	
}

function openImage(sURL)
{
  //winodw.open(sURL,"Screenshot","fullscreen:1,location:0,menubar:0,toolbar:0");
  var sFeatures = "resizable:1;dialogWidth:1300px;dialogHeight:1070px;help:0;center:1;status:0";
  window.showModalDialog(sURL, null, sFeatures);
  window.event.cancelBubble = true;
  window.event.returnValue = false;
  return false;	
}

function parseMoney(v)
{
	return parseFloat(v);
}

function sbmtRegistrationForm()
{
	try
	{
		if(form1.UserName.value) 
			return true;
	}
	catch(_e){}   

	try
	{		
		if(!form1.EmailAddress.value ||
		   !form1.Password.value ||
		   !form1.FirstName.value ||
		   !form1.LastName.value ||
		   !form1.StreetAddress.value ||
		   !form1.ZIP.value ||
		   !form1.CHECK_AGE.checked ||
		   !form1.CHECK_POLICIES.checked ||
		   !form1.CHECK_TERMS_AND_CONDITIONS.checked || 
		   form1.EmailAddress.value!=form1.confirm_emailaddress.value ||
		   form1.Password.value!=form1.confirm_password.value) throw new Error(1000, "missing fields");
		 
		if(!form1.Alias.value)
			form1.Alias.value = form1.FirstName.value + "." + form1.LastName.value;
			  
		var title = form1.Title.options[form1.Title.selectedIndex].innerText;
		 
		if(!title) title = "Mr.";
		form1.RealName.value = title + " " + form1.FirstName.value + " " + form1.LastName.value;
		form1.UserName.value = form1.EmailAddress.value;
	}
	catch(e)
	{
		alert("You need to enter valid values for all the fields with the asterisc\nand confirm that you have read all the required agreements.");
		window.event.returnValue = false;
	}
}

function getLoadingImage()
{
	try
	{
		if(window['form1'] && form1.imgLoading)
			return form1.imgLoading;
		else if(window['imgLoading'])
			return imgLoading;
		else
			return null;
	}
	catch(e)
	{
		return null;
	}
}

function showLoadingImage()
{
	var img = getLoadingImage();
	if(img!=null)
	{		
		img.loop = 0;
		img.style.visibility = 'visible';
	}
}

function hideLoadingImage()
{
	var img = getLoadingImage();
	if(img!=null)
	{		
		img.style.visibility = 'hidden';
		img.loop = 0;
	}
}

function XMLHttpPost(sURL, sFormData, callBack, bXmlResponse)
{
    var result = null;
    try
    {
		if(callBack!=null)
			showLoadingImage();
		
		try { objHttp = new ActiveXObject("MSXML2.XMLHTTP"); } catch(_E) {objHttp = null;}
		if(objHttp==null) try { objHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(_E) {objHttp = null;}
		if(objHttp != null)
		{
			if(callBack!=null)
			{
				__handleXmlHttpCallback.__callBack = callBack;
				__handleXmlHttpCallback.__xml = bXmlResponse;
				objHttp.onreadystatechange = __handleXmlHttpCallback;
			}
				
			objHttp.open("POST", sURL, callBack!=null);
			objHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			objHttp.send(sFormData);
			
			if(callBack==null)
				result = __handleXmlHttpCallback();
		}
		else
		{
			alert("No AJAX (XMLHTTP Requests) are allowed by this computer.\nPlease check your ActiveX settings or contact support@mobilefx.com for further assistance.");
			result = null;
		}
		
		if(callBack==null)
			objHttp = null;	
	}
	catch(e)
	{
		result = null;
	}

    return result;
}

function __handleXmlHttpCallback()
{
	if(objHttp!=null)
	{
		if(objHttp.readyState==4)
		{
			var result = objHttp.responseText;
					
			var xDom = new ActiveXObject("Microsoft.XMLDOM");
			xDom.async = false;
			xDom.loadXML(result);
			
			if(xDom.documentElement && xDom.documentElement.nodeName=="ERROR")
			{
				var n = xDom.documentElement;
				result = { error: { number: n.getAttribute("number"), description: n.text } };
				n = null;
			}
			
			xDom = null;
			
			if(__handleXmlHttpCallback.__callBack!=null)
			{
				if(__handleXmlHttpCallback.__xml)
					__handleXmlHttpCallback.__callBack(objHttp.responseXML);
				else
					__handleXmlHttpCallback.__callBack(result);
				
				__handleXmlHttpCallback.__xml = null;
				__handleXmlHttpCallback.__callBack = null;
				
				hideLoadingImage();				
			}
			else
				return result;
		}
		return;	
	}
}

function getContentDownloadSMS(OrderGUID, UserContentID, CountryID, PreferredNetwork, fnCallBack)
{
	try
	{
		data = "";
		data += "OrderGUID=" + OrderGUID;
		data += "&UserContentID=" + UserContentID;
		data += "&CountryID=" + CountryID;
		data += "&Network=" + PreferredNetwork;
		getContentDownloadSMSCallBack.__callBack = fnCallBack;
		XMLHttpPost(SITE_URL_BASE + "/web/system/proc_get_content_sms.asp", data, getContentDownloadSMSCallBack);
	}
	catch(e)
	{
		info = null;
		throw e
	}	             
}

function getContentDownloadSMSCallBack(xml)
{	
	var info = null;
	
	if(xml && xml.error)
		info = xml;
	else
	{	
		var xDom = new ActiveXObject("Microsoft.XMLDOM");
		xDom.async = false;
		xDom.loadXML(xml);
		if(xDom.parseError.errorCode==0)
		{
			info = 
			{ 
				OperatorID:		parseInt(xDom.selectSingleNode("/SMS/OperatorID").text),
				ShortCode:		xDom.selectSingleNode("/SMS/ShortCode").text,
				Text:			xDom.selectSingleNode("/SMS/Text").text,
				FinalPrice:		parseMoney(xDom.selectSingleNode("/SMS/FinalOperatorPrice").text),
				NumMessages:	parseInt(xDom.selectSingleNode("/SMS/NumMessages").text),
				BillingComment:	xDom.selectSingleNode("/SMS/BillingComment").text 
			};
		}
		xDom = null;
	}
	
	if(getContentDownloadSMSCallBack.__callBack!=null)
		getContentDownloadSMSCallBack.__callBack(info);
	
	getContentDownloadSMSCallBack.__callBack = null;
	
	return info;	
}

function loadOperators()
{
	try
	{
		while(form1.NetworkOperator.options.length>0)
			form1.NetworkOperator.remove(0);
			
		XMLHttpPost(SITE_URL_BASE + "/web/system/proc_get_operator.asp", "CountryID="+form1.Country.value, __loadOperators);
	}
	catch(e)
	{
		opt = document.createElement("OPTION");
		opt.innerText = "(No supported Networks)";
		form1.NetworkOperator.appendChild(opt);	
	}
}

function __loadOperators(xml)
{
	var cid = form1.Country.value;
	
	try
	{
		if(xml && xml.error)
			throw "ERR_FAIL";
		
		var NETWORK_OPS = new ActiveXObject("Microsoft.XMLDOM");
		NETWORK_OPS.async = false;
		NETWORK_OPS.loadXML(xml);
		if(parseInt(NETWORK_OPS.parseError.errorCode)!=0)
			throw "ERR_FAIL";

		var list = NETWORK_OPS.documentElement.childNodes;
		
		if(list.length==0 && cid>=1)
			throw "ERR_FAIL";
		else
		{
			opt = document.createElement("OPTION");
			opt.innerText = "(Select)";
			form1.NetworkOperator.appendChild(opt);
		}
			
		for(var i=0;i<list.length;i++)
		{
			var node = list[i];
			opt = document.createElement("OPTION");
			opt.innerText = node.text;
			form1.NetworkOperator.appendChild(opt);
		}
		
		if(window['setContentDownloadInfo']==null)
			__fixSelect(form1.NetworkOperator);
	}
	catch(e)
	{
		opt = document.createElement("OPTION");
		opt.innerText = "(No supported Networks)";
		form1.NetworkOperator.appendChild(opt);
		if(window['setContentDownloadInfo']!=null)
			setContentDownloadInfo(xml);
	}
}

function fixSelects()
{
	var selects = document.all.tags("SELECT");
	for(var i=0;i<selects.length;i++)
		__fixSelect(selects[i]);
}

function __fixSelect(select)
{
	for(var j=0; j<select.options.length; j++)
	{
		if(select.xvalue!=null)
		{
			if(select.options[j].innerText==select.xvalue || select.options[j].value==select.xvalue)
			{
				select.selectedIndex = j;
				if(select.name=="Country")
					loadOperators();
				break;
			}
		}
	}
}

function XML_DOM(anyXML)
{
	var obj, sURL, sXML;
	
	obj = new ActiveXObject("Microsoft.XMLDOM");
	obj.async=false;
	obj.setProperty("SelectionLanguage", "XPath");
	
	if(anyXML)
	{
		if(typeof(anyXML)=='object' && anyXML['nodeName'] || anyXML['documentElement'])
			
			sXML = anyXML.xml;
			
		else if(anyXML.indexOf('<')==-1)
		{
			sURL = anyXML;
			obj.load(sURL);
			if(!obj.documentElement) obj.load(sURL);
			sXML = null;
		}
		else
			sXML = anyXML;
		
		if(sXML) obj.loadXML(sXML);
	}
	
	return obj;
}

if(window.attachEvent!=null)
{

window.attachEvent("onload", function()
{
	try
	{
		fixSelects();
	}
	catch(e)
	{
	}
});

}

else

{
window.addEventListener("onload", function()
{
	try
	{
		fixSelects();
	}
	catch(e)
	{
	}
});

}


