// JavaScript Document
var url='http://shauto.ro';
//var url='http://kpk';
var screenSizeW,screenSizeH;
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 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 show_hide(id)
{
	if (g_byID(id).style.display=='none')	
		show(id);
	else hide(id);
}

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 openProfile(id,ordinal)
	{
			window.open('/profile.php?id='+id+'&layout=1&ordinal='+ordinal,'profile','status=0, toolbar=0, menubar=0, location=0, resizable=1, width=615, height=550, focus=1, scrollbars=1, directories=0');
	}
	
	function openSendMail(id)
	{
			window.open('/send_message.php?id='+id+'&layout=1','send_message','status=0, toolbar=0, menubar=0, location=0, resizable=1, width=615, height=550, focus=1, scrollbars=1, directories=0');
	}
	
	function openViewMail(id)
	{
			window.open('/view_mail.php?id='+id+'&layout=1','view_message','status=0, toolbar=0, menubar=0, location=0, resizable=1, width=615, height=550, focus=1, scrollbars=1, directories=0');
	}
	
	function replyMail(user,mail)
	{
			window.open('/send_message.php?id='+user+'&replyMailId='+mail+'&layout=1','send_message','status=0, toolbar=0, menubar=0, location=0, resizable=1, width=615, height=550, focus=1, scrollbars=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;
    }
} 

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

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*0.66;
	
	g_byID('cutterWidth').value=w;
}

function chatch_onmousemove(ev)
{
	var picx;
	var pict;
	var IE = document.all?true:false
	var version;
	
	if(!catched)
	{
	
	picx=g_byID('pic_x').value;
	pict=g_byID('pic_y').value;
	
	if(!IE)
	{
		x=ev.pageX;
		y=ev.pageY;
		x=x*1-10;
		y=y*1-10;
		g_byID('cutter').style.left=x+'px';
		g_byID('cutter').style.top=y+'px';
		g_byID('cornerLeft').value=(x*1)-(picx*1);
		g_byID('cornerTop').value=(y*1)-(pict*1);
	}
	else{
		x=event.clientX;
		y=event.clientY;
		x=x*1-10;
		y=y*1-10;
		g_byID('cutter').style.left=x - 2 + document.body.scrollLeft;
		g_byID('cutter').style.top=y -2 + document.body.scrollTop;
		g_byID('cornerLeft').value=g_byID('cutter').offsetLeft-(picx*1)-315;
		g_byID('cornerTop').value=g_byID('cutter').offsetTop-(pict*1)-170;
		
		// IE 7
		version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		if(version>6)
			g_byID('cornerLeft').value=(g_byID('cornerLeft').value*1)+59;
		//
	}
	
	
	}
	
}

function change_sex(val)
{
	document.getElementById('sex_0').style.display='none';
	document.getElementById('sex_1').style.display='none'; 
	document.getElementById('sex_'+val).style.display='';
	
	if (val=='0')
		document.getElementById('sex_caut').value='1';
	else document.getElementById('sex_caut').value='0';
	
	document.getElementById('sex_looking_0').style.display='none';
	document.getElementById('sex_looking_1').style.display='none'; 
	document.getElementById('sex_looking_'+document.getElementById('sex_caut').value).style.display='';
}

function change_sex2(val)
{
	document.getElementById('sex_looking_0').style.display='none';
	document.getElementById('sex_looking_1').style.display='none'; 
	document.getElementById('sex_looking_'+val).style.display='';
	
	if (val=='0')
		document.getElementById('sex_eu').value='1';
	else document.getElementById('sex_eu').value='0';
	
	
	document.getElementById('sex_0').style.display='none';
	document.getElementById('sex_1').style.display='none'; 
	document.getElementById('sex_'+document.getElementById('sex_eu').value).style.display='';
	
	
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",500)
}
window.onload = startBlink;

function check_uncheck(check)
{
	if(g_byID('check_all').value==0)
	{
			checkAll();
			g_byID('check_all').value=1;
			g_byID('check_sus').checked=true;
			g_byID('check_jos').checked=true;
	}
	else{
		uncheckAll();
		g_byID('check_all').value=0;
		g_byID('check_sus').checked=false;
		g_byID('check_jos').checked=false;
	}
}


function over(param)
{
	setTimeout("overlib(param,WRAP, VAUTO)",300);
}

function selectAccountType(tid)
{
	if(tid==1)
	{
		show('persoana_fizica');
		hide('idmagazin');
	}
	else{
		hide('persoana_fizica');
		show('idmagazin');
	}
}

