function without(){
	if(document.submitAlone.url.disabled == true){
		document.submitAlone.url.disabled = false;
		document.submitAlone.url.value = 'http://';
	}
	else if(document.submitAlone.url.disabled == false){
		document.submitAlone.url.disabled = true;
		document.submitAlone.url.value = 'NO URL';
	}
}

function submitAloneSubmit(form){
	var errMsg = "";
	var urlValue = trimStr(form.url.value);
	if(urlValue.indexOf('http://') != 0 && urlValue !='NO URL'){
	errMsg += "Please check the URL, It should contain http://\n";
	}

	if(trimStr(form.url.value)=='http://' || trimStr(form.url.value)==''){
	errMsg += "lol, Check the URL\n";	
	}	

	if(errMsg == '')
	{
		if(form.nolinkcheck.checked){
		form.url.disabled = false;
		form.url.value = 'NO URL';
		}
		form.submit();
	}
	else
	{
	alert(errMsg);	
	form.url.focus();	
	}
}

function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
}      

function ajaxRequest()
{
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}

function ajaxget(){
var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function(){
 if (mygetrequest.readyState==4){
  if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
   document.getElementById("keysList").value += mygetrequest.responseText
		if(document.getElementById("keysList").value.length >=299)
		{
			document.getElementById("keysList").value = document.getElementById("keysList").value.substring(0,499)
		}
  }
  else{
   alert("An error has occured making the request1")
  }
 }
}
var keyvalue=encodeURIComponent(document.getElementById("keyword").value)
mygetrequest.open("GET", "/trends.php?keyword="+keyvalue, true)
mygetrequest.send(null)
}

