// JavaScript Document

var cursor = {x:0, y:0};

document.onmousemove= getXY

preloading=new Image();
preloading.src='/imagini/clock.gif';
function getXY(e) {
  x = (window.Event) ? e.pageX : event.clientX+document.body.scrollLeft;
  y = (window.Event) ? e.pageY : event.clientY+document.body.scrollTop;

  cursor.x=x;
  cursor.y=y;
}

function g_byID(id)
{
	return document.getElementById(id);
}

function show(id)
{
		g_byID(id).style.display='';
}

function hide(id)
{
		g_byID(id).style.display='none';
}

function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  //strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      alert('A valid e-mail address is required.\nPlease amend and retry');
      return false;
    } 
    return true; 
}

function isEmpty(str,field)
{
	if (str=="" || str==" " || str==null)
		{alert('Fill all mandatory fields! "'+field+'" is mandatory !');
		return true;
		}
	return false;
}

function isSelected(str,field)
{
	if (str=="" || str=="0")
		{alert('Fill all mandatory fields! "'+field+'" is mandatory !');
		return false;
		}
	return true;
}

	function validate_form()
	{		
		if (!isValidEmail(g_byID('email').value)) return false;
	//	if (isEmpty(g_byID('nick').value,'Nickname')) return false;
		if (isEmpty(g_byID('city').value,'City')) return false;		
		if (isEmpty(g_byID('phone').value,'Phone')) return false;
		if (isEmpty(g_byID('rates').value,'Rates')) return false;
	//	if (isEmpty(g_byID('description').value,'Description')) return false;		
		if (!isSelected(g_byID('country').value)) return false;
		return true;
	}

	function openBig(src,title)
					{
						window.open('/preview.php?img='+src+'&title='+title,'mywindows','status=0, toolbar=0, menubar=0, location=0, resizeable=1, width=470, height=350, focus=1, directories=0');
					}
	
	
	function openPopup(popURL){

	var popLeft = (screen.width - 370) / 2;

	var popTop = (screen.height - 590) / 2;

	passPop=window.open(popURL,"","width=370,height=590,top="+popTop+",left="+popLeft+",")

}

function openAdvertise(popURL){

	passPop=window.open ('http://www.girls4arabians.com/advertising/?url='+popURL,'w','width=1024, height=768, toolbar=1, resizable=1, menubar=1, location=1, status=1, scrollbars=1,').blur(); 
	window.focus();

}

function checkall(formname,checkname,thestate){
  var   el_collection=eval("document.forms."+formname+"."+checkname)
  for (c=0;c<el_collection.length;c++){
      el_collection[c].checked=thestate;
    }
} 

var catched=false;
function set_catched()
{
	if(catched)
		catched=false;
	else catched=true;	
}

function resizeCutter(plus,value)
{
	var w;
	
	w=document.getElementById('cutter').offsetWidth+(plus*value);
	document.getElementById('cutter').style.width=w;
	document.getElementById('cutter').style.height=w*1.3;
	
	g_byID('cutterWidth').value=w;
}

function chatch_onmousemove(ev)
{
	var picx;
	var pict;
	var w;
	var h;
	var IE = document.all?true:false
	
	w=40;
	h=60;
	
	if(!catched)
	{
	
	picx=g_byID('pic_x').value;
	pict=g_byID('pic_y').value;
	
	if(!IE)
	{
		g_byID('cutter').style.left=(ev.pageX*1-w)+'px';
		g_byID('cutter').style.top=(ev.pageY*1-h)+'px';
		g_byID('cornerLeft').value=(ev.pageX*1-w)-(picx*1);
		g_byID('cornerTop').value=(ev.pageY*1-h)-(pict*1);
	}
	else{
		g_byID('cutter').style.left=event.clientX - 2 - w + document.body.scrollLeft;
		g_byID('cutter').style.top=event.clientY -2 - h + document.body.scrollTop;
		g_byID('cornerLeft').value=g_byID('cutter').offsetLeft-(picx*1);
		g_byID('cornerTop').value=g_byID('cutter').offsetTop-(pict*1);
	}
	
	
	}
	
} 

function insertEmoticons(val)
{
	var text;
	text=g_byID('description').value+' '+val+' ';
	g_byID('description').value=text;
}

function checkAll()
	{
		var checks,i;
		checks=document.getElementsByName('sel[]');
		for (i=0;i<checks.length;i++)
			checks[i].checked=true;
	}
function uncheckAll()
	{
		var checks,i;
		checks=document.getElementsByName('sel[]');
		for (i=0;i<checks.length;i++)
			checks[i].checked=false;
	}

function getMouseCoords()
{
	var ev=window.event;
	var IE = document.all?true:false
	
	if(IE)
		return event.clientX+'_'+event.clientX;
	else return ev.pageX+'_'+ev.pageY;
}

function allowClose()
{
	permitClose=1;
}
function movePrew()
{
	var prew=document.getElementById('previewContainer');
	prew.style.left=cursor.x+15;
	prew.style.top=cursor.y+15;
}

function getPreview(esc_id)
{
	var prew=document.getElementById('previewContainer');
	
	
	prew.style.display='';
	prew.style.left=cursor.x+5;
	prew.style.top=cursor.y+5;
	
	
	prew.innerHTML='<img src="'+preloading.src+'" border="0">';
	ajax_get('http://www.yourescortagency.com/ag/ajaxdo/getEscPreview.php?esc_id='+esc_id,'previewContainer');
	return true;
}

function closePreview()
{
	
	document.getElementById('previewContainer').style.display='none';

	return true;
}
