//Global variable
var storedContent='';
function createAjax(){
    var xmlHttp;
	try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  	catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
	{
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
      catch (e)
	{
	alert("Your browser does not support AJAX!");
	return false;
	}
      }
    }
    return xmlHttp;
}

function goToFullPheed(){
    var currLocation=window.location;
    currLocation=currLocation.toString();
    currLocation=currLocation.replace('_images', '');
    for(var i=0; i<20; i++){
        currLocation=currLocation.replace('%27', '\'');
    }
    window.location=currLocation;
}

function checkMatching(){
    if(document.reg.password.value==document.reg.conf.value && document.reg.conf.value!='' && document.reg.password.value!=''){
        document.getElementById("matching").innerHTML='<font style="color: green; font-family: Arial,Helvetica,sans-serif;">Matches</font>';
    }
    else if(document.reg.conf.value!='' && document.reg.password.value!=''){
        document.getElementById("matching").innerHTML='<font style="color: red; font-family: Arial,Helvetica,sans-serif;">Doesn\'t Match</font>';
    }
}

function sendToAFriend(urlToSend, title){
  var email=document.getElementById('friendemail').value;
  var senderEmail=document.getElementById('senderemail').value;
  var senderName=document.getElementById('sendername').value;
  var name=document.getElementById('friendname').value;
  var personalMessage=document.getElementById('pmessage').value;
  if(senderName!=''){
      if(senderEmail.indexOf('@', 0) > -1 && senderEmail.indexOf('.') > -1 && senderEmail.indexOf(' ') < 0 && senderEmail!=''){
          if(name!=''){
                if(email.indexOf('@', 0) > -1 && email.indexOf('.') > -1 && email.indexOf(' ') < 0 && email!=''){
                  var xmlHttp=createAjax();
                  xmlHttp.onreadystatechange=function()
                  {
                      if(xmlHttp.readyState==4)
                      {
                          if(xmlHttp.responseText==1){
                              document.getElementById('emailmessage').innerHTML='E-Mail Sent';
                              document.getElementById('friendemail').value='';
                              document.getElementById('senderemail').value='';
                              document.getElementById('sendername').value='';
                              document.getElementById('friendname').value='';
                              document.getElementById('pmessage').value='';
                          }
                          else{
                              document.getElementById('emailmessage').innerHTML='E-Mail NOT Sent, Please retry';
                          }
                      }
                  }
                  url="../sendtoafriend.php?email="+email+"&url="+urlToSend+"&name="+name+"&sendername="+senderName+"&senderemail="+senderEmail+"&pmessage="+personalMessage+"&title="+title;
                  xmlHttp.open("GET",url,true);
                  xmlHttp.send(null);
              }
              else {
                  alert('Please enter a valid friend email');
                  document.getElementById('friendemail').focus();
              }
        }
        else {
            alert('Please enter your friend\'s Name');
            document.getElementById('friendname').focus();
        }
      }
      else {
          alert('Please enter a valid email');
          document.getElementById('senderemail').focus();
      }
}
else {
    alert('Please enter your Name');
    document.getElementById('sendername').focus();
}
  
}

function showHideOtherForm(theCheckBox){
    var formLength=document.twitterform.elements.length;
    if(theCheckBox.checked==false){
        //document.getElementById('otherform').style.display='none';
        for(var i=0; i<formLength; i++){
            if(document.twitterform.elements[i].name!='enableupdates' && document.twitterform.elements[i].name!='idfeed' && document.twitterform.elements[i].type!='submit' && document.twitterform.elements[i].type!='button' ){
                document.twitterform.elements[i].disabled=true;
            }
            else if(document.twitterform.elements[i].type=='submit' && document.twitterform.elements[i].value=='Next Step'){
                document.twitterform.elements[i].value='Save';
            }
        }
        document.getElementById('otherform').style.display='none';
    }
    else {
        //document.getElementById('otherform').style.display='inline';
        for(var i=0; i<formLength; i++){
            if(document.twitterform.elements[i].name!='enableupdates' && document.twitterform.elements[i].type!='submit' && document.twitterform.elements[i].type!='button' ){
                document.twitterform.elements[i].disabled=false;
            }
            else if(document.twitterform.elements[i].type=='submit' && document.twitterform.elements[i].value=='Save'){
                document.twitterform.elements[i].value='Next Step';
            }
        }
        document.getElementById('otherform').style.display='inline';
    }
    return true;
}

function postAgeSet(setting){
    if(setting=='preset'){
        document.getElementById('postagedaterange').style.display='none';
        document.getElementById('postagepresets').style.display='inline';
    }
    if(setting=='range'){
        document.getElementById('postagedaterange').style.display='inline';
        document.getElementById('postagepresets').style.display='none';
    }
    return;
}

function checkTwitterForm(){
    if(document.getElementById('stopupdates').checked==true){
        for(var i=1; i<8; i++){
        var dayInput='day'+i;
        var oneChecked=false;
        if(document.getElementById(dayInput).checked==true){
           oneChecked=true;
           i=8;
        }
    }
    if(!oneChecked){
        alert('At least one day should be chosen.');
        return false;
    }
    for(i=1; i<25; i++){
        var timeInput='time'+i;
        oneChecked=false;
        if(document.getElementById(timeInput).checked==true){
           oneChecked=true;
           i=26;
        }
    }
    if(!oneChecked){
        alert('At least one hour of the day should be chosen.');
        return false;
    }
    if(document.twitterform.twitter.value=='' || document.twitterform.twitter.value=='ScreenName'){
        alert('Please enter your twitter sceen name that you are following us with');
        document.twitterform.twitter.focus();
        return false;
    }
    if(document.getElementById('ownmess').value=='' && document.getElementById('ownmess').checked==true){
        alert('Please enter the message format you would like to receive or chose one of the defaults');
        document.twitterform.messageformat.focus();
        return false;
    }
    }
    return true;
}

function checkEmailForm(){
    if(document.getElementById('stopupdates').checked==true){
        for(var i=1; i<8; i++){
        var dayInput='day'+i;
        var oneChecked=false;
        if(document.getElementById(dayInput).checked==true){
           oneChecked=true;
           i=8;
        }
    }
    if(!oneChecked){
        alert('At least one day should be chosen.');
        return false;
    }
    for(i=1; i<25; i++){
        var timeInput='time'+i;
        oneChecked=false;
        if(document.getElementById(timeInput).checked==true){
           oneChecked=true;
           i=26;
        }
    }
    if(!oneChecked){
        alert('At least one hour of the day should be chosen.');
        return false;
    }
    }
    return true;
}


function checkContact(){
	if(document.contact.fname.value==""){
		alert("Please fill in your first name");
		document.contact.fname.focus();
		return false;
	}
	if(document.contact.lname.value==""){
		alert("Please fill in your last name");
		document.contact.lname.focus();
		return false;
	}
	if(document.contact.email.value==""){
		alert("Please fill in your email");
		document.contact.email.focus();
		return false;
	}
	if ((document.contact.email.value.indexOf('@', 0) == -1) || (document.contact.email.value.indexOf('.') == -1) || (document.contact.email.value.indexOf(' ') > 0)){
		alert ("Please fill in a correct email" );
		document.contact.email.focus();
		return false;
	}
	
	if(document.contact.message.value==""){
		alert("Please fill in your message");
		document.contact.message.focus();
		return false;
	}
}