function formLogout(){
  document.logoutForm.submit();
}

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function trimStr(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

function submitOneImage(category,imglink,title,text)
{
	var categorySel = valButton(category);
	var imageSel = valButton(imglink);
	var titleTyped = trimStr(title);
	var textTyped = trimStr(text);
	var errorMsg = "";
	
	if (categorySel == null)
		{
			errorMsg += "Please select a CATEGORY\n";	
		}
	if (imageSel == null)
		{
			errorMsg += "Please select an IMAGE\n";	
		}
	
	if (titleTyped == '' || titleTyped == null)
		{
			errorMsg += "Please Enter the TITLE\n";
		}		
	if (textTyped == '' || textTyped == null)
		{
			errorMsg += "Please enter the DESCRIPTION\n";
		}
	if(titleTyped != '' && titleTyped.length < 20)
		{
			errorMsg += "Please enter atleast 20 charachters in the TITLE\n";
		}
	if(textTyped != '' && textTyped.length < 100)
		{
			errorMsg += "Please enter the some more DESCRIPTION (100 charachters atleast)\n";
		}
		
	if (errorMsg != '') 
		{
			alert(errorMsg);
		}
	else{
		document.formURL.submit();
		}
		
}

function submitOne(category,title,text)
{
	var categorySel_1 = valButton(category);
	var titleTyped_1 = trimStr(title);
	var textTyped_1 = trimStr(text);
	var errorMsg_1 = "";
	
	if (categorySel_1 == null)
		{
			errorMsg_1 += "Please select a CATEGORY\n";	
		}
	if (titleTyped_1 == '' || titleTyped_1 == null)
		{
			errorMsg_1 += "Please Enter the TITLE\n";
		}		
	if (textTyped_1 == '' || textTyped_1 == null)
		{
			errorMsg_1 += "Please enter the DESCRIPTION\n";
		}
	if(titleTyped_1 != '' && titleTyped_1.length < 20)
		{
			errorMsg_1 += "Please enter atleast 20 charachters in the TITLE\n";
		}
	if(textTyped_1 != '' && textTyped_1.length < 100)
		{
			errorMsg_1 += "Please enter the some more DESCRIPTION (100 charachters atleast)\n";
		}
		
	if (errorMsg_1 != '') 
		{
			alert(errorMsg_1);
		}
	else{
		document.formURL.submit();
		}
		
}

function checkTags(tags)
{
	var tagsTyped = trimStr(tags);
	var errorMsg_tags = "";
	if(tagsTyped == '')
		{
			errorMsg_tags += "Please enter a comma seperated list of TAGS\n";
		}
	if (errorMsg_tags != '') 
	{
		alert(errorMsg_tags);
	}
	else
	{
		document.submitFinal.submit();
	}	
}

function ajaxgetadmin(action, id, lik, user){
var mygetrequestadmin=new ajaxRequest()
mygetrequestadmin.onreadystatechange=function(){
 if (mygetrequestadmin.readyState==4){
  if (mygetrequestadmin.status==200 || window.location.href.indexOf("http")==-1){
	//document.getElementById("adminMessage").innerHTML = mygetrequestadmin.responseText
	document.adminForm.adminSelect.value='nothing'
  }
  else{
   alert("An error has occured making the request2")
  }
 }
}

var adminAction=action
var actionId=id
var actionLink = encodeURIComponent(lik)
var actionUser = user

mygetrequestadmin.open("GET", "/doAdmin.php?action="+adminAction+"&id="+actionId+"&user="+actionUser+"&link="+actionLink, true)
mygetrequestadmin.send(null)
}

function doAdmin(form, id, linkn, user)
{
	if(form.adminSelect.value != 'nothing')
	{
		if(confirm ("Are you sure ?"))
		{
			ajaxgetadmin(form.adminSelect.value, id, linkn, user)
		}
	}	
}

function addLinkToId(id,title,link, user){
var disableBut = 'document.addAltLinks.altLinkAdder'+id
var mygetrequestlink=new ajaxRequest()
mygetrequestlink.onreadystatechange=function(){
 if (mygetrequestlink.readyState==4){
  if (mygetrequestlink.status==200 || window.location.href.indexOf("http")==-1){
	alert(mygetrequestlink.responseText);  
	//document.getElementById("adminMessage").innerHTML = mygetrequestadmin.responseText
  }
  else{
   alert("An error has occured making the request3")
  }
 }
}
var linkId=id
var altTitle = title
var altLink = link
var linkAdder = user
var linkRequest = "/addLink.php?id="+linkId+"&title="+altTitle+"&url="+altLink+"&username="+linkAdder
mygetrequestlink.open("GET", linkRequest, true)
mygetrequestlink.send(null)
}


function preview(form){

document.getElementById("showPreview").style.display = 'none';
document.getElementById("showPreview").style.visibility = 'hidden';

var comments = form.commentsText.value;
var fail = "-1";
while(comments.lastIndexOf("\n") != fail || comments.lastIndexOf("\r\n") != fail){
comments = comments.replace("\r\n","<br/>");
comments = comments.replace("\n","<br/>");
}
comments = trimStr(comments);

var commentMsg = "";

	if(comments == '')
		{
			commentMsg += "Comment empty naughty boy\n";
		}
	if(comments != '' && comments.length <= 1)
		{
			commentMsg += "Itna ehsaan bhi kyun karte ho ?\n";	
		}

	if (commentMsg != '') 
	{
		alert(commentMsg);
	}
	else
	{
		document.getElementById("showPreview").style.display = 'block';
		document.getElementById("showPreview").style.visibility = 'visible';
		document.getElementById("commentsPreview").innerHTML = comments;
	}	
}

function submitComment(){

var comments_submit = document.commentform.commentsText.value;
comments_submit = trimStr(comments_submit);

var commentMsg_submit = "";

	if(comments_submit == '')
		{
			commentMsg_submit += "Comment empty naughty boy\n";
		}
	if(comments_submit != '' && comments_submit.length <= 1)
		{
			commentMsg_submit += "Itna ehsaan bhi kyun karte ho ?\n";	
		}

	if (commentMsg_submit != '') 
	{
		alert(commentMsg_submit);
	}
	else
	{
		document.getElementById("showPreview").style.display = 'none';
		document.getElementById("showPreview").style.visibility = 'hidden';
		document.commentform.commentsubmitbutton.disabled=true;
		document.getElementById("submittingComment").style.display = 'inline';
		document.getElementById("submittingComment").style.visibility = 'visible';
		document.commentform.submit();
	}		
}

function pause(millisecondi)
{
	var now = new Date();
	var exitTime = now.getTime() + millisecondi;

	while(true)
	{
		now = new Date();
		if(now.getTime() > exitTime) return;
	}
}
	  
function submitOnAltLinks(unique, image1, text1){
	if(trimStr(document.altPageForm.keysList.value) == ""){ alert("Please Enter Tags");document.altPageForm.keysList.style.border="1px solid #ff0000"; }else if(trimStr(document.altPageForm.keysList.value)!="" && trimStr(document.altPageForm.keysList.value).length < 10){ alert("Please Enter More Tags, Hope you are using the Tagger");document.altPageForm.keysList.style.border="1px solid #ff0000";} 
else
	{ 
		document.getElementById("burned").style.display = 'inline';
		document.getElementById("burned").style.visibility = 'visible';
		document.altPageForm.altSubmitButton.disabled=true;
	    ajaxImage(unique,image1,text1);
		//document.altPageForm.submit();
	}
}

function submitOnAltLinksFinal(){
	if(trimStr(document.altPageForm.keysList.value) == ""){ alert("Please Enter Tags");document.altPageForm.keysList.style.border="1px solid #ff0000"; }else if(trimStr(document.altPageForm.keysList.value)!="" && trimStr(document.altPageForm.keysList.value).length < 10){ alert("Please Enter More Tags, Hope you are using the Tagger");document.altPageForm.keysList.style.border="1px solid #ff0000";} 
else document.altPageForm.submit();	
}

function ajaxImage(unique, image, text){
var mygetrequestImage=new ajaxRequest()
mygetrequestImage.onreadystatechange=function(){
 if (mygetrequestImage.readyState==4){
  if (mygetrequestImage.status==200 || window.location.href.indexOf("http")==-1){
   document.getElementById("imageDiv").innerHTML = '<img src="'+mygetrequestImage.responseText+'" width="100" class="listimg" />';
   document.getElementById("burned").innerHTML = 'Image Burned, Submit Form';
   document.getElementById("burned").innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Submit Story" class="commentSubmit" onClick="document.altPageForm.submit();" />';
  }
  else{
   alert("An error has occured making the request4")
  }
 }
}
var keyvalue=encodeURIComponent(image)
var keyvalue1=encodeURIComponent(text)
var keyvalue2 = unique
mygetrequestImage.open("GET", "/burnImage.php?image="+keyvalue+"&text="+keyvalue1+"&unique="+keyvalue2, true)
mygetrequestImage.send(null)
}

function ajaxDeleteAlt(id,user){
	var mygetrequestDeleteAlt=new ajaxRequest()
	mygetrequestDeleteAlt.onreadystatechange=function(){
	 if (mygetrequestDeleteAlt.readyState==4){
	  if (mygetrequestDeleteAlt.status==200 || window.location.href.indexOf("http")==-1){
	  alert(mygetrequestDeleteAlt.responseText)
	  }
	  else{
	   alert("An error has occured making the request5")
	  }
	 }
	}
	var idHere=id
	var userHere = user;
	mygetrequestDeleteAlt.open("GET", "/addLink.php?iddel="+idHere+"&user="+userHere, true)
	mygetrequestDeleteAlt.send(null)
}

function deleteAlt(id,user){
	if(confirm("Are you sure ?"))
	{
		ajaxDeleteAlt(id,user);
	}
}

function ajaxBanAlt(host,user){
	var mygetrequestBanAlt=new ajaxRequest()
	mygetrequestBanAlt.onreadystatechange=function(){
	 if (mygetrequestBanAlt.readyState==4){
	  if (mygetrequestBanAlt.status==200 || window.location.href.indexOf("http")==-1){
	alert(mygetrequestBanAlt.responseText)
	  }
	  else{
	   alert("An error has occured making the request6")
	  }
	 }
	}
	var hostHere=encodeURIComponent(host)
	var userHereBan=user
	mygetrequestBanAlt.open("GET", "/doAdmin.php?banalt="+hostHere+"&user="+userHereBan, true)
	mygetrequestBanAlt.send(null)
}

function banAlt(host,user){
	if(confirm("Are you sure ?"))
	{
		ajaxBanAlt(host,user);
	}
}

function ajaxAddCustomAltLink(link,user,id,pageurl){

	var myrequestAddCustomAltLink=new ajaxRequest()
	myrequestAddCustomAltLink.onreadystatechange=function(){
	if (myrequestAddCustomAltLink.readyState==4){
	if (myrequestAddCustomAltLink.status==200 || window.location.href.indexOf("http")==-1){
	document.getElementById("addAltResultDiv").innerHTML = ""
	document.getElementById("addAltResultDiv").innerHTML = myrequestAddCustomAltLink.responseText
	}
	else{
	alert("An error has occured making the request7")
	document.getElementById("addAltResultDiv").innerHTML = ""
	}
	}
	}
	var altLinkHere= encodeURIComponent(link)
	var userAltHere= user
	var idAltHere = id
	var pageurlhere= encodeURIComponent(pageurl)
	myrequestAddCustomAltLink.open("GET", "/addLink.php?altcust="+altLinkHere+"&user="+userAltHere+"&id="+idAltHere+"&pageurl="+pageurlhere, true)
	myrequestAddCustomAltLink.send(null)	
}

function ajaxAddAltCustom(url,user,id,pageurl){

		if(trimStr(url) !=''){			
		ajaxAddCustomAltLink(url,user,id,pageurl)
		document.getElementById("addAltResultDiv").innerHTML = "<img src='images/loading.gif' />"
		}
		else{
		alert("Please enter the link");	
		}

}

function chukde(user, ip, id, md5){
	
	var myrequestchukde=new ajaxRequest()
	myrequestchukde.onreadystatechange=function()
	{
		if (myrequestchukde.readyState==4)
		{
			if (myrequestchukde.status==200 || window.location.href.indexOf("http")==-1)
			{	
				document.getElementById("count").innerHTML = myrequestchukde.responseText
			}
			else
			{
				alert("An error has occured making the request8")	
			}
		}
	}

	var voter = user
	var ipVoter = ip
	var storyVoter = id 
	var md5Voter = encodeURIComponent(md5)
	myrequestchukde.open("GET", "/chukde.php?user="+voter+"&ip="+ipVoter+"&id="+storyVoter+"&md5="+md5Voter, true)
	myrequestchukde.send(null)		
}


function addCustomImageAjax(image,text){
	var addCustomImageAjax=new ajaxRequest()
	addCustomImageAjax.onreadystatechange=function(){
	if (addCustomImageAjax.readyState==4){
	if (addCustomImageAjax.status==200 || window.location.href.indexOf("http")==-1){	
		if(addCustomImageAjax.responseText != 'Invalid Image')
		{			
			document.getElementById("imageView").innerHTML = "<img src='"+addCustomImageAjax.responseText+"'  width='100' height='80' />";
			document.getElementById("image_edit").value = addCustomImageAjax.responseText
			document.newImageForm.newImage.value ="";
			alert("New Image Uploaded. Now save the field.");
		}
		else alert(addCustomImageAjax.responseText)
	}
	else{
	document.getElementById("processingImage").innerHTML = ""
	alert("An error has occured making the request9")	
	}
	}
	}
	var addImageHere = encodeURIComponent(image)	
	var addImageTitle = trimStr(text)
	addCustomImageAjax.open("GET", "/burnImage.php?image="+addImageHere+"&text="+addImageTitle, true)
	addCustomImageAjax.send(null)
}


function HandleFileButtonClick()
{
	if(trimStr(document.newImageForm.newImage.value)!='')
	{
		var imageHere = trimStr(document.newImageForm.newImage.value);
		var textHere = trimStr(document.getElementById("title").innerHTML);
		if(textHere =='')
		{
			textHere = 	trimStr(document.getElementById("title_edit").innerHTML);
		}
		if(textHere !='' && imageHere !='')
		{
			addCustomImageAjax(imageHere, textHere);
		}
	}
}

function HandleDefault()
{
document.getElementById("image_edit").value ='thumb_default.gif';
}

function getSelection(ta)
{ var bits = [ta.value,'','','']; 
if(document.selection)
  { var vs = '#$%^%$#';
	var tr=document.selection.createRange()
	if(tr.parentElement()!=ta) return null;
	bits[2] = tr.text;
	tr.text = vs;
	fb = ta.value.split(vs);
	tr.moveStart('character',-vs.length);
	tr.text = bits[2];
	bits[1] = fb[0];
	bits[3] = fb[1];
  }
else
  { if(ta.selectionStart == ta.selectionEnd) return null;
	bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
  }
return bits;
}

function matchPTags(str)
{ str = ' ' + str + ' ';
ot = str.split(/\[[B|U|I].*?\]/i);
ct = str.split(/\[\/[B|U|I].*?\]/i);
return ot.length==ct.length;
}

function addPTag(ta,pTag)
{ bits = getSelection(ta);
if(bits)
  { if(!matchPTags(bits[2]))
	  { alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
		return;
	  }
	ta.value = bits[1] + '<' + pTag + '>' + bits[2] + '</' + pTag + '>' + bits[3];
  }
}

function addPLink(txt)
{
bitst = getSelection(txt);
replyt = prompt("Enter the Link\n\n", "http://")
	if(bitst && trimStr(replyt)!='')
	{
		txt.value = bitst[1] + '<a href="' + replyt + '" target="_blank">' + bitst[2] + '</a>' + bitst[3];
	}
}

function ajaxUploadImage(image, text, theBigId){

	var myrequestUploadImage=new ajaxRequest()
	myrequestUploadImage.onreadystatechange=function()
	{
		if (myrequestUploadImage.readyState==4)
		{
			if (myrequestUploadImage.status==200 || window.location.href.indexOf("http")==-1)
			{
				document.getElementById("uploadedImageProcess").innerHTML = ""
				document.getElementById("uploadedImages").innerHTML += myrequestUploadImage.responseText
				document.getElementById("docExerpt").value = trimStr(myrequestUploadImage.responseText) + "\r" + document.getElementById("docExerpt").value
				document.getElementById("uploadImage").value = ""				
			}
			else
			{
				alert("An error has occured making the request10")
				document.getElementById("uploadedImageProcess").innerHTML = ""
				document.getElementById("uploadedImages").innerHTML += "error processing this image, try another one"
			}
		}
	}
	var imageTitle = text
	var imageUpload = encodeURIComponent(image)
	var bigImageId = theBigId
	myrequestUploadImage.open("GET", "/burnImage.php?picture="+imageUpload+"&name="+imageTitle+"&uniqueId="+bigImageId, true)
	myrequestUploadImage.send(null)	
}


function uploadPicture(form){

var imageToUpload = form.uploadImage.value;
var imageName = prompt("Enter a Clean and Good name for the image, Preferably the story title", "");
var theUniqueIdBig = form.theUnique.value;

	if(trimStr(imageToUpload) != '' && trimStr(imageName) !='')
	{	
		if(imageToUpload.search(/.jpg/i)!=-1 || imageToUpload.search(/.png/i)!=-1 || imageToUpload.search(/.gif/i)!=-1 || imageToUpload.search(/.jpeg/i)!=-1 || imageToUpload.search(/.bmp/i)!=-1)
		{
			ajaxUploadImage(imageToUpload, imageName, theUniqueIdBig);
			document.getElementById("uploadedImageProcess").innerHTML = "<img src='/images/working.gif' />"
		}
		else
			alert("Please enter a .jpg, .gif, .png or a .bmp image file only");
	}
	else alert("Image link and Image name are required for Upload");
	
}


function ajaxUploadImageC(image, text){
	var myrequestUploadImageC=new ajaxRequest()
	myrequestUploadImageC.onreadystatechange=function()
	{
		if (myrequestUploadImageC.readyState==4)
		{
			if (myrequestUploadImageC.status==200 || window.location.href.indexOf("http")==-1)
			{
				document.getElementById("uploadedImageProcessC").innerHTML = ""				
				document.getElementById("commentsText").value = trimStr(myrequestUploadImageC.responseText) + "\r" + document.getElementById("commentsText").value
				document.getElementById("uploadImageC").value = ""
			}
			else
			{
				document.getElementById("uploadedImageProcessC").innerHTML = ""
				document.getElementById("uploadedImagesC").innerHTML += "error processing this image, try another one"
			}
		}
	}
	var imageTitleC = text
	var imageUploadC = encodeURIComponent(image)

	myrequestUploadImageC.open("GET", "/burnImage.php?picture="+imageUploadC+"&name="+imageTitleC, true)
	myrequestUploadImageC.send(null)	
}

function uploadPictureC(form){

var imageToUploadC = form.uploadImageC.value;
var imageNameC = prompt("Enter a Clean and Good name for the image, Preferably the story title", "");

	if(trimStr(imageToUploadC) != '' && trimStr(imageNameC) !='')
	{	
		if(imageToUploadC.search(/.jpg/i)!=-1 || imageToUploadC.search(/.png/i)!=-1 || imageToUploadC.search(/.gif/i)!=-1 || imageToUploadC.search(/.jpeg/i)!=-1 || imageToUploadC.search(/.bmp/i)!=-1)
		{
			ajaxUploadImageC(imageToUploadC, imageNameC);
			document.getElementById("uploadedImageProcessC").innerHTML = "<img src='images/working.gif' />"
		}
		else
		{	
			alert("Please enter a .jpg, .gif, .png or a .bmp image file only");	alert("7");
		}
	}
	else alert("Image link and Image name are required for Upload");
	
}

function addMusic(){

var fileName = prompt("Enter an MP3 file location. Preview working before submitting", "");

	if(trimStr(fileName) != '')
	{	
//		if(imageToUpload.search(/.mp3/i)!=-1)
//		{
			document.getElementById("commentsText").innerHTML = '<embed type="application/x-shockwave-flash" src="audio-player.swf?audioUrl='+fileName+'" width="400" height="27" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" />'+ '\r' + document.getElementById("commentsText").value; 			
			//document.getElementById("commentsText").innerHTML = '<object style="visibility:visible;" id="movie_player_2" data="player.swf?file='+fileName+'" type="application/x-shockwave-flash" width="250" height="20"><param value="#ffffff" name="bgColor"><param value="transparent" name="wmode"><param value="false" name="autoplay"><param value="playerID=1&amp;soundFile='+fileName+'" name="flashvars"></object>'+ '\r' + 'listen to the music file above' + '\r' + document.getElementById("commentsText").value;
//		}
//		else
//			alert("Please enter a valid MP3 file location");
	}
	else alert("MP3 file location required to insert");
	
}

function checkAll(field) {
	for (i = 0; i < field.length; i++)
	field[i].checked = true;
}

function unCheckAll(field) {
	for (i = 0; i < field.length; i++)
	field[i].checked = false;
}

function insertVideo(spanId){
	var videoValue = document.getElementById("video_"+spanId).innerHTML
	document.getElementById("docExerpt").value = trimStr(videoValue) + "\r" + document.getElementById("docExerpt").value	
}

function validateFileExtension(form) {
	if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(form.userImage.value)) {
		alert("Invalid image file type.");
		form.reset();
		userImage.focus();
	}
	else
	{
	form.submit();
	}
}

