/*
*    this script is used to insert and remove user's rss message 
*    in network
*
*   
*    AUTHR :  javier     TIME:  2008 - 11 - 18
*/

/*   At after we will user ymPrompt.js to wirte alert */
document.write("<script language='javascript' src='../../ymPrompt/ymPrompt.js'></script>");   

var xmlHttp;
var requestType="";

function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

function subscrinews(str){
	if(str == ""){
		ymPrompt.alert("Sorry this news is not found","300","180","Not Found");	
	}else{
		createXMLHttpRequest();
		var url = "../../module/chapter/news.php?messagen="+str ;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange=handleStateChange;
		xmlHttp.send(null);
	}
}

function delesubnews(str){
	if(str == ""){
		ymPrompt.alert("Sorry this news is not found","300","180","Not Found");
	}else{
		createXMLHttpRequest();
		var url = "../../module/chapter/news_google_choice.php?dele="+str;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange=handleStateChange;
		xmlHttp.send(null);
	}
}

function addyahoonews(str){
	///alert(str);
	///return false;
	if(str == "") {
		ymPrompt.alert("Sorry this news is not found","300","180","Not Found");
	}else{
		createXMLHttpRequest();
		var url = "../../module/chapter/newchocie.php?yahoo="+str ;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}

function deleteyahoonews(str){
	if(str == ""){
		ymPrompt.alert("Sorry this news is not found","300","180","Not Found");
	}else{
		createXMLHttpRequest();
		var url = "../../module/chapter/newchocie.php?delet="+str;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}

function addiptv(str){
	if(str == "" ){
		ymPrompt.alert("Sorry this video is not found","300","180","Not Found");
	}else{
		createXMLHttpRequest();
		var url = "../../module/chapter/iptv.php?ipvalue="+str;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}

function deliptv(str){
	if(str == "" ){
		ymPrompt.alert("Sorry this video is not found","300","180","Not Found");
	}else{
		createXMLHttpRequest();
		var url = "../../module/chapter/iptv.php?del="+str;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}

function valibeuser(){
	var user = document.getElementById("username").value;
	var pwd = document.getElementById("password").value;
	
	if(user == ""){
		var user = document.getElementById("warnmyerrlog");
		user.innerHTML="<font color='yellow'style='font-size:15px'>Please enter LoginName</font>";
		//alert("Please enter LoginName","300","180","LoginName is null" );
	}else if(pwd == ""){
		var user = document.getElementById("warnmyerrlog");
		user.innerHTML="<font color='yellow'style='font-size:15px'>Please enter Password</font>";
		//ymPrompt.alert("Please enter Password","300","180","Password is null");
	}else{
		createXMLHttpRequest();
		var url = "../../module/chapter/indexsungale.php?user="+user+"&pwd="+pwd ;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange = valibeuserChange;
		xmlHttp.send(null);
	}
}

function forgotsub(){
	var mac = document.getElementById("macid").value;
	var username = document.getElementById("username").value;
	var email = document.getElementById("email").value;
	var divmsg = document.getElementById("divmsg");

	if(mac == ""){divmsg.innerHTML="<font color='yellow' style='font-size:15px'>Please fill in your MACID</font>";}
	else if(username == ""){divmsg.innerHTML="<font color='yellow' style='font-size:15px'>Please fill in your Username</font>";}
	else if(email == ""){divmsg.innerHTML="<font color='yellow' style='font-size:15px'>Please fill in your Email</font>";}
	else{
		createXMLHttpRequest();
		var url = "../../module/chapter/forgot.php?mac="+mac+"&username="+username+"&email="+email ;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange = valibusermessage;
		xmlHttp.send(null);
		divmsg.innerHTML="";
	}
}

function valibusermessage(){
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			var divmsg = document.getElementById("divmsg");
			divmsg.innerHTML("<font color='yellow' style='font-size:15px'>"+xmlHttp.responseText+"</font>");
			document.getElementById("macid").value = "";
			document.getElementById("username").value = "";
			document.getElementById("email").value = "";
		}
	}
}

function valibeuserChange(){
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			if(xmlHttp.responseText == "invalid username or password"){
				
				var user = document.getElementById("warnmyerrlog");
				user.innerHTML="<font color='yellow' style='font-size:15px'>invalid username or password</font>";

				//ymPrompt.alert(xmlHttp.responseText,"300","180","LoginName or Password is error");
				document.getElementById("username").value = "";
			    	document.getElementById("password").value = "";
				//window.document.form1.submit();
			}else{
				window.document.form1.submit();
				//ymPrompt.alert(xmlHttp.responseText,"300","180","LoginName or Password is error");
			}
		}
	}
}


function handleStateChange(){
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			ymPrompt.alert(xmlHttp.responseText,"300","180","Message",handler);
		}
	}
}

function handler(){
	window.location.reload();

}