if (navigator.appName=='Microsoft Internet Explorer') 

	document.write("<link href='IEStyle.css' rel='stylesheet' type='text/css' />"); 

else 

	document.write("<link href='FFStyle.css' rel='stylesheet' type='text/css' />");



function GetXmlHttpObject()

{

  var xmlHttp=null;

  try

    {

    // Firefox, Opera 8.0+, Safari

    xmlHttp=new XMLHttpRequest();

    }

  catch (e)

    {

    // Internet Explorer

    try

      {

      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

      }

    catch (e)

      {

      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

      }

    }

  return xmlHttp;

}



function onevent(me,task,color,decoration) {

	if(task=='over') {

		me.style.cursor = 'pointer';

		me.style.color = color;

		if(decoration=='underline') {

			me.style.textDecoration = 'underline'; 

		}

	} else {

		me.style.cursor = 'pointer';

		me.style.color = color;

		if(decoration=='none') {

			me.style.textDecoration = 'none';  

		}

	}

}



/********************ourstories****************************/

function selected(data,todo) { 

	xmlHttp=GetXmlHttpObject(); //alert(todo+'::'+data); //return;

	if(todo=='userinfo' && data=='') { //alert(todo+'::'+data);

		window.location = 'user.php';

		return;

	} 

	if (xmlHttp==null) {

		alert ("Your browser does not support AJAX!");

		return;

	}

	var url="mainfunction.php?todo="+todo+"&data="+data+"&sid="+Math.random(); 

	if(todo=='showallpost') {

		xmlHttp.onreadystatechange=stateChangedshowallpost;

	} else if(todo=='showpost') {

		xmlHttp.onreadystatechange=stateChangedshowpost;

	} else if(todo=='showownerpost') {

		xmlHttp.onreadystatechange=stateChangedshowownerpost; 

	} else if(todo=='vote') { 

		xmlHttp.onreadystatechange=stateChangedvote;

	} else if(todo=='thispost' || todo=='dash') { 

		xmlHttp.onreadystatechange=stateChangedthispost;

	} else if(todo=='userinfo') { //alert(todo+'::'+data);

		xmlHttp.onreadystatechange=stateChangeduserinfo;

	} else if(todo=='showlistphoto') { 

		xmlHttp.onreadystatechange=stateChangedshowlistphoto;

	} else if(todo=='delpost') {

		var answer=confirm('Are you sure you want to delete this post?');

		if(answer) {

			xmlHttp.onreadystatechange=stateChangeddelpost;

		} else { 

			return; 

		}

	} else if(todo=='editpost') { 

		xmlHttp.onreadystatechange=stateChangededitpost;

	} else if(todo=='submitpost') {  

		xmlHttp.onreadystatechange=stateChangedsubmitpost;

	} else if(todo=='showallpostindex') {  

		xmlHttp.onreadystatechange=stateChangedshowallpostindex;

	}  else if(todo=='profiledash') { 

		xmlHttp.onreadystatechange=stateChangedprofiledash;

	}

	xmlHttp.open("POST",url,true);

	xmlHttp.send(null);	

}



