// JavaScript Document

function srcfrmSubmit(target)
{
	var qstr = '';
	qstr += '?referrer='+document.forms['srcForm'].elements['referrer'].value;
	qstr += '&type='+document.forms['srcForm'].elements['type'].value;
	qstr += '&location='+document.forms['srcForm'].elements['location'].value;
	qstr += '&market='+document.forms['srcForm'].elements['market'].value;
	qstr += '&status='+document.forms['srcForm'].elements['status'].value;
	qstr += '&size='+document.forms['srcForm'].elements['size'].value;
	qstr += '&price='+document.forms['srcForm'].elements['price'].value;
/*
	var page = '';
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		page = 'searchact.php'+qstr;
	}
	else
	{
		page = '';
		page = 'searchact.php'+qstr;
	}
*/
	var page = '';
	page = 'searchact.php'+qstr;

	window.open(page,target,'width=600,height=600,left='+(screen.availWidth/2-300)+',top='+(screen.availHeight/2-300)+'');
	return true;
}

function postfrmSubmit(target)
{
	if (document.forms['postfrm'].elements['auth'].value.length!=32)
	{
		alert('الرّجاء الدخول بحسابك كي تستطيع الإعلان');
		return false;
	}
	height = 440;
	width = 440;

	var qstr = '';
	qstr += '?type='+document.forms['postfrm'].elements['type'].value;
	qstr += '&location='+document.forms['postfrm'].elements['location'].value;
	qstr += '&market='+document.forms['postfrm'].elements['market'].value;
	qstr += '&status='+document.forms['postfrm'].elements['status'].value;
	qstr += '&size='+document.forms['postfrm'].elements['size'].value;
	qstr += '&price='+document.forms['postfrm'].elements['price'].value;
	qstr += '&otherinfo='+document.forms['postfrm'].elements['otherinfo'].value;
	qstr += '&search='+document.forms['postfrm'].elements['search'].value;
	qstr += '&auth='+document.forms['postfrm'].elements['auth'].value;
/*
	var page = '';
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		page = 'searchact.php'+qstr;
	}
	else
	{
		page = '';
		page = 'searchact.php'+qstr;
	}
*/
	var page = '';
	page = 'postAct.php'+qstr;

	mywin = window.open(page,target,'width='+width+',height='+height+',left='+(screen.availWidth/2-(width/2))+',top='+(screen.availHeight/2-(height/2))+'');
}

function loginorregister(target,href)
{
	if (href.indexOf('loginn.php')!=-1)
		height = 240;
	else
		height = 440;
	width=440;
	window.open(href,target,'width='+width+',height='+height+',left='+(screen.availWidth/2-220)+',top='+(screen.availHeight/2-(height/2))+'');
	return false;
}

function srcreferrerempty()
{
	alert(window.parent.document.getElementById('div-form'));
}

function refreshuserstats()
{
	$.ajax({
		type: "POST",
		url: "userstat.php",
		data: 	"",
		success: function(html){
			$("#userstat").html(html);
			refreshuserstatus();
		}
	});
}

function refreshuserstatus()
{
	$.ajax({
		type: "POST",
		url: "userstatus.php",
		data: 	"",
		success: function(html){
			$("#auth").val(html);
		}
	});
}

function logout()
{
	$.ajax({
		type: "POST",
		url: "loginnout.php",
		data: 	"",
		success: function(html){
			refreshuserstats();
		}
	});
}

function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength)
}

/*
function fn_validateNumeric(evento, elemento, dec)
{
	var valor=elemento.value;
	var charWich=evento.which;
	var charCode=evento.keyCode;
	if(charWich==null)
	{
		charWich=charCode;
	}
//alert(charWich);
	if ( (charWich>=48 && charWich<=57) || charCode==8 || charCode==39 || charCode==37 || charCode==46 || charWich==46 || charWich==13 || charWich==36 || charWich==32 )
	{
		if(dec=="n" && ((charWich==46) || (charWich==36) || (charWich==32) ))
		{
			return false;
		}
		else
		{
			if(valor.indexOf('.')!=-1 && charWich==46)
			{
				return false;
			}
			else
			if(valor.length!=0 && charWich==36)
			{
				return false;
			}
			if(valor.length!=1 && charWich==32)
			{
				return false;
			}
		}
		return true;
	}
	else
	{
		return false;
	}
}
*/

function fn_validateNumeric(evento, elemento, dec)
{
	var valor=elemento.value;
	var charWich=evento.which;
	var charCode=evento.keyCode;
	if(charWich==null)
	{
		charWich=charCode;
	}
//alert(charWich);
	if ( (charWich>=48 && charWich<=57) || charCode==8 || charCode==39 || charCode==37 || charCode==46 || charWich==46 || charWich==13 )
	{
		if(dec=="n" && ((charWich==46) || (charWich==36) || (charWich==32) ))
		{
			return false;
		}
		else
		{
			if(valor.indexOf('.')!=-1 && charWich==46)
			{
				return false;
			}
		}
		return true;
	}
	else
	{
		return false;
	}
}

