dochref = document.location.href.substr(document.location.href.search('/')+2, 1000);
if(dochref.search('/') == -1){
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref;
} else {
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref.substr(0, dochref.search('/'));
}
$thisurl = $thisurl + '';

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try {
	xmlhttp = new XMLHttpRequest ();
  }
  catch (e) {
  xmlhttp = false}
}

function myXMLHttpRequest ()
{
  var xmlhttplocal;
  try {
  	xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
  catch (e) {
	try {
	xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
	catch (E) {
	  xmlhttplocal = false;
	}
  }

  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
	try {
	  var xmlhttplocal = new XMLHttpRequest ();
	}
	catch (e) {
	  var xmlhttplocal = false;
	}
  }
  return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var xvotesString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function vote (user, id, htmlid, md5, value)
{
  	if (xmlhttp) {
		url = $thisurl + "/vote.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = true;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.rottenneighbor.com/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');

    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('xvotes-' + htmlid);
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
							    					} else {
							var mySplitResult = xvotesString[htmlid].split('~');
target3 = document.getElementById ('xvote-' + htmlid);
target3.style.width = mySplitResult[0] + 'px';
target4 = document.getElementById ('mnma-' + htmlid);
target4.innerHTML = mySplitResult[1];
target5 = document.getElementById ('mnmb-' + htmlid);
target5.innerHTML = mySplitResult[2];
target7 = document.getElementById ('xvotes-' + htmlid);
target7.className = 'star-rating-noh';
							    					}
    				}
    			}
    		}
    	}
	}
}


function unvote (user, id, htmlid, md5, value)
{
  	if (xmlhttp) {
		url = $thisurl + "/vote.php";
		var mycontent = "unvote=true&id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = true;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.rottenneighbor.com/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');

    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
				target1 = document.getElementById ('xvotes-' + htmlid);
  				target2 = document.getElementById ('xvote-' + htmlid);
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						 xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
													} else {
							    					}
    				}
    			}
    		}
    	}
	}
}


function cvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/cvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = true;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.rottenneighbor.com/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
    						changecvotevalues (htmlid, true);
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function changemnmvalues (id, value, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('xvotes-' + id);
	target2 = document.getElementById ('xvote-' + id);
	target3 = document.getElementById ('xreport-' + id);
	target4 = document.getElementById ('xnews-' + id);
	if (error) {
		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }
		else if (value < 0) { target2.innerHTML = "<span>Buried</span> "; }
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
		new Effect.Fade(target3);
		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }
		else if (value < 0 ) { target2.innerHTML = "<span>Buried</span> ";
													new Effect.Opacity(target4, {duration:0.8, from:1.0, to:0.3}); }
	}
	return false;
}

function changecvotevalues (id, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	target1 = document.getElementById ('cvote-' + id);
	if (error) {
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
	}
	return false;
}


function enablebutton (button, button2, target)
{
	var string = target.value;
	button2.disabled = false;
	if (string.length > 0) {
		button.disabled = false;
	} else {
		button.disabled = true;
	}
}

function checkfield (type, form, field)
{
	url = $thisurl + '/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);
	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
			if (responsestring == 'OK') {
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:black">"' + field.value +
						'": ' + responsestring + '</span>';
				form.submit.disabled = '';
			} else {
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:red">"' + field.value + '": ' +
				responsestring + '</span>';
				form.submit.disabled = '';
			}
		}
	}
  checkitxmlhttp.send (null);
  return false;
}