function stateChangedprofiledash() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	 

			if(retval!="false") { 

				window.location = 'user.php';

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedshowallpostindex() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") { 

				document.getElementById('showallpostindex').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedsubmitpost() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText;  	 

			if(retval=="false") {  

				window.location = 'notifydraft.php';

			} else { 

				alert("Thank you for submitting an article.\n"+

					  "It has now been added to our queue.\n\nWe will send "+

					  "you an email if your article \nhas been posted.");

				document.getElementById('drafts').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangededitpost() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval=="true") {

				window.location = 'newpost.php?';

			} else {

				alert('Unable to process. Try again later.');

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangeddelpost() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval=="false") {

				alert('Unable to delete. Try again later.');

			} else {

				alert('Post successfully deleted.');

				document.getElementById('drafts').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedshowlistphoto() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				document.getElementById('showlistphoto').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangeduserinfo() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				window.location = 'user.php';

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedthispost() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				window.location = 'post.php';

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedvote() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				window.location = 'vote.php';

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedshowownerpost() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				document.getElementById('showownerpost').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedshowallpost() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				document.getElementById('showallpost').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedshowpost() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				window.location="post.php";

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



/**************************finalconfirmation*********************************/

function confirmation(terms,consent, yob, curryear){
  if(terms.checked!==true) {
    alert("You must read and agree with the terms and condition.");
    terms.select();
    terms.focus();
    return false;
  } 

 /* if(!consent.checked && (curryear-yob.value<18) ) {
	//check first if above 18 (consent.checked!==true)
		alert("You must have your parents' or guardian's consent before you can register.");
		consent.select();
		consent.focus();
		return false;
  }*/
  return true;
}



function confirmterms(terms){

  if(terms.checked!==true) {
    alert("You must read and agree with the terms and condition.");
    terms.select();
    terms.focus();
    return false;
  } 

  if (document.getElementById('title').value=='') { 
		alert('Oops! You forgot the title of your story.'); 
		document.getElementById('title').focus();
		return false;
	}
	/*
	if(document.getElementById('uploadpic').value ==''){
		alert('A picture of your story is mandatory.');	
		return false;
	}*/
}



/*************************sortby****************************/

function sortby(what) {
	xmlHttp=GetXmlHttpObject(); //alert(data); //return;
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="mainfunction.php?todo=sort&data="+what+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedsortby;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);		
}


function stateChangedsortby() {
	if (xmlHttp.readyState==4) {
		if(xmlHttp.status==200) { 
			var retval = xmlHttp.responseText; 	
			if(retval!="false") {
				document.getElementById('showallpost').innerHTML = retval;
			}
		} else {
			alert("Unable to process. Try again later.");
		}
	} 		
}

/***********************newwindowpopuppic******************************/
var windowtitle="Image Window"  //pop window title


function detectexist(obj){
	return (typeof obj !="undefined")
}


function popimage(imgpath, popwidth, popheight, textdescription){
		popheight = popheight+50;

		function getpos(){

		leftpos=(detectexist(window.screenLeft))? document.documentElement.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0

		toppos=(detectexist(window.screenTop))? document.documentElement.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0

			if (window.opera){

				leftpos-=screenLeft;

				toppos-=screenTop;

				}

		}

		getpos();

		var winattributes='width='+popwidth+',height='+popheight+',scrollbars=yes,resizable=yes,left='+leftpos+',top='+toppos;

	

		if (typeof popwin=="undefined" || popwin.closed) {

				popwin=window.open("","",winattributes)

		} else	{

			popheight = popheight+50;

			//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too

			//popwin.moveTo(leftpos, toppos)

			popwin.resizeTo(popwidth, popheight);

		}

		popwin.document.open();

		popwin.document.write('<html><head><title>'+windowtitle+'</title><style type="text/css">body {	margin:0 0 0 0; }</style></head><body><div><img src="'+imgpath+'"><br><br><span  style="padding-left:30px;font:normal 14px verdana;">'+textdescription+'<br><br><br></span></div></body></html>');

		popwin.document.close();

		popwin.focus();

}



/**************************forimageviewer***********************************/

//dimmer

function dimScreen(spanid) {

	var sH = document.body.scrollHeight

	var cH = document.documentElement.scrollHeight

	if(sH < cH) document.getElementById(spanid).style.height = cH+"px";

	else document.getElementById(spanid).style.height = sH+"px";

	

	var sW = document.body.scrollWidth;

	document.getElementById(spanid).style.width = sW+"px";

	document.getElementById(spanid).style.visibility = "visible";

}



var isMozilla;

var objDiv = null;

var DivID='';

var over = false;

var browser = navigator.appName;

function MouseDown(e) 

{

    if (over)

    {

        if (isMozilla) {

            objDiv = document.getElementById(DivID);

            X = e.layerX;

            Y = e.layerY;

            return false;

        }

        else {

            objDiv = document.getElementById(DivID);

            objDiv = objDiv.style;

            X = event.offsetX;

            Y = document.body.scrollTop; //event.offsetX;

        }

    }

}



function MouseMove(e) {

    if (objDiv) {

        if (isMozilla) {

            objDiv.style.top = (e.pageY-Y) + 'px';

            objDiv.style.left = (e.pageX-X) + 'px';

            return false;

        } else {	

			objDiv.pixelLeft = event.clientX-X + document.body.scrollLeft-12;

			objDiv.pixelTop = event.clientY-Y + document.body.scrollTop + getTop()-12;

            return false;

        }

    }

}



function MouseUp() {

    objDiv = null;

}



function init(idvId) {

	DivID=idvId;

    // check browser

    isMozilla = (document.all) ? 0 : 1;

    if (isMozilla) {

        document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);

    }

    document.onmousedown = MouseDown;

    document.onmousemove = MouseMove;

    document.onmouseup = MouseUp;

}