function makeHigh(id){
	if(document.getElementById("radio"+id).checked==true)
	{
		document.getElementById("image"+id).style.border="#ff0000 solid 2px";	
	}
}

function makeLow(count){
	count = count-1
	while(count>=0)
	{
		
		if(document.getElementById("radio"+count).checked==false)
		{
			document.getElementById("image"+count).style.border="0px";	
		}
		count = count-1;
	}
}

function showReply(commentId, actionUrl)
{
	
	var divShow = document.getElementById("replyTo"+commentId);

	var formShow = '<form id="replyForm'+commentId+'" name="replyForm'+commentId+'" method="GET" action="/doAdmin.php"><textarea id="textArea'+commentId+'" rows="5" class="replyCommentBox"></textarea><div class="listdivi" style="height:5px;"></div><input type="button" value=" Add Reply " class="replyCommentSubmit" onclick="javascript:addReplyComment('+commentId+')" /> OR <a href="javascript:void(0);" onclick="javascript:showReply('+commentId+');">Cancel</a> <span id="processingReplyToComment'+commentId+'"></span></form>';
	
	if(divShow.style.display == 'none'){
		divShow.style.display='block';
		divShow.focus();
		divShow.innerHTML = formShow;
	}
	else{
		divShow.innerHTML = "";
		divShow.style.display = 'none';
	}		
	
}


