// Set Focus
function fokus(){
	try
	{
		document.frmPost.myTitle.focus();
	}
	catch(err)
	{}
}

// Entry Length
function entryLength(parent,session)
{
	//Category
	if(parent==0 || session==0)
	{
		alert("You must select a Category AND a Sub-category for your Ad.");
		return(false);
	}
	//Title
	if(document.frmPost.myTitle.value.length < 1)
	{
		alert("Your Ad MUST possess a suitable Title!");
		document.frmPost.myTitle.focus();
		return(false);
	}
	//Content
	if(document.frmPost.myAd.value.length < 1 || document.frmPost.myAd.value.length > 3000)
	{
		alert("Ads can neither be blank nor exceed 3000 characters.\nYour Ad is "+document.frmPost.myAd.value.length+" character(s).\nPlease edit your Ad and try again.");
		document.frmPost.myAd.focus();
		return(false);
	}
	//Email
	var tst2;
	tst2 = new RegExp("^[a-zA-Z0-9_\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$");
	if(!tst2.test(document.frmPost.myEmail.value) && document.frmPost.myEmail.value!="")
	{
		alert("Your Email Address seems to be invlaid. Please check it and try again.");
		document.frmPost.myEmail.focus();
		return(false);
	}
	else if(document.frmPost.myEmail.value=="")
	{
		alert("A valid E-mail Address is required.");
		document.frmPost.myEmail.focus();
		return(false);
	}
	document.frmPost.send.value = "Preparing...";
	document.frmPost.send.disabled = true;
	document.frmPost.submit();
}

// Reply Check
function checkReply()
{
	//Email
	var tst2;
	tst2 = new RegExp("^[a-zA-Z0-9_\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$");
	if(!tst2.test(document.frmReply.email.value) && document.frmReply.email.value!="")
	{
		alert("Your Email Address seems to be invlaid. Please check it and try again.");
		document.frmReply.email.focus();
		return(false);
	}
	else if(document.frmReply.email.value=="")
	{
		alert("A valid E-mail Address is required.");
		document.frmReply.email.focus();
		return(false);
	}
	//Reply
	if(document.frmReply.reply.value.length < 1 || document.frmReply.reply.value.length > 1000)
	{
		alert("Replies can neither be blank nor exceed 1000 characters.\nYour Reply is "+document.frmReply.reply.value.length+" character(s).\nPlease edit your Reply and try again.");
		document.frmReply.reply.focus();
		return(false);
	}
	document.frmReply.rply.value = "Preparing...";
	document.frmReply.rply.disabled = true;
	document.frmReply.submit();
}

// Ad Save
function adsave()
{
	document.frmAction.save.value = "Publishing...";
	document.frmAction.save.disabled = true;
	window.location='scripts/post.php?save'
}

//Location Verification for Posting
function locVerify(country,region,city)
{
	if(country==0)
	{
		alert("Please select your country.");
		return(false);
	}
	else if(region==0)
	{
		alert("Please select your region.");
		return(false);
	}
	else if(city==0)
	{
		alert("Please select the city/town nearest to you.");
		return(false);
	}
	else
	{
		window.location="?post";
	}
}

// AGE RESTRICTION ALERT
// Adopted from the original by Massimo Beatini (c) 2006
//
// global variables
var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;
// Dynamically add page dimmer Div
function buildDimmerDiv()
{
  document.write('<div id="dimmer" class="dimmer" style="width:93%; height:100%;"></div>');
}
// Main Function
function displayAgeAlert(divId, title, width, height, left, top, goto) 
{
	DivID = divId;
	document.getElementById('dimmer').style.visibility = "visible";
	document.getElementById(divId).style.width = width + 'px';
	document.getElementById(divId).style.height = height + 'px';
	document.getElementById(divId).style.left = left + 'px';
	document.getElementById(divId).style.top = top + 'px';
	document.getElementById(divId).style.display = "block";
	var addHeader;
	var addFooter;
	if (originalDivHTML == "") originalDivHTML = document.getElementById(divId).innerHTML;
	addHeader = '<table style="width:' + width + 'px" class="floatingHeader">' +
	            '<tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px">' + title + '</td>' + 
	            '</tr></table>';
	addFooter = '<p align="center"><input type="button" class="button2" value="   I Agree   " onclick="javascript:hiddenFloatingDiv(\'ageAlert\',\'' + goto + '\');void(0);" />' +
							'&nbsp;&nbsp;&nbsp;<input type="button" class="button2" value="Cancel" onclick="javascript:hiddenFloatingDiv(\'ageAlert\',\'\');void(0);" /></p>';
	// Add header & footer to Div
	document.getElementById(divId).innerHTML = addHeader + originalDivHTML + addFooter;
	
	document.getElementById(divId).className = 'dimming';
	document.getElementById(divId).style.visibility = "visible";
}
// Div hider
function hiddenFloatingDiv(divId, goto) 
{
	document.getElementById(divId).innerHTML = originalDivHTML;
	document.getElementById(divId).style.visibility='hidden';
	document.getElementById('dimmer').style.visibility = 'hidden';
	DivID = "";
	if(goto != "")
	{
		document.location = goto;
	}
}
// Drag and Drop Semantics
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 = event.offsetY;
        }
    }
}
//
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;
            objDiv.pixelTop = event.clientY-Y + document.body.scrollTop;
            return false;
        }
    }
}
//
function MouseUp() 
{
    objDiv = null;
}
//
function init()
{
    // 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;

    // add the div
    // used to dim the page
	buildDimmerDiv();

}
// Initialize
init();
// END AGE RESTRICTION ALERT

// Google Tracker
document.write("\<script src='http://www.google-analytics.com/ga.js' type='text/javascript'>\<\/script>" );

if (typeof(_gat) == "object") { 
	var pageTracker = _gat._getTracker("UA-3216877-1");
	pageTracker._initData();
	pageTracker._trackPageview();
}