function getTop() { 

	var scrXY = new Array();

	var displacedH;

	scrXY = getScrollXY();

	if(browser=='Microsoft Internet Explorer') {

		if (document.documentElement && document.documentElement.clientHeight)

			browserheight = document.documentElement.clientHeight;

		else if (document.body)

			browserheight = document.body.clientHeight

		displacedH = scrXY[1]; 

	}

	else if(browser=='Netscape') {

			displacedH = scrXY[1]; //document.body.scrollTop; 

	}

	else if(browser=='Opera') {

		var browserheight = document.body.clientHeight;

		displacedH = scrXY[1]; 

	}

	return displacedH;

}

 

function getScrollXY() {

  var scrOfX = 0, scrOfY = 0;

  if( typeof( window.pageYOffset ) == 'number' ) {

    //Netscape compliant

    scrOfY = window.pageYOffset; 

    scrOfX = window.pageXOffset;

  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {

    //DOM compliant

    scrOfY = document.body.scrollTop; 

    scrOfX = document.body.scrollLeft;

  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {

    //IE6 standards compliant mode

    scrOfY = document.documentElement.scrollTop; 

    scrOfX = document.documentElement.scrollLeft;

  }

// return [ scrOfX, scrOfY ];

 var scr = new Array(scrOfX,scrOfY);

 return scr;

} 



function closeImageViewer(viewerID,dimmerID) {

	document.getElementById(viewerID).style.visibility='hidden';

	document.getElementById(dimmerID).style.visibility='hidden';

}



function goDim(srcimage,imgWidth,imgHeight,viewerID,dimmerID) {

	dimScreen(dimmerID);

	init(viewerID);

		

	var posY = getTop(); 

	var posX = (document.body.clientWidth/2) - (imgWidth/2);

	document.getElementById('image').innerHTML = '<img src="'+srcimage+'" width="'+imgWidth+'" height="'+imgHeight+'">';

	document.getElementById(viewerID).style.top=posY+'px';

	document.getElementById(viewerID).style.left=posX+'px';  

	document.getElementById(viewerID).style.visibility='visible'

}





function goDim2(viewerID,dimmerID) {

	dimScreen(dimmerID);

	init(viewerID);

		

	var posY = getTop(); 

	var posX = (document.body.clientWidth/2) - (200/2);

	//document.getElementById('image').innerHTML = filetext;

	document.getElementById(viewerID).style.top=posY+'px';

	document.getElementById(viewerID).style.left=posX+'px';  

	document.getElementById(viewerID).style.visibility='visible'

}





/**************************adminstuff***********************************/

function whattodo(id,todo,title) {

	xmlHttp=GetXmlHttpObject(); //alert(todo); //return;

	if (xmlHttp==null) {

		alert ("Your browser does not support AJAX!");

		return;

	}

	var url="adminfunc.php?todo="+todo+"&data="+id+"&title="+title+"&sid="+Math.random();

	if(todo=='deletead') {

		var answer=confirm('Are you sure you want to delete this post?\n"'+title+'"');

		if(answer) {

			xmlHttp.onreadystatechange=stateChangedshowreslistdelapp;

		} else { 

			return; 

		}

	} else if(todo=='approvedad') {

		xmlHttp.onreadystatechange=stateChangedshowreslistdelapp;

	} else if(todo=='disapprovedad') { 

		var x = prompt("Please enter reason for disapproving", "");

		if (x=='' || x==null) { alert("You must enter your reason for disapproving"); return false;}

		url += "&disappreason="+x;

		xmlHttp.onreadystatechange=stateChangedshowreslistdelapp;

	} else if(todo=='viewad') { 

		xmlHttp.onreadystatechange=stateChangedviewres;

	} else if(todo=='back') { 

		xmlHttp.onreadystatechange=stateChangedviewres;

	} else if(todo=='in' || todo=='out') {

		xmlHttp.onreadystatechange=stateChangedinoutad;

	}  else if(todo=='initialapproval' || todo=='finalapproval') {  

		xmlHttp.onreadystatechange=stateChangedshowreslistdelapp;

	} 

	xmlHttp.open("POST",url,true);

	xmlHttp.send(null);	

	//alert(url);

}



function stateChangedinoutad() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	//alert(retval);

			if(retval!="false") {

				document.getElementById('featlist').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedviewres() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	//alert(retval);

			if(retval!="false") {

				document.getElementById('showreslist').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}



function stateChangedshowreslistdelapp() {

	if (xmlHttp.readyState==4) {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				document.getElementById('showreslist').innerHTML = retval;

			}

		} else {

			alert("Unable to process. Try again later.");

		}

	} 		

}

var postlimit_ok = false;

var sislookup_ok = false;

var uploadpic_ok = false;



function sislookup(thisuniquekey, selfkey){ 

	xmlHttp=GetXmlHttpObject(); //alert(todo); //return;

	if (xmlHttp==null) {

		alert ("Your browser does not support AJAX!");

		return false;

	}

	if (thisuniquekey==selfkey) { 

		alert('You cannot be your own SisterInInk.\nPlease try again'); 

		document.getElementById('uidflag').disabled=true; 

		document.getElementById('sisuniquekey').value='';

		document.getElementById('sisuniquekey').focus();

		return;

	}

	

	if (thisuniquekey=='') { 

		alert('Please provide your Sister\'s unique PIN code.\nOtherwise, you may save your post as draft.\nPlease try again'); 

		document.getElementById('sisuniquekey').value='';

		document.getElementById('sisuniquekey').focus();

		return;

	}

	

	

	var url="sislookup.php";

	var keyvalue = "sisuniquekey="+thisuniquekey;

	xmlHttp.onreadystatechange=stateChangedShowSisLookup;

	xmlHttp.open("POST",url,true);

	//alert(methods);

	//xmlhttp.setRequestHeader('X-Referer', document.location);

    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

    xmlHttp.setRequestHeader("Content-Length", keyvalue.length);

    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.send(keyvalue);

	xmlHttp.send(keyvalue+"&"+Math.random());	

}



function stateChangedShowSisLookup(){ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete') {

		if(xmlHttp.status==200) { 

			var retval = xmlHttp.responseText; 	

			if(retval!="false") {

				document.getElementById('verifysis').innerHTML = retval;



				if (retval.indexOf("not able to look up")!=-1) { 

					sislookup_ok = false; document.getElementById('uidflag').disabled = true;  return false; 

				}

				//check enabler if false

				sislookup_ok = true;

				checkenabler();

				return true;

			}

		} else {

			alert("Unable to process. Please try again.");

			document.getElementByid('verifysis').focus();

			return false;

		}

	} else { 

	document.getElementById('verifysis').innerHTML = 'verifying records... please wait...'; }

}



