
function createRequestObject()
{
	var request_o;
	var browser = navigator.appName;
	
	if(window.ActiveXObject)
	{
		try 
		{
			request_o = new ActiveXObject('Msxml2.XMLHTTP');
		} 
		catch (e) 
		{
			try 
			{
				request_o = new ActiveXObject('Microsoft.XMLHTTP');
			} 
			catch (e) {}
		}
	}
	else if(window.XMLHttpRequest)
	{
		request_o = new XMLHttpRequest();
    }
	
	return request_o;
}

var http = createRequestObject();

function loadIframeBack()
{
	toggleLayer('divlogin');
	toggleLayer('divHeader');
	toggleLayer('iframediv1');
}

function loadOpinion(request,uid)
{
	toggleLayer('link2');
	do_it(request,uid);
}

function closeOpinionBack()
{
	history.back();
	toggleLayer('link2');
}

function loadProgramLoginInfo()
{
	var frm = document.getElementById('frmprogram');
	if(http.readyState == 4)
	{
		try 
		{
			if (http.status == 200) 
			{
				var response = http.responseText;				
				var spnLogin = document.getElementById('divlogin');
				spnLogin.innerHTML = response;
				showLayer('divlogin');
				hideLayer('divArchive');
				hideLayer('divHeader');
				hideLayer('iframediv1');
			}
		} 
		catch(err) 
		{
			var spnLogin = document.getElementById('divlogin');
			spnLogin.innerHTML = "<span class='alertmessage2'>Network Error. Try Again</span>";
		   	showLayer('divlogin');
			hideLayer('divArchive');
			hideLayer('divHeader');
			hideLayer('iframediv1');
		}
	}
}

function loadArchiveEpisodes()
{
	if(http.readyState == 4)
	{
		try 
		{
		    if (http.status == 200) 
		    {
			var response = http.responseText;
			var archive = document.getElementById('divArchive');
			archive.innerHTML = response;
			showLayer('divArchive');
			hideLayer('divlogin');
			hideLayer('divHeader');
			hideLayer('iframediv1');
		    }
		} 
		catch(err) 
		{
			var archive = document.getElementById('divHeader');
			archive.innerHTML = "<span class='alertmessage2'>Network Error. Try Again</span>";
			showLayer('divArchive');
			hideLayer('divlogin');
			hideLayer('divHeader');
			hideLayer('iframediv1');
		}
	}
}

function loadProvinces()
{
	if(http.readyState == 4)
	{
	    try 
	    {
		    if (http.status == 200) 
		    {
				var response = http.responseText;				
				var prv = document.getElementById('provincelist');
				prv.innerHTML = response;
		    }
		} 
		catch(err) 
		{
			var prv = document.getElementById('provincelist');
			prv.innerHTML = "<span class='alertmessage2'>Network Error. Try Again</span>";
		}
	}
}

function loadProvinces2()
{
	if(http.readyState == 4)
	{
	    try 
	    {
		    if (http.status == 200) 
		    {
				var response = http.responseText;				
			
				var prv = document.getElementById('billing_provincelist');
				prv.innerHTML = response;
		    }
		} 
		catch(err) 
		{
			var prv = document.getElementById('billing_provincelist');
			prv.innerHTML = "<span class='alertmessage2'>Network Error. Try Again</span>";
		}
	}
}

function fetchProgramLoginInfo2()
{
	if(!http) 
   	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
    	}
	http.open('GET', 'login_ajax.php',true);
	http.onreadystatechange = loadProgramLoginInfo;
	http.send(null);
}

function archive_episodes()
{
	if(!http) 
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http.open('GET', 'archive_episodes_ajax.php',true);
	http.onreadystatechange = loadArchiveEpisodes;
	http.send(null);
}

function getProvinces(cid,prvid)
{
	if(!http) 
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http.open('GET', 'province_ajax.php?cid='+cid+'&prvid='+prvid,true);
	http.onreadystatechange = loadProvinces;
	http.send(null);
}

function getProvinces2(cid,prvid)
{
	if(!http) 
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http.open('GET', 'billing_province_ajax.php?cid='+cid+'&prvid='+prvid,true);
	http.onreadystatechange = loadProvinces2;
	http.send(null);
}


function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display ? "":"none";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display ? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function toggleParentLayer(whichLayer)
{
	if (parent.document.getElementById)
	{
		// this is the way the standards work
		var style2 = parent.document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"none";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = parent.document.all[whichLayer].style;
		style2.display = style2.display ? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = parent.document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function hideLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = "none";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = "block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = "block";
	}
}

function showLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = "";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = "";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = "";
	}
}


function ExpandCollapse(action_id)
{
   var expcol = document.getElementById('link1');
   var cb = document.getElementById('iframediv1');
   if(action_id==1)
   {
	  expcol.innerHTML = '<a href=\"javascript:ExpandCollapse(2);\">Collapse</a>';
	  cb.style.height = 500+'px';
   }
   else
   {
	  expcol.innerHTML = '<a href=\"javascript:ExpandCollapse(1);\">Expand</a>';
	  cb.style.height = 250+'px';
   }
}

function open_popup(link,wid,high)
{
	window.open(link,'','resizable=1,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,width='+wid+',height='+high);
}

function open_popup2(link,wid,high)
{
	window.open(link,'','resizable=1,scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,width='+wid+',height='+high);
}

function open_window(link)
{
	window.open(link,'','');
}

// E-mail validation
function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
	    alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1)
	 {
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	 {
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1)
	 {
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 return true					
}

	function changePayRegisterImage(url, button_name,item)
	{
	   var cb = document.getElementById(button_name);
	   if(item.checked)
	   {
		cb.style.backgroundImage = "url" + '(' + url + 'registerandpay.gif'+ ')';
	   }
	   else
	   {
		cb.style.backgroundImage = "url" + '(' + url + 'registerandpay_dis.gif'+ ')';
	   }
	}


	function changeUpgradePaymentImage(url, button_name,item)
	{
	   var cb = document.getElementById(button_name);
	   if(item.checked)
	   {
		cb.style.backgroundImage = "url" + '(' + url + 'payment.gif'+ ')';
	   }
	   else
	   {
		cb.style.backgroundImage = "url" + '(' + url + 'payment_dis.gif'+ ')';
	   }
	}

	function login_valiadate(frm)
	{
		if (!frm.txtLogUsername.value)
		{
		   alert('Please enter your login name.');
		   frm.txtLogUsername.focus();
		   return false;
		}
		if (!frm.txtLogPassword.value)
		{
		   alert('Please enter your password.');
		   frm.txtLogPassword.focus();
		   return false;
		}
		return true;
	}

	function closeArchive()
	{
		showLayer('divHeader');
		showLayer('iframediv1');
		hideLayer('divArchive');
	}


function setRestoreImage(item,imgsrc)
{
	item.src= imgsrc;
}

function setSwapImage(item,imgsrc)
{
	item.src= imgsrc;
}