function fixFillerHeight(){
    var fullTableHeight=document.getElementById('thefulltable').offsetHeight;
    if(window.innerHeight!='undefined' && window.innerHeight>0){
        windowHeight=window.innerHeight;
    }
    else {
        windowHeight=document.body.offsetHeight;
    }
    document.getElementById('thefiller').style.height=25+(windowHeight-fullTableHeight)+'px';
}

function goToStep2(){
	if(document.reg.email.value==''){
		alert('Please Fill in your email');
		document.reg.email.focus();
		return false;
	}
	if ((document.reg.email.value.indexOf('@', 0) == -1) || (document.reg.email.value.indexOf('.') == -1) || (document.reg.email.value.indexOf(' ') != -1)){
		alert ("Please fill in a correct email" );    
		document.reg.email.focus();
		return false;
	}
	if(document.reg.firstname.value==''){
		alert('Please fill in your First Name');
		document.reg.firstname.focus();
		return false;
	}
	if(document.reg.dispname.value==''){
		alert('Please choose a Display Name');
		document.reg.dispname.focus();
		return false;
	}
	if(document.reg.password.value==''){
		alert('Please Fill in a password');
		document.reg.password.focus();
		return false;
	}
	if(document.reg.conf.value==''){
		alert('Please Confirm your password');
		document.reg.conf.focus();
		return false;
	}
	if(document.reg.password.value!=document.reg.conf.value){
		alert('Password and confirmation doesn\'t match');
		document.reg.password.focus();
		return false;
	}
	if(document.reg.available.value==0){
		alert('Your display name is already taken please choose another');
		document.reg.dispname.focus();
		return false;
	}
	if(document.reg.terms.checked==false){
		alert('You should accept the terms and conditions of the site to be able to register!');
		document.reg.termes.focus();
		return false;
	}
}

function updateAccount(){
	if(document.reg.email.value==''){
		alert('Please Fill in your email');
		document.reg.email.focus();
		return false;
	}
	if ((document.reg.email.value.indexOf('@', 0) == -1) || (document.reg.email.value.indexOf('.') == -1) || (document.reg.email.value.indexOf(' ') >= 1)){
		alert ("Please fill in a correct email" );    
		document.reg.email.focus();
		return false;
	}
	if(document.reg.password.value!=document.reg.conf.value){
		alert('Password and confirmation doesn\'t match');
		document.reg.password.focus();
		return false;
	}
	if(document.reg.firstname.value==''){
		alert('Please fill in your First Name');
		document.reg.firstname.focus();
		return false;
	}
	if(document.reg.oldpassword.value!='' || document.reg.password.value!='')
	{
		if(document.reg.password.value==''){
			alert('Please Pick a New Password');
			document.reg.password.focus();
			return false;
		}
		if(document.reg.conf.value==''){
			alert('Please Confirm Your New Password');
			document.reg.conf.focus();
			return false;
		}
		if(document.reg.conf.value!=document.reg.password.value){
			alert('New password and confirmation did not match');
			document.reg.password.focus();
			return false;
		}
	}
}

function getOtherAnswer(idQuestion, position){
  var xmlHttp=createAjax();
  xmlHttp.onreadystatechange=function()
  {
      if(xmlHttp.readyState==4)
      {
        document.getElementById('answers').innerHTML=xmlHttp.responseText;
      }
  }
  url="getotheranswers.php?id="+idQuestion+"&position="+position;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function getNewTime(theGmtTime){
  var xmlHttp=createAjax();
  xmlHttp.onreadystatechange=function()
  {
      if(xmlHttp.readyState==4)
      {
        document.getElementById('time').innerHTML=xmlHttp.responseText;
      }
  }
  url="../gettimegmt.php?gmtoffset="+theGmtTime;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}
function showHideSwButton(enCheckBox){
  if(enCheckBox.checked==true){
      document.getElementById('swearbutton').style.display='inline';
  }
  else {
      document.getElementById('swearbutton').style.display='none';
      hideSwearWordStuff();
  }
}

function followFeed(idOwner, idFeed){
	  var xmlHttp=createAjax();
	  xmlHttp.onreadystatechange=function()
	  {
	      if(xmlHttp.readyState==4)
	  	  {
	  	  	document.getElementById('followfeed'+idFeed).style.display='none';
		  }
	  }
      url="../followfeed.php?idowner="+idOwner+"&idfeed="+idFeed;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
}
function followFeedOut(idOwner, idFeed){
	  var xmlHttp=createAjax();
	  xmlHttp.onreadystatechange=function()
	  {
	      if(xmlHttp.readyState==4)
	  	  {
	  	  	document.getElementById('followfeed'+idFeed).style.display='none';
		  }
	  }
      url="followfeed.php?idowner="+idOwner+"&idfeed="+idFeed;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
}

//Function checkOpenIdReg
function checkOpenIdReg(){
	if(document.reg.email.value==''){
		alert('Please Fill in your email');
		document.reg.email.focus();
		return false;
	}
	if ((document.reg.email.value.indexOf('@', 0) == -1) || (document.reg.email.value.indexOf('.') == -1) || (document.reg.email.value.indexOf(' ') != -1)){
		alert ("Please fill in a correct email" );    
		document.reg.email.focus();
		return false;
	}
	if(document.reg.firstname.value==''){
		alert('Please fill in your First Name');
		document.reg.firstname.focus();
		return false;
	}
	if(document.reg.lastname.value==''){
		alert('Please fill in your Last Name');
		document.reg.lastname.focus();
		return false;
	}
	if(document.reg.dispname.value==''){
		alert('Please choose a Display Name');
		document.reg.dispname.focus();
		return false;
	}
	if(document.reg.available.value==0){
		alert('Your display name is already taken please choose another');
		document.reg.dispname.focus();
		return false;
	}
	if(document.reg.terms.checked==false){
		alert('You should accept the terms and conditions of the site to be able to register!');
		document.reg.termes.focus();
		return false;
	}
}
//End of checkOpenIdReg
//function fixUrl fixes urls inserted while creating a new feed or editing an existing one
function fixUrl(url, urlInput, inputNum){
	urlHttpPart=url.substring(0, 7);
	if(urlHttpPart!='http://' && urlHttpPart!='Http://' && urlHttpPart!='HTTP://' && urlHttpPart!='' && urlHttpPart!='Feed://' && urlHttpPart!='FEED://' && urlHttpPart!='feed://'){
		url=urlInput.value.replace(' ', '');
		for(var i=0; i<100; i++){
			url=url.replace(' ', '');
		}
		urlInput.value='http://'+url;
	}
	else {
		url=urlInput.value.replace(' ', '');
		for(var i=0; i<100; i++){
			url=url.replace(' ', '');
		}
		urlInput.value=url;
	}
    toCheckUrl=urlInput.value;
    //Including a function to check url
    var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
            var urlMessage='url'+inputNum+'message';
            var urlValidInput='url'+inputNum+'valid';
            var urlInput='url'+inputNum;
            theResponseArray=xmlHttp.responseText.split('|');
            if(theResponseArray[0]==1){
                document.getElementById(urlMessage).innerHTML='<font style="font-family: Arial, Verdana; color: green; font-size: 12px; padding-left: 2px;">Valid</font>';
                if(theResponseArray[1]!='' && xmlHttp.responseText!=1){
                    document.getElementById(urlInput).value=theResponseArray[1];
                }
                document.getElementById(urlValidInput).value=1;
            }
            else {
                document.getElementById(urlMessage).innerHTML='<font style="font-family: Arial, Verdana; color: red; font-size: 12px; padding-left: 2px;">Invalid</font>';
                document.getElementById(urlValidInput).value=0;
            }
        }
    }
    toCheckUrl2=toCheckUrl;
    for(i=0; i<20; i++){
    	toCheckUrl2=toCheckUrl2.replace('&', ';;;;');
    }
    for(i=0; i<20; i++){
    	toCheckUrl2=toCheckUrl2.replace('+', '(pls)');
    }
    for(i=0; i<20; i++){
    	toCheckUrl2=toCheckUrl2.replace('%22', 'THEQUOTES');
    }
    for(i=0; i<20; i++){
    	toCheckUrl2=toCheckUrl2.replace('"', 'THEQUOTES');
    }
    url="../checkurlrss.php?url="+toCheckUrl2;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