function addReplyCommentAjax(commentId, commentVal){
var processingAjaxReplyTo = "processingReplyToComment"+commentId;
var replyToCommentRequest=new ajaxRequest()

replyToCommentRequest.onreadystatechange=function()
{
	if (replyToCommentRequest.readyState==4)
	{
		if (replyToCommentRequest.status==200 || window.location.href.indexOf("http")==-1)
		{
			document.getElementById(processingAjaxReplyTo).innerHTML = "";
			document.getElementById("replyTo"+commentId).innerHTML = "comment added, refresh page to view"+replyToCommentRequest.responseText;
		}
		else
		{
			document.getElementById(processingAjaxReplyTo).innerHTML = "ERROR, please try later or report to admin"
		}
	}
}

var commentIdMain = commentId;
var commentTextMain = commentVal;

while (commentTextMain.indexOf("\n") != -1)
    {
		commentTextMain = commentTextMain.replace("\n","::::::::::");
    }

replyToCommentRequest.open("GET", "/doAdmin.php?commentid="+commentIdMain+"&comment="+commentTextMain, true)
replyToCommentRequest.send(null)	
 
}

function addReplyComment(commentId){
	var rText = 'textArea'+commentId;
	var processing = "processingReplyToComment"+commentId;
	if(trimStr(document.getElementById(rText).value) !='')
	{			
		document.getElementById(processing).innerHTML = "<img src='images/working.gif' /> processing...";
		var rTextVal = document.getElementById(rText).value;		
		addReplyCommentAjax(commentId, rTextVal);
	}
	else
		alert("Please enter a comment, click Cancel to abort.");
}