function emailto (original_id, htmlid, instpath, address_count)
{
	email_message = document.getElementById('email_message' + htmlid).value;
	email_address = document.getElementById('email_address_1_' + htmlid).value;
	if (address_count > 1){
		for ($i = 2; $i <= address_count; $i++) {
			if(document.getElementById('email_address_' + $i + '_' + htmlid).value != "") {
				email_address = email_address + ', ' + document.getElementById('email_address_' + $i + '_' + htmlid).value;
			}
		}
	}

	if (xmlhttp) {
		url = $thisurl + "/recommend.php";
		mycontent = "email_address=" + escape(email_address) + "&email_to_submit=submit&email_message=" + escape(email_message) + "&original_id=" + original_id + "&backup=0";
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>Sending, please wait....";

		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;

					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}

function show_recommend(htmlid, linkid, instpath)
{
	var emailtodisplay=document.getElementById('emailto-' + htmlid).style.display ? '' : 'none';
	document.getElementById('emailto-' + htmlid).style.display = emailtodisplay;

	if (xmlhttp) {
		url = $thisurl + "/recommend.php";
		mycontent = "draw=small&htmlid=" + htmlid + "&linkid=" + linkid;
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>Loading, please wait....";
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();

		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}

// start:  This funciton is added by parvinder on 3rd december for new flag system
function FlagThisForRemoval(linkid,lat,lng)
{
	var emailtodisplay=document.getElementById('flag-' + linkid).style.display ? '' : 'none';

	if(emailtodisplay == ''){
		var posttodisplay='none';
	} else {
		var posttodisplay='';
	}

	document.getElementById('flag-' + linkid).style.display = emailtodisplay;
	if(document.getElementById('post-container-' + linkid)!=null){
	document.getElementById('post-container-' + linkid).style.display = posttodisplay;
	}

	if (xmlhttp) {
		url = $thisurl + "/flagforremoval.php";
		mycontent = "linkid=" + linkid + "&lat=" + lat + "&lng="+lng;
		target2 = document.getElementById ('flag-' + linkid);
		target2.innerHTML = "<br>Loading, please wait....";
		mnmxmlhttp[linkid] = new myXMLHttpRequest ();

		if (mnmxmlhttp) {
			mnmxmlhttp[linkid].open ("POST", url, true);
			mnmxmlhttp[linkid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[linkid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('flag-' + linkid);
			mnmxmlhttp[linkid].onreadystatechange = function () {
				if (mnmxmlhttp[linkid].readyState == 4) {
					xvotesString[linkid] = mnmxmlhttp[linkid].responseText;
					if (xvotesString[linkid].match (errormatch)) {
						xvotesString[linkid] = xvotesString[linkid].substring (6, xvotesString[linkid].length);
						target2 = document.getElementById ('flag-' + linkid);
						target2.innerHTML = xvotesString[htmlid];
					} else {
						target2 = document.getElementById ('flag-' + linkid);
						target2.innerHTML = xvotesString[linkid];
					}
				}
			}
		}
	}
}

function emailForFlag(original_id, htmlid, instpath)
{
	var email = document.getElementById('email_address_1_' + htmlid).value;
	var name = document.getElementById('name_1_' + htmlid).value;
	var email_message = document.getElementById('email_message_1_' + htmlid).value;
	//if(email=="" || name=="" || email_message=="")
	if(email_message=="")
	{
		alert("Please enter Reason for Removal.");
		return false;
	}

	if (xmlhttp) {
		url = $thisurl + "/flagforremoval.php";
		mycontent = "email_address=" + escape(email) + "&name=" +escape(name)+ "&email_to_submit=submit&email_message=" + escape(email_message) + "&original_id=" + original_id + "&backup=0";
		target2 = document.getElementById ('flag-' + htmlid);
		target2.innerHTML = "<br>Sending, please wait....";

		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('flag-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;

					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
						target2 = document.getElementById ('flag-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					} else {
						target2 = document.getElementById ('flag-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}
// end:  This funciton is added by parvinder on 3rd december for new flag system

// this function is from the /templates/yget/link_summart.tpl //
function bookmarksite(title, url)
{
	try {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			return window.sidebar.addPanel(title, url, "");
		} else if( window.external ) { // IE Favorite
			return window.external.AddFavorite( url, title);
		} else if(window.opera && window.print) { // Opera Hotlist
			return true;
		}
	} catch(err) {
		// do nothing
	}
	alert('Could not create a bookmark on your client.\n\nTo return to ' + title + ' you must manually create a bookmark to: \n' + url + '.');

}


//// contest Photo Rating

var contest_mnmxmlhttp = Array ();
var contest_xvotesString = Array ();
var contest_mnmPrevColor = Array ();
var contest_responsestring = Array ();
var contest_myxmlhttp = Array ();
var contest_responsestring = new String;

function contest_changemnmvalues (id, value, error)
{
	split = new RegExp ("~--~");
	b = contest_xvotesString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('xvotes-' + id);
	target2 = document.getElementById ('xvote-' + id);
	target4 = document.getElementById ('xnews-' + id);
	if (error) {
		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }
		else if (value < 0) { target2.innerHTML = "<span>Buried</span> "; }
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = contest_mnmPrevColor[id];
		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }
	}
	return false;
}


function vote_photo_contest (user, id, htmlid, md5, value,title,active)
{

	if (xmlhttp) {
		url = $thisurl + "/vote_contest_photo.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;

		if (user == '0') {
				window.location="login.php?return=/rottenmedia_photos_contest.php";
		} else {

			if (active == 'n') {
					window.location="activateaccount.php?return=/rottenmedia_photos_contest.php";
			} else {




				var msg ="Are you sure you want to vote for the photo entry named '"+title+"'?\r\nYou only get one vote per day per category.";
				var answer = confirm(msg)

				if (answer){

						contest_mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
						if (contest_mnmxmlhttp) {
							contest_mnmxmlhttp[htmlid].open ("POST", url, true);
							contest_mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
										 'application/x-www-form-urlencoded');

							contest_mnmxmlhttp[htmlid].send (mycontent);
							errormatch = new RegExp ("^ERROR:");
							target1 = document.getElementById ('xvotes-' + htmlid);
							contest_mnmPrevColor[htmlid] = target1.style.backgroundColor;
							contest_mnmxmlhttp[htmlid].onreadystatechange = function () {
								if (contest_mnmxmlhttp[htmlid].readyState == 4) {
									contest_xvotesString[htmlid] = contest_mnmxmlhttp[htmlid].responseText;
									if (contest_xvotesString[htmlid].match (errormatch)) {
										contest_xvotesString[htmlid] = contest_xvotesString[htmlid].substring (6, contest_xvotesString[htmlid].length);
										contest_changemnmvalues (htmlid, value, true);									} else {
										if (contest_xvotesString[htmlid].substring (1, 6) == "ERROR") { alert(contest_xvotesString[htmlid]);  } else {contest_changemnmvalues (htmlid, value, false); } 									}
								}
							}
						}
				}else{}

			}
		}
	}
}


function vote_video_contest (user, id, htmlid, md5, value,title,active)
{
  	if (xmlhttp) {
		url = $thisurl + "/vote_contest_video.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;

		if (user == '0') {
				window.location="login.php?return=/rottenmedia_videos_contest.php";
		} else {

			if (active == 'n') {
					window.location="activateaccount.php?return=/rottenmedia_video_contest.php";
			} else {

				var msg ="Are you sure you want to vote for the video entry named '"+title+"'?\r\nYou only get one vote per day per category.";
				var answer = confirm(msg)

			if (answer){

					contest_mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
					if (contest_mnmxmlhttp) {
						contest_mnmxmlhttp[htmlid].open ("POST", url, true);
						contest_mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
									 'application/x-www-form-urlencoded');

						contest_mnmxmlhttp[htmlid].send (mycontent);
						errormatch = new RegExp ("^ERROR:");
						target1 = document.getElementById ('xvotes-' + htmlid);
						contest_mnmPrevColor[htmlid] = target1.style.backgroundColor;
						contest_mnmxmlhttp[htmlid].onreadystatechange = function () {
							if (contest_mnmxmlhttp[htmlid].readyState == 4) {
								contest_xvotesString[htmlid] = contest_mnmxmlhttp[htmlid].responseText;
								if (contest_xvotesString[htmlid].match (errormatch)) {
									contest_xvotesString[htmlid] = contest_xvotesString[htmlid].substring (6, contest_xvotesString[htmlid].length);
									contest_changemnmvalues (htmlid, value, true);								} else {
									if (contest_xvotesString[htmlid].substring (1, 6) == "ERROR") { alert(contest_xvotesString[htmlid]);  } else {contest_changemnmvalues (htmlid, value, false); } 								}
							}
						}
					}
				} else {}

			}
    }
	}
}