function limitchars(thistxtarea){ 

	var numofchars = thistxtarea.value.length;

	var errlimit = "";



	if (numofchars>=5000) {

			thistxtarea.value = thistxtarea.value.substring(0, 5000);

			postlimit_ok = true;

			try { document.getElementById('savedraft').disabled = false;}  catch (e) {}

			

	} else if (numofchars<=1500) {

			errlimit = " : minimum is 1500 and maximum char is 5000";

			postlimit_ok = false;

			/*try{ 

				document.getElementById('uidflag').disabled = true;

			} catch(e) {}*/

			

			try { 

				document.getElementById('savedraft').disabled = true;

			} catch (e) {}

	} else { 

		errlimit = ""; postlimit_ok = true;

		try{document.getElementById('savedraft').disabled = false;} catch(e){}

	}

	document.getElementById('showchars').value = numofchars + errlimit;

	return;

}







function checkenabler(){ //alert('sis: '+sislookup_ok + '  post: '+postlimit_ok);

	if (sislookup_ok && postlimit_ok && uploadpic_ok) document.getElementById('uidflag').disabled = false;

	else document.getElementById('uidflag').disabled = true;

	return;

}



function checkuploadpic(thisobj){

	//alert(thisobj.value);	

	if (thisobj.value!='') {

		var uploadfileArr = thisobj.value.split("\\");	

		var letindex = uploadfileArr.length;

		var checkbasefile = uploadfileArr[letindex-1];

		var matchreg = checkbasefile.match(/^[a-zA-Z0-9-_\.]+\.(jpg|JPG|gif|GIF|bmp|BMP)$/);

		if (matchreg){

			uploadpic_ok = true;

		

		}

		else { uploadpic_ok = false; alert('Only jpeg, gif, bmp images are allowed.\n\nFilenames with spaces are not allowed.\nThis field is mandatory.'); }

		

	} else uploadpic_ok = false;

	checkenabler();

}

function checkenterkey(event){
	if(event.keyCode==13) {
		document.getElementById('content').value += '<br><br>';
	}
	return;
}