function addAnchorTagAjax(tag, link){

var addAnchorTagRequest=new ajaxRequest()

addAnchorTagRequest.onreadystatechange=function()
{
	if (addAnchorTagRequest.readyState==4)
	{
		if (addAnchorTagRequest.status==200 || window.location.href.indexOf("http")==-1)
		{
			document.getElementById("anchorTagDiv").innerHTML = ""
			document.getElementById("anchorTagDiv").innerHTML = addAnchorTagRequest.responseText
		}
		else
		{
			document.getElementById("anchorTagDiv").innerHTML = "ERROR"
		}
	}
}

var tagHere = tag;
var linkHere = encodeURIComponent(link);

addAnchorTagRequest.open("GET", "doAdmin.php?tag="+tagHere+"&link="+linkHere, true)
addAnchorTagRequest.send(null)	

}

function addAnchorTagFn(form, url)
{
	var anchorTag = form.tagAnchor.value;
	var urlStory = url;
	
	if(trimStr(anchorTag) !="")
	{
		addAnchorTagAjax(anchorTag,urlStory);
	}
	else
	{		
		alert("Will your fuffar add the tag ?");
	}	
}

var newwindow;

function buzzPopup(link,windowname)
{
var href;

if(typeof(link)=='string') href=link;
else href=link.href;newwindow=window.open(href,windowname,'width=540,height=510,scrollbars=yes');if(window.focus){newwindow.focus()}

return false;
}

function trim12 (str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}


function submitClick(searchForm){
	var searchVal = searchForm.q.value;
	if(searchVal =="" || searchVal =="search okidda...") return false;
	else
	{
		searchForm.q.value = trimStr(searchForm.q.value);
		searchForm.submit();
	}
	
}

function submitSubscribe(subscribeForm){
	if(subscribeForm.email.value == "enter your email")
	{
		subscribeForm.email.value = "";
		subscribeForm.submit();
	}
	else
	{
		subscribeForm.submit();
	}
}

function bookmarksite(title,url)
{
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print)
{ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}