//End of fixUrl

function getSubCats(idCat){
		if(idCat==""){
                    document.getElementById("subcat").innerHTML="";
                    document.getElementById("subcategorizeit").innerHTML="";
                }
                else {
                 var xmlHttp=createAjax();
                 if(idCat==13){
                 	document.getElementById('subcatforjs').value=0;
                 }
		    xmlHttp.onreadystatechange=function()
		      {
		      if(xmlHttp.readyState==4)
			{
                document.getElementById("subcat").innerHTML=xmlHttp.responseText;
                document.getElementById("subcategorizeit").innerHTML='Please Choose a Subcategory<span class="form-star">*</span>';
                document.getElementById("thesubcattofocus").focus();
			}
		    }
		    url="../getsubcats.php?id="+idCat;
		    xmlHttp.open("GET",url,true);
		    xmlHttp.send(null);}
}
//End of getSubCats

function getSubCatsFM(idCat, idFeed){
		if(idCat==""){
                    document.getElementById("subcat"+idFeed).innerHTML='<select class="medium-input"></select>';
                }
                else {
                 var xmlHttp=createAjax();
                 if(idCat==13){
                 	document.getElementById('subcatforjs'+idFeed).value=0;
                 }
		    xmlHttp.onreadystatechange=function()
		      {
		      if(xmlHttp.readyState==4)
			{
                document.getElementById("subcat"+idFeed).innerHTML=xmlHttp.responseText;
                document.getElementById("thesubcattofocus").focus();
			}
		    }
		    url="../getsubcatsfm.php?id="+idCat+"&idfeed="+idFeed;
		    xmlHttp.open("GET",url,true);
		    xmlHttp.send(null);}
}
//End of getSubCatsFM

function checkLogin(){
	if(document.login.email.value==''){
		alert('Please Fill in your email');
		document.login.email.focus();
		return false;
	}
	/*if ((document.login.email.value.indexOf('@', 0) == -1) || (document.login.email.value.indexOf('.') == -1) || (document.login.email.value.indexOf(' ') != -1)){
		alert ("Please fill in a correct email" );    
		document.login.email.focus();
		return false;
	}*/
	if(document.login.password.value==''){
		alert('Please Fill in your password');
		document.login.password.focus();
		return false;
	}
}

function checkLoginAdmin(){
	if(document.login.login.value==''){
		alert('Please Fill in your username');
		document.login.login.focus();
		return false;
	}
	if(document.login.password.value==''){
		alert('Please Fill in your password');
		document.login.password.focus();
		return false;
	}
}

function checkCreateFeed(maxAllowedUrls, maxAllowedBaskets){
	if(document.createfeed.feedname.value=='' || document.createfeed.feedname.value==' ' || document.createfeed.feedname.value=='   '){
		alert('Please Pick a name for your Pheed');
		document.createfeed.feedname.focus();
		return false;
	}
	var notEmpty=false;
	for(var i=1; i<=maxAllowedUrls; i++){
		thisUrl='url'+i;
		thisUrl=document.getElementById(thisUrl).value
		if(thisUrl!=''){
			notEmpty=true;
			i=maxAllowedUrls+1;
		}
	}
	
	if(!notEmpty){
		alert('Please fill in at least 1 feed url');
		document.createfeed.url1.focus();
		return false;
	}
    for(i=1; i<=maxAllowedUrls; i++){
		thisUrl='url'+i;
        thisUrlValid='url'+i+'valid';
		thisUrl=document.getElementById(thisUrl).value;
        thisUrlValid=document.getElementById(thisUrlValid).value;
		if(thisUrl!='' && thisUrlValid!=1){
			alert('Url '+i+' is not valid, please fix it');
            return false;
		}
	}
    for(i=1; i<11; i++){
        if(document.getElementById("word"+i).value=="Your Keyword"){
            document.getElementById("word"+i).value='';
        }
    }
    return true;
}
function checkEditFeed(maxAllowedUrls, maxAllowedBaskets){
	if(document.editfeed.feedname.value=='' || document.editfeed.feedname.value==' ' || document.editfeed.feedname.value=='   '){
		alert('Pheed Name cannot be empty');
		document.editfeed.feedname.focus();
		return false;
	}
    var notEmpty=false;
	for(var i=1; i<=maxAllowedUrls; i++){
		thisUrl='url'+i;
		thisUrl=document.getElementById(thisUrl).value
		if(thisUrl!=''){
			notEmpty=true;
			i=maxAllowedUrls+1;
		}
	}
	if(!notEmpty){
		alert('Please fill in at least 1 feed url');
		document.editfeed.url1.focus();
		return false;
	}
    for(i=1; i<=maxAllowedUrls; i++){
		thisUrl='url'+i;
        thisUrlValid='url'+i+'valid';
		thisUrl=document.getElementById(thisUrl).value;
        thisUrlValid=document.getElementById(thisUrlValid).value;
		if(thisUrl!='' && thisUrlValid!=1){
			alert('Url '+i+' is not valid, please fix it');
            return false;
		}
	}
   
    for(i=1; i<11; i++){
        if(document.getElementById("word"+i).value=="Your Keyword"){
            document.getElementById("word"+i).value='';
        }
    }
    return true;
}
//Function that gets next description
function getPrevDesc(idDesc, idFeed, currDesc){
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('description').innerHTML='Getting previous description...';
      }
      if(xmlHttp.readyState==4)
	{	
		document.getElementById('description').innerHTML=xmlHttp.responseText;
	}
    }
    url="getprevdesc.php?iddesc="+idDesc+"&idfeed="+idFeed+"&currdesc="+currDesc;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
//end of getNextDesc function;
//Function that makes a feed private or not
function setPrivate(id, private) {
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
	{	
		if(private==0){
			document.getElementById('priv'+id).src='../images/private.gif';
			document.getElementById('privspan'+id).innerHTML='<a style="padding-right: 3px;" onClick="setPrivate('+id+', 1)" title="This feed is Public"><img src="../images/private.gif" class="edit-image" id="priv'+id+'" border="0" title="This feed is Private" /></a>';
        }
		else if(private==1){
			document.getElementById('priv'+id).src='../images/notprivate.gif';
            document.getElementById('privspan'+id).innerHTML='<a style="padding-right: 3px;" onClick="setPrivate('+id+', 0)" title="This feed is Private"><img src="../images/notprivate.gif" class="edit-image" id="priv'+id+'" border="0" title="This feed is Public" /></a>';
        }
	}
    }
    if(private==0){
    	privateToSend=1;
    }
    else {
    	privateToSend=0;
    }
    url="../setprivate.php?idfeed="+id+"&private="+privateToSend;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
//End of setprivate

//Function that removes posts from a certain feed
function removePost(idPost, idFeed){
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
	{	
		document.getElementById(idPost).style.display='none';
	}
    }
    url="../removepost.php?idpost="+idPost+"&idfeed="+idFeed;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