function get_get222(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
      return getstr;
   }
   
   function get_get(obj)
   {
	   var getstr="?";
	   arr=obj.split('|');
	   for(i=0;i<arr.length;i++)
	   {
		   //	alert(arr[i]);
		   	byname=document.getElementsByName(arr[i]);
		   	curel=byname[(byname.length-1)];
		    
/*			if(curel.name=='description') curel=document.getElementsByName(arr[i])[1];
			if(curel.name=='email') curel=document.getElementsByName(arr[i])[1];
			if(curel.name=='password') curel=document.getElementsByName(arr[i])[1];
*/			
			aux=curel.value;
			curel.value=aux.replace('+','');
			
			if (curel.tagName == "TEXTAREA") {
				getstr += curel.name + "=" + escape(curel.value) + "&";
				
			}
			
			if (curel.tagName == "INPUT") {
			if (curel.type == "hidden") {
               getstr += curel.name + "=" + escape(curel.value) + "&";
            }
            if (curel.type == "text" || curel.type == "password") {
               getstr += curel.name + "=" + escape(curel.value) + "&";
            }
            if (curel.type == "checkbox") {
               if (curel.checked) {
                  getstr += curel.name + "=" + escape(curel.value) + "&";
               } else {
                  getstr += curel.name + "=&";
               }
            }
            if (curel.type == "radio") {
               if (curel.checked) {
                  getstr += curel.name + "=" + escape(curel.value) + "&";
               }
            }
         }   
         if (curel.tagName == "SELECT") {
            var sel = curel;
            getstr += sel.name + "=" + escape(sel.options[sel.selectedIndex].value) + "&";
         }
		   
		   
	
		
	   }
		return getstr;
   }

function hideSelects(action) {
//documentation for this script at http://www.shawnolson.net/a/1198/hide-select-menus-javascript.html
//possible values for action are 'hidden' and 'visible'
if (action!='visible'){action='hidden';}
if (navigator.appName.indexOf("MSIE")) {
for (var S = 0; S < document.forms.length; S++){
for (var R = 0; R < document.forms[S].length; R++) {
if (document.forms[S].elements[R].options) {
document.forms[S].elements[R].style.visibility = action;
}
}
}
}
}


function showSelects(action) {
//documentation for this script at http://www.shawnolson.net/a/1198/hide-select-menus-javascript.html
//possible values for action are 'hidden' and 'visible'
if (action!='hidden'){action='visible';}
if (navigator.appName.indexOf("MSIE")) {
for (var S = 0; S < document.forms.length; S++){
for (var R = 0; R < document.forms[S].length; R++) {
if (document.forms[S].elements[R].options) {
document.forms[S].elements[R].style.visibility = action;
}
}
}
}
}


function closeMessage()
{
	g_byID('errordiv').style.display='none'; showSelects('visible');	
}

function sendForm()
{
	//alert(g_byID('errordiv').innerHTML);
	val=g_byID('errordiv').innerHTML;
	if(val.length<2)
			g_byID('form11').submit();
	else{ setTimeout('sendForm()',500);
	}
}


function submit_form(fid,obj,filename)
{
	hideSelects('hidden');
	position_center('errordiv');
	g_byID('errordiv').style.display='block';
	p=new Image();
	p.src='/imagini/loading.gif';
	g_byID('errordiv').innerHTML='<img src="'+p.src+'" border="0">';
	get=get_get(obj);

	if(ajax_get('/includes/ajaxdo/'+filename+get,'errordiv'))	
	{
		setTimeout('sendForm()',900);
		
	}
	
	
}

function countChars() {
if(document.form11.description.value.length>1500) {
document.form11.description.blur();
document.form11.lungime.value =0;
alert("Ati atins numarul maxim de caractere permis!");
}
else document.form11.lungime.value =
1500-document.form11.description.value.length;
if (document.form11.lungime.value==0) {
var text=document.form11.description.value
document.form11.description.value=text.substr(0,1500);
}
}

function sendForm2(val)
{
	if(val=='delete')
		if(confirm('Esti sigur ca vrei sa stergi?'))
		{
			g_byID('action').value=val;
			g_byID('form1').submit();
		}
		else{}
	else{
			g_byID('action').value=val;
			g_byID('form1').submit();	
	}
	return true;
}

function position_center(id)
	{
		
		var scrol=getScrollXY();
		var wi,he;
		var el;
		
		el=document.getElementById(id);
		
		we=el.offsetWidth;
		he=el.offsetHeight;
		
		we=250;
		he=100;

		alertSize();
		
		if (navigator.appName == "Microsoft Internet Explorer")
		{	
			var comm_left=screenSizeW/2-we + 1*scrol[0];
			var comm_top=screenSizeH/2-he + 1*scrol[1];
			
		}
		else{
			var comm_left=screenSizeW/2-we + 1*scrol[0];
			var comm_top=screenSizeH/2-he + 1*scrol[1];
		}
		
		//alert(screenSizeW+','+screenSizeH);
		el.style.top=comm_top + 'px';
		el.style.left=comm_left + 'px';
		return true;
	}
	
	function alertSize() {
		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		//  window.alert( 'Width = ' + myWidth );
		 // window.alert( 'Height = ' + myHeight );
		  screenSizeW=myWidth;
		  screenSizeH=myHeight;
		}

	function getScrollXY() {
		  var scrOfX = 0, scrOfY = 0;
		  if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		  }
		  return [ scrOfX, scrOfY ];
		}
	
	function on_load(lng)
	{
			
	//	ajax_get('/includes/ajaxdo/getMenu.php?menu=0&lng_code='+lng,'menu_holder');
	}
	
	function nolink()
	{
		
	}
	
	function switchMenu(nr,lng)
	{
		ajax_get('/includes/ajaxdo/getTMenu.php?menu='+nr+'&lng_code='+lng,'tmenu_holder');
		for(i=0;i<4;i++)
			hide('menu'+i);
		
		show('menu'+nr);
	}