//end of removePost function;

//Function that delete a user basket
function deleteBasket(idBasket, basketName){
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
	{	
		document.getElementById('basket'+idBasket).style.display='none';
	}
    }
    url="../deletebasket.php?idbasket="+idBasket+"&basketname="+basketName;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
//end of deleteBasket function;

//Function that gets next description
function getNextDesc(idDesc, idFeed, currDesc){
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('description').innerHTML='Getting next description...';
      }
      if(xmlHttp.readyState==4)
	{	
		document.getElementById('description').innerHTML=xmlHttp.responseText;
	}
    }
    url="getnextdesc.php?iddesc="+idDesc+"&idfeed="+idFeed+"&currdesc="+currDesc;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
//end of getNextDesc function;


function fixFeedName(feedName){
	var i;
    for(i=0; i<30; i++){
        feedName=feedName.replace('/', '-');
        feedName=feedName.replace('\\', '-');       
        feedName=feedName.replace('"', ' ');
    }
	
	document.getElementById('feedname').value=feedName;
	
}
function fixAndCheckDisplayName(dispName){
	document.getElementById('available').value=0;
    for(i=0; i<30; i++){
        dispName=dispName.replace('.', '-');
         dispName=dispName.replace('?', '-');
        dispName=dispName.replace(',', '-');
        dispName=dispName.replace('/', '-');
        dispName=dispName.replace('\\', '-');
        dispName=dispName.replace('"', ' ');
    }
	dispNameArr=dispName.split(" ");
	var i;
	dispName='';
	for(i=0; i<dispNameArr.length; i++){
		dispName+=dispNameArr[i];
	}
	document.getElementById('dispname').value=dispName;
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
    {
        if(xmlHttp.responseText=='Available'){
            document.getElementById('available').value=1;
            var theFont='<font style="color: green; font-family: Arial,Helvetica,sans-serif;">';
        }
        else {
        	var theFont='<font style="color: red; font-family: Arial,Helvetica,sans-serif;">';
        }
        document.getElementById('availability').innerHTML=theFont+' '+xmlHttp.responseText+'</font>';
    }
    }
    url="checkavailability.php?name="+dispName;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function getWizardForm(){
	if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{	
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;
	}
    }
    url="../wizardform.php";
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function getGlobalFilter(showSwStuff){
    if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;
        if(showSwStuff!=''){
            showSwearWordStuff();
            var showSwStuffArr=showSwStuff.split(',');
            for(var i=0; i<document.editglobals.elements.length; i++){
                for(var j=0; j<showSwStuffArr.length; j++){
                    if(document.editglobals.elements[i].value==showSwStuffArr[j]){
                        document.editglobals.elements[i].checked=true;
                    }
                }
            }
            document.editglobals.addedsw.value=showSwStuff;
        }
	}
    }
    url="../globalfilters.php";
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function geteditAcount(){
    if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{	
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;
	}
    }
    url="../editacount.php";
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}


function getTools(idFeed){
	if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{	
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;
		
	}
    }
    url="../wizardformedit.php?id="+idFeed;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function getTwitterForm(idFeed){
    if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;

        showHideOtherForm(document.twitterform.stopupdates);

	}
    }
    url="../twitterstepone.php?id="+idFeed;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function getEmailForm(idFeed){
    if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;

        showHideOtherForm(document.twitterform.stopupdates);

	}
    }
    url="../emailstepone.php?id="+idFeed;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function twitterStepOne(){
    if(document.getElementById('twitter').value!=''){
        var xmlHttp=createAjax();
        var twitterName=document.getElementById('twitter').value;
        var idFeed=document.getElementById('idfeed').value;
         xmlHttp.onreadystatechange=function()
             {
          if(xmlHttp.readyState!=4){
            document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
          }
          if(xmlHttp.readyState==4){
                document.getElementById('feeds').innerHTML=xmlHttp.responseText;
          }
        }
        url="../twitterstepone.php?id="+idFeed+"&twittername="+twitterName;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    else {
        alert("Your twitter name cannot be empty.");
    }
}
function twitterStepThree(){
    if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
    var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
         {
      if(xmlHttp.readyState!=4){
        document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4){
            document.getElementById('feeds').innerHTML=xmlHttp.responseText;
      }
    }
    url="../twitterstepthree.php";
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
//Function to check xml file availability
function checkXMLAvailability(xmlName, idUser, idFeed){
			xmlName=escape(xmlName);
			var xmlHttp=createAjax();
		    xmlHttp.onreadystatechange=function()
		      {
		      if(xmlHttp.readyState==4)
			{	
				document.getElementById('feedname').value=xmlHttp.responseText;
			}
		    }
		    url="../checkxmlavailable.php?filename="+xmlName+"&id="+idUser+"&idfeed="+idFeed;
		    xmlHttp.open("GET",url,true);
		    xmlHttp.send(null);
}
//***End of check xml availability***//

//Function that gets back what was in the div before the edit button was clicked
 function cancelEdit(idFeed){
        document.getElementById('feeds').innerHTML=storedContent;
 }
//end of cancel edit function


//Function that delete feeds
 function delFeed(idFeed){
	 if(confirm('Are you sure you want to delete this Pheed permanently?')){
     var currLocation=window.location;
     currLocation=currLocation.toString();
     currLocation=currLocation.replace('#', '');
     
	 var xmlHttp=createAjax();
		    xmlHttp.onreadystatechange=function()
		      {
		      if(xmlHttp.readyState==4)
			{	
				window.location=currLocation;
			}
		    }
		    url="../deletefeed.php?id="+idFeed;
		    xmlHttp.open("GET",url,true);
		    xmlHttp.send(null);
	 }
 }
//end of delete feed function

//Function that delete feeds
 function unFollow(idOwner, idFeed){
	 if(confirm('Are you sure you want to stop this Pheed?')){
     var currLocation=window.location;
	 var xmlHttp=createAjax();
		    xmlHttp.onreadystatechange=function()
		      {
		      if(xmlHttp.readyState==4)
			{
				window.location=currLocation;
			}
		    }
		    url="../unfollowfeed.php?idowner="+idOwner+"&idfeed="+idFeed;
		    xmlHttp.open("GET",url,true);
		    xmlHttp.send(null);
	 }
 }


//function showFeedURL shows feed url in another div to be copiable
function showURL(idFeed, urlFeed, theEditDiv, desc){
	for(var i=0; i<19; i++){
		urlFeed=urlFeed.replace('"', '&quot;');
	}
    var theClass;
    var linksDivHieght;
    if((theEditDiv%2)==0){
        theClass="bigArticle-even";
    }
    else{
        theClass="bigArticle-odd";
    }
	if(document.getElementById(idFeed+'details')){
        //Getting the height of that div
         linksDivHieght=document.getElementById(idFeed+'details').offsetHeight;
    }
    else {
         linksDivHieght=document.getElementById(idFeed).offsetHeight;
    }
    linksDivHieght-=20;
	//Setting the images xml Link
	var urlFeedImages=urlFeed.replace('.xml', '');
	urlFeedImages=urlFeedImages+'_images.xml';
	//Setting the inner html of the div to show
	document.getElementById(theEditDiv+'edit').innerHTML='<div align="left" style="padding-top: 5px; float: left; width: 95%; height: '+linksDivHieght+'px"><table cellpadding="0" cellspacing="0"><tr><td width="10"></td><td align="left" class="form-label">Full Feed:</td><td width="10"></td><td align="left"><input type="text" class="feed-input" readonly value="'+urlFeed+'" /></td></tr><tr><td></td><td align="left" class="form-label">Images Only:</td><td></td><td align="left"><input type="text" class="feed-input" readonly value="'+urlFeedImages+'" /></td></tr></table></div><div align="right" style="float: left;"><img src="../images/quitbutton.gif" class="edit-image" onClick="hideURL('+idFeed+', '+theEditDiv+');" /></div>';
	
	//Getting position of the feed div
	obj=document.getElementById(idFeed);
	curtop=posGetTop(obj);
	curleft=posGetLeft(obj);
	//End of getting position of the feed div
    document.getElementById(theEditDiv+'edit').style.height=linksDivHieght+'px';
    document.getElementById(theEditDiv+'edit').className=theClass;
    document.getElementById(theEditDiv+'edit').setAttribute('style', 'height: '+linksDivHieght+'px');
	document.getElementById(theEditDiv+'edit').style.position='absolute';
	document.getElementById(theEditDiv+'edit').style.display='inline';
    if(desc==1){
        document.getElementById(theEditDiv+'edit').style.top=(curtop+28)+'px';
    }
    else {
        document.getElementById(theEditDiv+'edit').style.top=(curtop+23)+'px';
    }
	
	document.getElementById(theEditDiv+'edit').style.left=(curleft+9)+'px';
	
}
//end of function showFeedURL

//function hideURL shows feed url in another div to be copiable
function hideURL(idFeed, theEditDiv){
	document.getElementById(idFeed).style.display='inline';
	document.getElementById(theEditDiv+'edit').style.display='none';
}
//end of function showFeedURL


//Function insertIntoUrl insert a url from the used feeds drop down
function insertIntoUrl(url, urlEntry, maxUrls){
	var j=0;
	var selected=urlEntry.selectedIndex;
	if(!urlEntry.options[selected].disabled){
		for(var k=0; k<maxUrls; k++){
			j++;
			if(j<=(maxUrls)){
				if(document.getElementById('url'+j).value==''){
					document.getElementById('url'+j).value=url;
					document.getElementById('url'+j+'valid').value=1;
					if(document.getElementById('url'+j).value==url){			
						urlEntry.options[selected].disabled='disabled';
					}
					if(document.getElementById('url'+j+'col')){
						document.getElementById('url'+j+'col').style.display='inline';
					}
					if(document.getElementById('url'+(j+1)+'col')){
						document.getElementById('url'+(j+1)+'col').style.display='inline';
					}
					k=maxUrls;
				}
			}
	   }	
	}
}
//End of insertIntoUrl
//Function enableUrl enables an already disabled url that was clicked on
function enableUrl(maxOptions, maxUrls){
	var dontEnable=false;
	for(var i=0; i<maxOptions; i++){
		for(var j=1; j<=maxUrls; j++){
			if(document.getElementById('url'+j).value==document.getElementById('sourcefeeds').options[i].value){
				dontEnable=true;
			}
		}
		if(!dontEnable){
			document.getElementById('sourcefeeds').options[i].disabled=false;
		}
		else {
			dontEnable=false;
		}
	}
}








function posGetLeft(o) {
		var fixBrowserQuirks = true;
			// If a string is passed in instead of an object ref, resolve it
		if (typeof(o)=="string") {
			o = resolveObject(o);
		}
		
		if (o==null) {
			return null;
		}
		
		var left = 0;
		var top = 0;
		var width = 0;
		var height = 0;
		var parentNode = null;
		var offsetParent = null;
	
		
		offsetParent = o.offsetParent;
		var originalObject = o;
		var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
		while (el.parentNode!=null) {
			el = el.parentNode;
			if (el.offsetParent==null) {
			}
			else {
				var considerScroll = true;
				/*
				In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 
				take its scroll position into account. If elements further up the chain are scrollable, their 
				scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value
				which must be ignored.
				*/
				if (fixBrowserQuirks && window.opera) {
					if (el==originalObject.parentNode || el.nodeName=="TR") {
						considerScroll = false;
					}
				}
				if (considerScroll) {
					if (el.scrollTop && el.scrollTop>0) {
						top -= el.scrollTop;
					}
					if (el.scrollLeft && el.scrollLeft>0) {
						left -= el.scrollLeft;
					}
				}
			}
			// If this node is also the offsetParent, add on the offsets and reset to the new offsetParent
			if (el == offsetParent) {
				left += o.offsetLeft;
				if (el.clientLeft && el.nodeName!="TABLE") { 
					left += el.clientLeft;
				}
				top += o.offsetTop;
				if (el.clientTop && el.nodeName!="TABLE") {
					top += el.clientTop;
				}
				o = el;
				if (o.offsetParent==null) {
					if (o.offsetLeft) {
						left += o.offsetLeft;
					}
					if (o.offsetTop) {
						top += o.offsetTop;
					}
				}
				offsetParent = o.offsetParent;
			}
		}
		
	
		if (originalObject.offsetWidth) {
			width = originalObject.offsetWidth;
		}
		if (originalObject.offsetHeight) {
			height = originalObject.offsetHeight;
		}
		
		return left;
	};
	function posGetTop(o) {
		var fixBrowserQuirks = true;
			// If a string is passed in instead of an object ref, resolve it
		if (typeof(o)=="string") {
			o = resolveObject(o);
		}
		
		if (o==null) {
			return null;
		}
		
		var left = 0;
		var top = 0;
		var width = 0;
		var height = 0;
		var parentNode = null;
		var offsetParent = null;
	
		
		offsetParent = o.offsetParent;
		var originalObject = o;
		var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
		while (el.parentNode!=null) {
			el = el.parentNode;
			if (el.offsetParent==null) {
			}
			else {
				var considerScroll = true;
				/*
				In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 
				take its scroll position into account. If elements further up the chain are scrollable, their 
				scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value
				which must be ignored.
				*/
				if (fixBrowserQuirks && window.opera) {
					if (el==originalObject.parentNode || el.nodeName=="TR") {
						considerScroll = false;
					}
				}
				if (considerScroll) {
					if (el.scrollTop && el.scrollTop>0) {
						top -= el.scrollTop;
					}
					if (el.scrollLeft && el.scrollLeft>0) {
						left -= el.scrollLeft;
					}
				}
			}
			// If this node is also the offsetParent, add on the offsets and reset to the new offsetParent
			if (el == offsetParent) {
				left += o.offsetLeft;
				if (el.clientLeft && el.nodeName!="TABLE") { 
					left += el.clientLeft;
				}
				top += o.offsetTop;
				if (el.clientTop && el.nodeName!="TABLE") {
					top += el.clientTop;
				}
				o = el;
				if (o.offsetParent==null) {
					if (o.offsetLeft) {
						left += o.offsetLeft;
					}
					if (o.offsetTop) {
						top += o.offsetTop;
					}
				}
				offsetParent = o.offsetParent;
			}
		}
		
	
		if (originalObject.offsetWidth) {
			width = originalObject.offsetWidth;
		}
		if (originalObject.offsetHeight) {
			height = originalObject.offsetHeight;
		}
		
		return top;
	};
	
	
/*Rating*/
var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet= new Array; // Is the PreSet value onces a selection has been made
var rated= new Array;

// Rollover for image Stars //
function rating(num, idFeed){
	sMax = 10;	// Isthe maximum number of stars
	/*for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}*/
	
	if(!rated[idFeed]){
		var thisStarId=String(num.id);
		var toReplace=idFeed+"_";
		s = thisStarId.split('_'); // Get the selected star
		s=s[1];
		a = 0;
		
		for(i=1; i<=sMax; i++){		
			thisStar=String(idFeed+'_'+i);
			if(i<=s){
				document.getElementById(thisStar).className = "on";
				//document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				
				document.getElementById(thisStar).className = "";
				
			}
			thisStar='';
		}
	}
}

// For when you roll out of the the whole thing //
function off(me, idFeed, rank){
	if(!rated[idFeed]){
		if(!preSet[idFeed]){	
			if(rank!=0){
				for(i=1; i<=rank; i++){		
					document.getElementById(idFeed+"_"+i).className = "on";
					//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
				}
				for(i=(rank+1); i<=sMax; i++){
					document.getElementById(idFeed+"_"+i).className = "";
				}
			}
			else{
				for(i=1; i<=sMax; i++){		
					document.getElementById(idFeed+"_"+i).className = "";
					//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
				}
			}
		}else{
			rating(preSet[idFeed]);
			//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me, idFeed){
	if(!rated[idFeed]){
		//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		preSet[idFeed] = me;
		rated[idFeed]=1;
		sendRate(me, idFeed);
		rating(me, idFeed);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel, idFeed){
	document.getElementById('rating'+idFeed).value=sel;
}


function exportFeeds(feedsNum, invFeedsNum){
			var validFeeds='';
			var invalidFeeds='';
			for(var i=1; i<=feedsNum; i++){
				if(document.getElementById('feed'+i).checked==true){
					validFeeds+=document.getElementById('feed'+i).value+',';
				}
			}
			for(i=1; i<=invFeedsNum; i++){
				if(document.getElementById('invfeed'+i).checked==true){
					invalidFeeds+=document.getElementById('invfeed'+i).value+',';
				}
			}
			if(validFeeds!='' || invalidFeeds!=''){
				window.location='../exportopml.php?validfeeds='+validFeeds+'&invalidfeeds='+invalidFeeds;
			}
			else {
				alert('You should choose at least 1 feed to export');
			}
}
/*End Rating*/
//Function that delete imported feeds
 function delimportedfeeds(title,path){
	 var xmlHttp;
			try
		    {
		    // Firefox, Opera 8.0+, Safari
		    xmlHttp=new XMLHttpRequest();
		    }
		  catch (e)
		    {
		    // Internet Explorer
		    try
		      {
		      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		      }
		    catch (e)
		      {
		      try
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		      catch (e)
			{
			alert("Your browser does not support AJAX!");
			return false;
			}
		      }
		    }
		    xmlHttp.onreadystatechange=function()
		      {
		      if(xmlHttp.readyState==4)
			{	
				document.getElementById(title).style.display='none';
				document.getElementById('message').innerHTML='Feed Successfully Deleted';
			}
		    }
		    url="../delimportedfeed.php?title="+title+"&url="+path;
		    xmlHttp.open("GET",url,true);
		    xmlHttp.send(null);
 }
//end of delete imported feeds function
//function to delete photos
function delPhoto(id, photo, photoNum)
  {
	  if(confirm("Are You sure you want to delete this photo?"))
	  {	  
		  var xmlHttp;
		  try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
		  catch (e) // Internet Explorer
			{
			try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e)
			  {
			  try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			  catch (e)
				{
				return false;
				}
			  }
			}
			xmlHttp.onreadystatechange=function()
			  {
			  if(xmlHttp.readyState!=4)
				{
				document.getElementById('message').innerHTML="Processing... Please Wait";
				}
			  if(xmlHttp.readyState==4)
				{
				document.getElementById('photo'+photoNum).style.display = 'none';
				document.getElementById('message').innerHTML="Photo have been successfully removed";
				}
			  }
			xmlHttp.open("GET","../deletephoto.php?id="+id+"&photo="+photo,true);
			xmlHttp.send(null);
	  }
}
//end delete photo

function onlynum(eventObj, obj)
{
	var keyCode

	// Check For Browser Type
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}
	var str=obj
	if(keyCode!=0){
	if(keyCode!=8){
	if(keyCode==46){ 
			if (str.indexOf(".")>0){
				return false
			}
		}
		if((keyCode<48 || keyCode >58)   &&   (keyCode != 46)){ // Allow only integers and decimal points
			return false
		}
		}}
	return true
	}

	//function  forgot password
function forgotpass(){
	if(document.login.email.value==''){
		alert('Please Fill in your email');
		document.login.email.focus();
		return false;
	}
	if ((document.login.email.value.indexOf('@', 0) == -1) || (document.login.email.value.indexOf('.') == -1) || (document.login.email.value.indexOf(' ') != -1)){
		alert ("Please fill in a correct email" );    
		document.login.email.focus();
		return false;
	}
	else{
			var email=document.login.email.value;
	 		var xmlHttp;
		  try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
		  catch (e) // Internet Explorer
			{
			try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e)
			  {
			  try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			  catch (e)
				{
				return false;
				}
			  }
			}
			xmlHttp.onreadystatechange=function()
			  {
			  if(xmlHttp.readyState!=4)
				{
				document.getElementById('login-message').innerHTML="Processing... Please Wait";
				}
			  if(xmlHttp.readyState==4)
				{
				document.getElementById('login-message').innerHTML = xmlHttp.responseText;
				}
			  }
			xmlHttp.open("GET","http://www.pheed.me/forgotpass.php?email="+email,true);
			xmlHttp.send(null);
		}	
}
var bName = navigator.appName;
function taLimit(event ,taObj, maxL) {
	if (taObj.value.length>=maxL)
	{
		if(event.keyCode!=8) { return false; }
			else return true;
	}
	return true;
}
function taLimitcopy(taObj, maxL)
{
	if(taObj.value.length>maxL)
	{
		taObj.value = taObj.value.substring(0, maxL);
	}
}
function taCount(taObj,Cnt, maxL) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
	}
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}
function showSubcategories(idCat, cat){
    if(idCat==12){
        cat='Language';
    }
    var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
	{
        document.getElementById('subcatstitle').innerHTML=cat+' Subcategories';
		document.getElementById('subcatstitle').style.display='inline';
        document.getElementById("subcats").innerHTML=xmlHttp.responseText;
	}
    }
    url="getsubcatsdir.php?id="+idCat;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
 }
 function showSubcategories1(idCat, cat){
    if(idCat==12){
        cat='Language';
    }
    var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
	{
        document.getElementById('subcatstitle1').innerHTML=cat+' Subcategories';
		document.getElementById('subcatstitle1').style.display='inline';
        document.getElementById("subcats1").innerHTML=xmlHttp.responseText;
	}
    }
    url="getsubcatsdir1.php?id="+idCat;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
 }
 
 function checkResetPass(){
	if (document.changepass.newpassword.value==""){
		alert("Please enter your 'New password'")
		document.changepass.newpassword.focus();
		return false;
	}
	
	if (document.changepass.newpassword.value.length<6){
		alert("Password should be more than 6 Charachters")
		document.changepass.newpassword.focus();
		return false;
	}
	
	if(document.changepass.confpassword.value==""){
 		alert("Please confirm your 'New password'");
 		document.changepass.confpassword.focus();
 		return false;
 	}
	
	if(document.changepass.newpassword.value != document.changepass.confpassword.value){
 		alert("New password and confirmation are not the same!");
 		document.changepass.newpassword.focus();
 		return false;
 	}
 }
  function getAnswers(id){
		if(id==""){
                    document.getElementById("answers").innerHTML="";
                }
                else {
                 var xmlHttp=createAjax();
		    xmlHttp.onreadystatechange=function()
		      {
		      if(xmlHttp.readyState==4)
			{
                document.getElementById("answers").innerHTML=xmlHttp.responseText;
			}
		    }
		    url="../getanswers.php?id="+id;
		    xmlHttp.open("GET",url,true);
		    xmlHttp.send(null);}
}
//End of getSubCats
//function change navbar class
function changeClass(page, action){
	if(action=='over')
	{
		document.getElementById('line'+page).className='navbarin_line';
	}
	else if(action=='out')
	{
		document.getElementById('line'+page).className='';
	}
}

function addSwearWord(swearWord, lastFilledCol){
    var xmlHttp=createAjax();
    var inserted=0;
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
    {
        if(xmlHttp.responseText!=0){
            for(var j=1; j<6; j++){
                if(document.getElementById('emptycol'+j) && document.getElementById('emptycol'+j).innerHTML==''){
                    document.getElementById('emptycol'+j).innerHTML='<input type="checkbox" value="'+xmlHttp.responseText+'" checked name="'+j+'" />'+swearWord;
                    j=6;
                    inserted=1;
                    if(document.getElementById('addedsw').value==''){
                       document.getElementById('addedsw').value=xmlHttp.responseText;
                    }
                    else {
                      document.getElementById('addedsw').value=document.getElementById('addedsw').value+','+xmlHttp.responseText;
                    }
                }
            }
        }
        else {
            document.getElementById('addmsg').innerHTML='Swear Word Already exists';
        }
        if(inserted==0){
            document.getElementById('addedsw').value=document.getElementById('addedsw').value+','+xmlHttp.responseText;
            getGlobalFilter(document.getElementById('addedsw').value);
        }
    }
    }
    url="../addswearword.php?swearword="+swearWord;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function showSwearWordStuff(){
     document.getElementById('addwordform').style.display='inline';
     document.getElementById('swearwordaddmsg').style.display='inline';
     document.getElementById('swearwordsep').style.display='inline';
     document.getElementById('swearwordstable').style.display='inline';
     return;
}
function hideSwearWordStuff(){
     document.getElementById('addwordform').style.display='none';
     document.getElementById('swearwordaddmsg').style.display='none';
     document.getElementById('swearwordsep').style.display='none';
     document.getElementById('swearwordstable').style.display='none';
     return;
}


function changePage1(page){
	document.getElementById('page'+page).style.display='inline';
    if(page!=1 && page!=4){
        document.getElementById('subpage'+page).style.display='inline';
    }
	//$("tr#page"+page).slideDown("slow");
	//$("tr#subpage"+page).slideDown("slow");
	for(var i=1; i<=4; i++)
	{
		if(i!=page)
		{
			document.getElementById('page'+i).style.display='none';
			if(i!=4){
				document.getElementById('subpage'+i).style.display='none';
			}
			//if ($("tr#page"+i).is(":hidden")) {
			//} else {
			//	$("tr#page"+i).slideUp("slow");
			//	$("tr#subpage"+i).slideUp("slow");
			//}

		}
	}
	if(page!=1)
		{
			document.getElementById('borderleft').className='';
		}
		else
		{
			document.getElementById('borderleft').className='greyborder';
		}

	if(page==1)
	{
		document.getElementById('fullmenucol1').innerHTML='<table cellpadding="0" id="fullmenu1"  cellspacing="0" onclick="return changePage1(1);"><tr><td width="5" height="37" id="l1" class="navbarleft"></td><td width="53" id="c1" class="navbarbg">Search</td><td width="5" id="r1" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol2').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu2" onclick="return changePage1(2);"><td id="l2" class="navbarleftout"></td><td width="136" id="c2" class="navbarbgout">Pheed Categories</td><td id="r2" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol3').innerHTML='<table cellpadding="0" id="fullmenu3" cellspacing="0" onclick="return changePage1(3);"><tr><td id="l3" class="navbarleftout"></td><td width="125" id="c3" class="navbarbgout">Feed Categories</td><td id="r3" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol4').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu4" onclick="return changePage1(4);"><td id="l4" class="navbarleftout"></td><td width="110" id="c4" class="navbarbgout">Image Search</td><td id="r4" class="navbarrightout"></td></tr></table>';
		document.getElementById('line1').className='navbarin_line';
		document.getElementById('line2').className='navbar_lineout';
		document.getElementById('line3').className='navbar_lineout';
		document.getElementById('line4').className='navbar_lineout';
	}
	if(page==2)
	{
		document.getElementById('fullmenucol2').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu2" onclick="return changePage1(2);"><td id="l2" class="navbarleft"></td><td width="136" id="c2" class="navbarbg">Pheed Categories</td><td id="r2" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol1').innerHTML='<table cellpadding="0" id="fullmenu1"  cellspacing="0" onclick="return changePage1(1);"><tr><td width="5" height="37" id="l1" class="navbarleftout"></td><td width="53" id="c1" class="navbarbgout">Search</td><td width="5" id="r1" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol3').innerHTML='<table cellpadding="0" id="fullmenu3" cellspacing="0" onclick="return changePage1(3);"><tr><td id="l3" class="navbarleftout"></td><td width="125" id="c3" class="navbarbgout">Feed Categories</td><td id="r3" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol4').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu4" onclick="return changePage1(4);"><td id="l4" class="navbarleftout"></td><td width="110" id="c4" class="navbarbgout">Image Search</td><td id="r4" class="navbarrightout"></td></tr></table>';
		document.getElementById('line2').className='navbarin_line';
		document.getElementById('line1').className='navbar_lineout';
		document.getElementById('line3').className='navbar_lineout';
		document.getElementById('line4').className='navbar_lineout';
	}
	if(page==3)
	{
		document.getElementById('fullmenucol3').innerHTML='<table cellpadding="0" id="fullmenu3" cellspacing="0" onclick="return changePage1(3);"><tr><td id="l3" class="navbarleft"></td><td width="125" id="c3" class="navbarbg">Feed Categories</td><td id="r3" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol1').innerHTML='<table cellpadding="0" id="fullmenu1"  cellspacing="0" onclick="return changePage1(1);"><tr><td width="5" height="37" id="l1" class="navbarleftout"></td><td width="53" id="c1" class="navbarbgout">Search</td><td width="5" id="r1" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol2').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu2" onclick="return changePage1(2);"><td id="l2" class="navbarleftout"></td><td width="136" id="c2" class="navbarbgout">Pheed Categories</td><td id="r2" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol4').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu4" onclick="return changePage1(4);"><td id="l4" class="navbarleftout"></td><td width="110" id="c4" class="navbarbgout">Image Search</td><td id="r4" class="navbarrightout"></td></tr></table>';
		document.getElementById('line3').className='navbarin_line';
		document.getElementById('line1').className='navbar_lineout';
		document.getElementById('line2').className='navbar_lineout';
		document.getElementById('line4').className='navbar_lineout';
	}
	if(page==4)
	{
		document.getElementById('fullmenucol4').innerHTML='<table cellpadding="0" id="fullmenu4" cellspacing="0" onclick="return changePage1(4);"><tr><td id="l4" class="navbarleft"></td><td width="110" id="c4" class="navbarbg">Image Search</td><td id="r4" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol1').innerHTML='<table cellpadding="0" id="fullmenu1"  cellspacing="0" onclick="return changePage1(1);"><tr><td width="5" height="37" id="l1" class="navbarleftout"></td><td width="53" id="c1" class="navbarbgout">Search</td><td width="5" id="r1" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol2').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu2" onclick="return changePage1(2);"><td id="l2" class="navbarleftout"></td><td width="136" id="c2" class="navbarbgout">Pheed Categories</td><td id="r2" class="navbarrightout"></td></tr></table>';
		document.getElementById('fullmenucol3').innerHTML='<table cellpadding="0" id="fullmenu3" cellspacing="0" onclick="return changePage1(3);"><tr><td id="l3" class="navbarleftout"></td><td width="125" id="c3" class="navbarbgout">Feed Categories</td><td id="r3" class="navbarrightout"></td></tr></table>';
		document.getElementById('line4').className='navbarin_line';
		document.getElementById('line1').className='navbar_lineout';
		document.getElementById('line2').className='navbar_lineout';
		document.getElementById('line3').className='navbar_lineout';
	}
}



function changePage(page){
	document.getElementById('page'+page).style.display='inline';
    if(page!=1){
        document.getElementById('subpage'+page).style.display='inline';
    }
	//$("tr#page"+page).slideDown("slow");
	//$("tr#subpage"+page).slideDown("slow");
	for(var i=1; i<=3; i++)
	{
		if(i!=page)
		{
			document.getElementById('page'+i).style.display='none';
			document.getElementById('subpage'+i).style.display='none';
			//if ($("tr#page"+i).is(":hidden")) {
			//} else {
			//	$("tr#page"+i).slideUp("slow");
			//	$("tr#subpage"+i).slideUp("slow");
			//}
			
		}
	}
	if(page!=1)
		{
			document.getElementById('borderleft').className='';
		}
		else
		{
			document.getElementById('borderleft').className='greyborder';
		}
	
	if(page==1)
	{
		document.getElementById('fullmenucol1').innerHTML='<table cellpadding="0" id="fullmenu1"  cellspacing="0" onclick="return changePage(1);"><tr><td width="5" height="37" id="l1" class="navbarleft"></td><td width="53" id="c1" class="navbarbg">Search</td><td width="5" id="r1" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol2').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu2" onclick="return changePage(2);" onmouseover="return changeClass(\'2\', \'over\')" onmouseout="return changeClass(\'2\', \'out\')"><td id="l2" class="navbarleft"></td><td width="136" id="c2" class="navbarbg">Pheed Categories</td><td id="r2" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol3').innerHTML='<table cellpadding="0" id="fullmenu3" cellspacing="0" onclick="return changePage(3);" onmouseover="return changeClass(\'3\', \'over\')" onmouseout="return changeClass(\'3\', \'out\')"><tr><td id="l3" class="navbarleft"></td><td width="125" id="c3" class="navbarbg">Feed Categories</td><td id="r3" class="navbarright"></td></tr></table>';
		document.getElementById('line1').className='navbarin_line';
		document.getElementById('line2').className='';
		document.getElementById('line3').className='';
	}
	if(page==2)
	{
		document.getElementById('fullmenucol2').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu2" onclick="return changePage(2);"><td id="l2" class="navbarleft"></td><td width="136" id="c2" class="navbarbg">Pheed Categories</td><td id="r2" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol1').innerHTML='<table cellpadding="0" id="fullmenu1"  cellspacing="0" onclick="return changePage(1);" onmouseover="return changeClass(\'1\', \'over\')" onmouseout="return changeClass(\'1\', \'out\')"><tr><td width="5" height="37" id="l1" class="navbarleft"></td><td width="53" id="c1" class="navbarbg">Search</td><td width="5" id="r1" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol3').innerHTML='<table cellpadding="0" id="fullmenu3" cellspacing="0" onclick="return changePage(3);" onmouseover="return changeClass(\'3\', \'over\')" onmouseout="return changeClass(\'3\', \'out\')"><tr><td id="l3" class="navbarleft"></td><td width="125" id="c3" class="navbarbg">Feed Categories</td><td id="r3" class="navbarright"></td></tr></table>';
		document.getElementById('line2').className='navbarin_line';
		document.getElementById('line1').className='';
		document.getElementById('line3').className='';
	}
	if(page==3)
	{
		document.getElementById('fullmenucol3').innerHTML='<table cellpadding="0" id="fullmenu3" cellspacing="0" onclick="return changePage(3);"><tr><td id="l3" class="navbarleft"></td><td width="125" id="c3" class="navbarbg">Feed Categories</td><td id="r3" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol1').innerHTML='<table cellpadding="0" id="fullmenu1"  cellspacing="0" onclick="return changePage(1);" onmouseover="return changeClass(\'1\', \'over\')" onmouseout="return changeClass(\'1\', \'out\')"><tr><td width="5" height="37" id="l1" class="navbarleft"></td><td width="53" id="c1" class="navbarbg">Search</td><td width="5" id="r1" class="navbarright"></td></tr></table>';
		document.getElementById('fullmenucol2').innerHTML='<table cellpadding="0" cellspacing="0" id="fullmenu2" onclick="return changePage(2);" onmouseover="return changeClass(\'2\', \'over\')" onmouseout="return changeClass(\'2\', \'out\')"><td id="l2" class="navbarleft"></td><td width="136" id="c2" class="navbarbg">Pheed Categories</td><td id="r2" class="navbarright"></td></tr></table>';
		document.getElementById('line3').className='navbarin_line';
		document.getElementById('line1').className='';
		document.getElementById('line2').className='';
	}
}
function showhideDates(theCheckBox) {
	if(theCheckBox.checked==true)
	{ 
		document.getElementById('dates').style.display='inline';
	 	document.getElementById('postagepresets').style.display='inline';
	 	document.getElementById('agesettingtobechecked').checked=true;
	} 
	else if(theCheckBox.checked==false)
	{ 
		document.getElementById('dates').style.display='none'; 
		document.getElementById('postagepresets').style.display='none'; 
		document.getElementById('postagedaterange').style.display='none';
	}
}
function getWidgetToGive(showSwStuff){
    if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;
        if(showSwStuff!=''){
            showSwearWordStuff();
            var showSwStuffArr=showSwStuff.split(',');
            for(var i=0; i<document.editglobals.elements.length; i++){
                for(var j=0; j<showSwStuffArr.length; j++){
                    if(document.editglobals.elements[i].value==showSwStuffArr[j]){
                        document.editglobals.elements[i].checked=true;
                    }
                }
            }
            document.editglobals.addedsw.value=showSwStuff;
        }
	}
    }
    url="../widgetgive.php";
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function getWidgetToGive1(showSwStuff, widget){
    if(storedContent=='')
    {
        storedContent=document.getElementById('feeds').innerHTML;
    }
	var xmlHttp=createAjax();
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState!=4){
      	document.getElementById('feeds').innerHTML='<span class="feed-message">Processing Please Wait...</span>';
      }
      if(xmlHttp.readyState==4)
	{
		document.getElementById('feeds').innerHTML=xmlHttp.responseText;
        if(showSwStuff!=''){
            showSwearWordStuff();
            var showSwStuffArr=showSwStuff.split(',');
            for(var i=0; i<document.editglobals.elements.length; i++){
                for(var j=0; j<showSwStuffArr.length; j++){
                    if(document.editglobals.elements[i].value==showSwStuffArr[j]){
                        document.editglobals.elements[i].checked=true;
                    }
                }
            }
            document.editglobals.addedsw.value=showSwStuff;
        }
	}
    }
    url="../widgetgive.php?widget="+widget;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
