function profileChangePhoto(item){		
	jQuery('#profile_photo_container a').hide()
	jQuery('#'+item).show();
}

function checkBrowser(){
	if(x.appName=="Opera")document.getElementById('cc').style.display="block";
	else document.getElementById('cc').style.display="table";
}

function fillSelectBox( idName, valuesString, textString ) {
	var selectBox=document.getElementById(idName);
	count=0;
	valuesArray = valuesString.split(',');
	textArray = textString.split(','); 
	for(var i=1; i<=valuesArray.length; i++) {
		selectBox.options[i]=new Option(textArray[count], valuesArray[count]);
		count++;
	}
}
	
function checkFormEmailReply(id, text){
	if(document.getElementById(id).value.length < 1 ){
		alert(text);
		return false;
	}
	return true;
}	
	
function divObj(txt, event){
	if (!event)event=window.event;
	day=document.getElementById("divO");
	if(event.type.toLowerCase()=="mouseout")
		day.style.display="none";
		else day.style.display="block";
	day.style.left=(event.clientX-150)+document.body.scrollLeft;
	day.style.top=(event.clientY+10)+document.body.scrollTop;
	day.innerHTML=txt;
}

function disableLocations() {
	//var tmp = eval("document.reg_form.info[location]");
	//alert( 'ajajai' );
	var location = parseInt(document.getElementById("location").value);
	//alert( location );
	if( location == 0 ) {
		document.getElementById("location2").disabled = true;
		document.getElementById("location3").disabled = true;
		document.getElementById("location2").value = 0;
		document.getElementById("location3").value = 0;
	} else {
		document.getElementById("location2").disabled = false;
		document.getElementById("location3").disabled = false;
	}
	return true;
}

function flip(rid) {
	var current;
	current=(document.getElementById(rid).style.display != 'block') ? 'block' : 'none';
	document.getElementById(rid).style.display = current;
}

function hideItem(rid) {
	document.getElementById(rid).style.display = 'none';
}

function showItem(rid) {
	document.getElementById(rid).style.display = 'block';
}

function validateSelections(inputName, msg) {
  var maxQuestion = parseInt(eval("document.ChooseClosedQuestionForm."+inputName).length);
  var check;
  var total = 0;
  for (var idx = 0; idx < maxQuestion; idx++) {
    check = eval("document.ChooseClosedQuestionForm."+inputName+"[" + idx + "]");
  
    if (check != null && check.checked == true) {
      total++;  
    }
  }
  
  if(total < 5)  {
    alert(msg);
    return false;
  }
  
  return true;
}

function highlightSelected(countfield)  {
	var maxQuestion = parseInt(eval("document.ChooseClosedQuestionForm.chosenQuestions").length);
	var check;
	var inputSrcID;
	var total = 0;
	for (var idx = 0; idx < maxQuestion; idx++) {
  	check = eval("document.ChooseClosedQuestionForm.chosenQuestions[" + idx + "]");
  	if (check != null && check.checked == true) {
     	inputSrcID = 'EH' + idx;
    	changeLabelForSrc(inputSrcID);
    	total++;  
  	}
    eval("document.ChooseClosedQuestionForm."+countfield+"1").value = total;
    eval("document.ChooseClosedQuestionForm."+countfield+"2").value = total;
	}
	return true;
}


function checkCount(checkID, countfieldID, maxCount, msgText) {
  var total = parseInt(document.getElementById(countfieldID).value);
  if(total == null) {
    total = 0;
  }

  if (document.getElementById(checkID).checked == true) {
    //error msg
    if(total == maxCount) {
      alert(msgText); 
      return false;
    }
    total++;
  }
  else {
  
    total--;
  }

  //update count
  if(total >= 0) {
    document.getElementById(countfieldID).value = total;
    //eval("document.ChooseClosedQuestionForm."+countfield+"2").value = total;
  }
  //update label
  //changeLabelForSrc(inputSrcID);
  return true;
}

function checkQuestionsForm( countFieldID, minCount, maxCount, msgText ) {
	alert('a');
	return false;
	var countQ = document.getElementById(countFieldID).value;
	if( countQ >= minCount && countQ <= maxCount ) {
		return true;
	} else {
		alert( msgText );
		return false;
	}
}

function makeChecked( fieldID ) {
	document.getElementById(fieldID).checked=true;
	//alert(fieldID);
	return true;
}

function makeUnchecked( fieldID ) {
	document.getElementById(fieldID).checked=false;
	//alert(fieldID);
	return true;
}

function checkClosedAnswersForm( questionsCount, msgText ) {
	var answer;
	var idName;
	var testFunc='';
	
	for (var i=1;i<=5;i++) {
		answer=null;
		for (var i2=1;i2<=10;i2++) {
			idName = "q"+i+"_"+i2;
			var obj=document.getElementById(idName);
			if (obj != null && document.getElementById(idName).checked == true) {answer = document.getElementById(idName).value;}
			idNameOpen = "q"+i+"_open";
			if( document.getElementById(idNameOpen).checked == true ) {
				idNameOpenAnswer = idNameOpen = "q"+i+"_open_answer";
				openAnswer = document.getElementById(idNameOpenAnswer).value;
				//alert( openAnswer.length );
				if( openAnswer.length > 0 ) answer="open";
			}
		}
		if( answer==null ) {
			alert(msgText);
			return false;
		}
	}
	return true;
}

function textCounter( fieldID, texCounterID, countFieldID, maxChars, maxQuestions, msgSelectedQuestions, msgTextInput ) {

  var currentLength = document.getElementById(fieldID).value.length;
  var charCount = document.getElementById(texCounterID).value;
  
  if( countFieldID!== false ) {
	  var countSelected = document.getElementById(countFieldID).value;
	  
	  // if the user already has max questions selected/typed alert error
	  if( countSelected == maxQuestions && charCount == maxChars )  {
	    alert( msgSelectedQuestions );
	    document.getElementById(fieldID).value = '';
	    document.getElementById(countFieldID).value = maxQuestions;
	    return false;
	  }
	  
	  //the field was just cleared
	  if( currentLength == 0 && charCount != maxChars )  {
	  	countSelected--;
	  	document.getElementById(countFieldID).value = countSelected;
	  }
	  //this is the first text being typed in or 
	  else if( charCount == maxChars && currentLength > 0)  {
	  	countSelected++;
	  	document.getElementById(countFieldID).value = countSelected;
	  }
	}
  
  charCount = maxChars - currentLength;
  if (charCount > 0) {
    document.getElementById(texCounterID).value = charCount;
  } else {
    document.getElementById(texCounterID).value = 0;
  }

  if ( currentLength > maxChars ) {
    alert( msgTextInput );
    document.getElementById(fieldID).value = document.getElementById(fieldID).value.substring( 0, maxChars );
    return false;
  }
  
  return true;
}

function checkOpenAnswersForm( fieldIDstring, questionsCount, msgEmptyFields ) {
	var fieldValueLength = 0;
	var fieldID;
	for( $i = 1; $i <= questionsCount; $i++ ) {
		fieldID = fieldIDstring+$i;
		var obj=document.getElementById(fieldID);
		if( obj != null ) {
			fieldValueLength = document.getElementById(fieldID).value.length;
			if( fieldValueLength <= 0 ) {
				alert( msgEmptyFields );
				return false;
			}
		}
	}
	return true;
}

//check form if no required fields left empty
function checkFormEmailSend( fields, msgEmpty ) {	
	
	
	var fieldsArray = fields.split( "," );					
	
	
	var i = 0;
	for(var i=0; i<fieldsArray.length; i++ ) {		
		var obj=document.getElementById(fieldsArray[i]);						
		if(document.getElementById(fieldsArray[i]).value.length <=0  ) {						
			alert( msgEmpty );
			return false;
		}
	}	
	
	return true;		
}

function redirect( mainLink, subLinkFieldID ) {
	var link;
	var subLink;
	subLink = document.getElementById(subLinkFieldID).value;
	link = mainLink + subLink;
  window.location.assign( link );
	return true;
}


  function disableNoMatterCheckbox(){
    var reg_form="";
         if(document.ed_form)reg_form=document.ed_form;
         else if(document.reg_form)reg_form=document.reg_form;
         else return;
    for(var i=0; i<reg_form.elements.length; i++){
       if(reg_form.elements[i].type=='checkbox' && reg_form.elements[i].value=='not_important'){
             checkName=reg_form.elements[i].name;
             setId=reg_form.elements[i].id=checkName;
             document.getElementById(setId).onclick=function(){
                 if(this.checked) allCheckBox(this.name, false);
		 else allCheckBox(this.name, true);
	      }

	      if(reg_form.elements[i].checked)allCheckBox(checkName, false);
      }
    }

  }



  function allCheckBox(chk, bool){
  var reg_form=document.ed_form?document.ed_form:document.reg_form;
    for(var i=0; i<reg_form.elements.length; i++){
       if(reg_form.elements[i].type=='checkbox' && reg_form.elements[i].value!='not_important'){
              if(chk==reg_form.elements[i].name){
                  if(bool!=true){
		  reg_form.elements[i].disabled=true;
		  reg_form.elements[i].checked=false;
		  }
		  else reg_form.elements[i].disabled=false;

	      }
       }
    }
  }
function handleError(){
   return true;
}
window.onerror= handleError;

function createOption(includedElm, optValue){
	var opt = document.createElement("option");
	opt.setAttribute("value",optValue);
	opt.appendChild(document.createTextNode(optValue));
	includedElm.appendChild(opt);
}

function clearAll(el){
	while(el.hasChildNodes())
			el.removeChild(el.firstChild);
}

function getUsedNumbers(selArgs){
	mas = new Array();	
	for(i=0; i<selArgs.length; i++){
		elm = document.getElementById(selArgs[i]);
		if(elm.selectedIndex > -1)
			if(elm.options[elm.selectedIndex].value.length > 0)
				mas.push(elm.options[elm.selectedIndex].value);
		}
	return mas;			
}

function trimAll(){
	var colors = Array ("color1", "color2", "color3", "color4", "color5", "color6", "color7", "color8");
	for(i=0; i<colors.length; i++){
		var elm = document.getElementById(colors[i]);
		clearAll(elm);
		createOption(elm, '');	
		for(y=0; y<colors.length; y++)
			createOption(elm, y+1);
	}
}


function trimAllStep5(){
	var colors = Array ("geometric[1]","geometric[2]","geometric[3]","geometric[4]","geometric[5]");
	for(i=0; i<colors.length; i++){
		var elm = document.getElementById(colors[i]);
		clearAll(elm);
		createOption(elm, '');	
		for(y=0; y<colors.length; y++)
			createOption(elm, y+1);
	}
}

function submitForm(form){
	var colors = Array ("color1", "color2", "color3", "color4", "color5", "color6", "color7", "color8");
	var error = false;
	for(i=0; i<colors.length; i++){
		var elm = document.getElementById(colors[i]);
		if(elm.options[elm.selectedIndex].value.length == 0)
			error = true;
	}
	if(!error)
		form.submit();
	else
		alert(document.getElementById('error_field').value);

}

function submitForm5(form,error_str){
	var colors = Array ("geometric[1]","geometric[2]","geometric[3]","geometric[4]","geometric[5]");
	var error = false;
	for(i=0; i<colors.length; i++){
		var elm = document.getElementById(colors[i]);
		if(elm.options[elm.selectedIndex].value.length == 0)
			error = true;
	}
	if(!error)
		form.submit();
	else
		alert(error_str);

}


function selectorChange5(my){
	var colors = Array ("geometric[1]","geometric[2]","geometric[3]","geometric[4]","geometric[5]");
	var vv = getUsedNumbers(colors);	
	for(i=0; i<colors.length; i++){	
		var elm = document.getElementById(colors[i]);
		if (elm.selectedIndex > -1){
			var before = elm.options[elm.selectedIndex].value;
			if(before.length < 1)
				before = null;			
		}	
		clearAll(elm);				
		createOption(elm, '');				
		for(y=1; y < colors.length+1; y++)
			if(!in_array(vv,y) || (before != null && before == y))
				createOption(elm, y);		
		if(before)		
			for(y=0; y<elm.options.length; y++)		
				if(elm.options[y].value == before)
					elm.selectedIndex = y;
					
	}			
}

function selectorChange(my){
	var colors = Array ("color1", "color2", "color3", "color4", "color5", "color6", "color7", "color8");
	var vv = getUsedNumbers(colors);		
	for(i=0; i<colors.length; i++){	
		var elm = document.getElementById(colors[i]);
		if (elm.selectedIndex > -1){
			var before = elm.options[elm.selectedIndex].value;
			if(before.length < 1)
				before = null;			
		}	
		clearAll(elm);
				
		createOption(elm, '');	
			
		for(y=1; y < colors.length+1; y++)
			if(!in_array(vv,y) || (before != null && before == y))
				createOption(elm, y);
		
		if(before)		
			for(y=0; y<elm.options.length; y++)		
				if(elm.options[y].value == before)
					elm.selectedIndex = y;
					
	}		
}

function in_array(v, datum, strict) {
    if (strict) function equals(a,b) { return a === b }
    else function equals(a,b) { return a == b }
    for (var i in v) {
        if (equals(v[i], datum)) return true;
    }
    return false;
}


function getElementsByName_fix(tag, name) {    
	var j = jQuery.noConflict();	
	return j.makeArray(j(tag+'[name*="'+name+'"]'));
	 
	 /*var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;*/
}

function checkForm4(form, arg){
	var complitedFields = 0;		
	for(s=1; s<31; s++){
		var elmMas = getElementsByName_fix('input',arg+'[question'+s+']');				
		for(y=0;y<elmMas.length; y++)
			if(elmMas[y].checked == true)
				complitedFields++;		
	}
		if(complitedFields < 27)			
			alert(document.getElementById("errorText").value);
		else
			form.submit();
}

function checkForm6(form){
	var complitedFields = 0;		
	for(s=1; s<5; s++){
		var elmMas = getElementsByName_fix('input','shapes['+s+']');				
		for(y=0;y<elmMas.length; y++)
			if(elmMas[y].checked == true)
				complitedFields++;		
	}
		if(complitedFields < 4){			
			alert(document.getElementById("error_field").value);			
		}else
			form.submit();
}

function checkForm7(form){
	var complitedFields = 0;			
		var elmMas = getElementsByName_fix('input','hands');				
		for(y=0;y<elmMas.length; y++)
			if(elmMas[y].checked == true)
				complitedFields++;					
		if(complitedFields < 1){			
			alert(document.getElementById("error_field").value);			
		}else
			form.submit();
}

function noMore2(me){
	var count = 0;
	var name = me.getAttribute('name');
	var elmMas = getElementsByName_fix('input',name);	
	for(e=0; e<elmMas.length; e++)
		if(elmMas[e].checked)
			count ++;
			
		for(e=0; e<elmMas.length; e++)
			if(count > 1){
				if(!elmMas[e].checked)
					elmMas[e].setAttribute('disabled', true);
			}else
				elmMas[e].removeAttribute('disabled');								
}

function checkForm8(form){
	var complitedFields = 0;			
		var elmMas = getElementsByName_fix('input','triangles');				
		for(y=0;y<elmMas.length; y++)
			if(elmMas[y].checked == true)
				complitedFields++;					
		if(complitedFields < 1){			
			alert(document.getElementById("error_field").value);			
		}else
			form.submit();
}

function checkForm10(form){	
	var mas1 = new Array("info[duties]","info[promises]","info[mistakes]","info[control]","info[understanding]","info[habits]","info[love_power]","info[thoughts]","info[children]","info[rumours]","info[secrets]","info[competence]","info[career]","info[jokes]","info[faithfulness]","info[criticism]");	
	var complitedFields = 0;				
	for(e = 0; e<mas1.length; e++){
		var elmMas = getElementsByName_fix('input',mas1[e]);				
		for(y=0; y<elmMas.length; y++)
			if(elmMas[y].checked == true)
				complitedFields++;						
	}		
		if(complitedFields < mas1.length)			
			alert(document.getElementById("error_field").value);
		else
			form.submit();
}

function checkForm12(form){	
	var mas1 = new Array("info[education][]","info[nationality][]","info[community][]","info[marital_status][]");	
	var complitedFields = 0;				
	for(e = 0; e<mas1.length; e++){
		var elmMas = getElementsByName_fix('input',mas1[e]);				
		for(y=0; y<elmMas.length; y++)
			if(elmMas[y].checked == true)				
				complitedFields=(complitedFields|(1<<e));						
	}				
		if(complitedFields == 15)			
			form.submit();			
		else
			alert(document.getElementById("error_field").value);
}


function checkForm13(form, error_str){	
	var mas1 = new Array("info[interests][]");	
	var complitedFields = 0;				
	for(e = 0; e<mas1.length; e++){
		var elmMas = getElementsByName_fix('input',mas1[e]);				
		for(y=0; y<elmMas.length; y++)
			if(elmMas[y].checked == true)				
				complitedFields++;			
	}				
		if(complitedFields > 0){			
			if(document.getElementById('field_description').value.length < 100)
				alert(document.getElementById("error_field").value+"\n"+error_str);
			else	
				form.submit();					
		}else
			alert(document.getElementById("error_field").value);
}


function checkForm11(form){	
	var mas1 = new Array("info[frequency_rate]","info[sex_hours]","info[difficulties]","info[partners_exp]","info[sex_without_love]","info[turned_on]","info[pornography]","info[thinking]","info[intimacy]","info[experience]","info[successful]","info[partners_search]","info[names]","info[fantasies]","info[flirt]","info[pleasure]","info[ways]");		
	var complitedFields = 0;				
	for(e = 0; e<mas1.length; e++){
		var elmMas = getElementsByName_fix('input',mas1[e]);				
		for(y=0; y<elmMas.length; y++)
			if(elmMas[y].checked == true)
				complitedFields++;						
	}		
	
		if(complitedFields < mas1.length)			
			alert(document.getElementById("error_field").value);
		else{
			val = getElementsByName_fix('input','info[frequency]')[0].value;
			if(val.length == 0 || !isNumeric(val))
				alert(document.getElementById("error_field").value);
				else{
					var elm = getElementsByName_fix('select','info[first_exp]')[0];					
					if(elm.selectedIndex > 0)
						form.submit();
					else	
						alert(document.getElementById("error_field").value);
				}
					
		}	
}


function checkForm9(form){
	var mas1 = new Array("info[roles]","info[marriage_place]","info[together]","info[baby]");
	var mas2 = new Array("info[problems][]","info[marriage][]");
	var complitedFields = 0;				
	for(e = 0; e<mas1.length; e++){
		var elmMas = getElementsByName_fix('input',mas1[e]);				
		for(y=0; y<elmMas.length; y++)
			if(elmMas[y].checked == true)
				complitedFields++;						
	}		
		if(complitedFields < mas1.length){			
			alert(document.getElementById("error_field").value);			
			
		}else{
			var complitedFields = new Array(0,0);
			for(e = 0; e<mas2.length; e++){
				var elmMas = getElementsByName_fix('input',mas2[e]);				
				for(y=0; y<elmMas.length; y++)
					if(elmMas[y].checked == true)
						complitedFields[e]=y+1;						
			}
				if(complitedFields[0] > 0 && complitedFields[1] > 0  )				
					form.submit();
				else	
					alert(document.getElementById("error_field").value);			
		}
}

function checkForm2(form){	
	
	var mas1 = new Array("info[education]","info[nationality]","info[religion]","info[community]","info[occupation]","info[occupation_area]","info[marital_status]","info[children]","info[cohabitants]","info[moving]","info[accommodation]","info[income]","info[money]","info[height]","info[build]","info[eyes]","info[hair]","info[health]","info[smoking]","info[drinking]","info[drugs]");	
	
	
	var complitedFields=0;
	var el = getElementsByName_fix('input','info[languages][]');
	
	for(y=0; y<el.length; y++)
		if(el[y].checked == true)
			complitedFields++;			
			
	if(complitedFields == 0)
		alert(document.getElementById("error_field").value);			
	else 		
		form.submit();			
}

function selectChenker(id){
	document.getElementById(id).checked = true;
}

function isNumeric(expression) {
	var nums = "0123456789";
	if (expression.length==0)return(false);
	for (var n=0; n < expression.length; n++){
		if(nums.indexOf(expression.charAt(n))==-1)return(false);
	}
	return(true);
}

function editProfile(n, txt,func){
var f = n.form;
var patt = /show\[(.+)\]/;
var count=0;
for(var i=0; i<f.elements.length; i++){
 var t = f.elements[i];
   if(patt.test(t.name)==true){
		if(t.checked) count++;
   }
} 
if(count<6) alert(txt);
else f.submit();
}

function editProfileShowed(message){
	alert(message);
}

$q = jQuery.noConflict();
$q(document).ready(function(){
$q("#meet_block").click(function(){
	hideTab(this);
		d();
	setTimeout("$q.getScript('/meet_guide.js')", 1000);


			return false;
	});
});

function d(){
var userLOC = getUserId("id");
$q.get(
  '/index.php',
  {
    ajx: "meeting",
    id: userLOC
  },
  onAjaxSuccess
);
	
}
function onAjaxSuccess(data)
{
	
  var d = data;
  document.getElementById("anketa_content").innerHTML = d;
  
		return true;
}

function uncheckAll(el){
			if(el.checked) ch = true;
			else ch = false;
		var check = el.parentNode.nextSibling.getElementsByTagName("input");
			for(var i=0; i<check.length; i++){
				if(check[i].type == "checkbox") {
					check[i].checked = ch;
					/*check[i].disabled = ch;*/
				}
			}
	}

function disable_box_by_parent(p_elm,reg_u,reg_d){		
	var parent = $(p_elm).up(reg_u);		
	var elm = null;
	for(var i = 0; (elm = parent.down(reg_d,i)) != null; i++)	
	if(p_elm != elm){				
		elm.disabled = p_elm.checked;		
		if(elm.disabled)elm.checked = false;	
			
	}
	

}

function checkUsername(inUsername, outNoticeid){	
	jQuery.post("/usernamevalidator.php", {'username':inUsername},
		function(data){													
			var noticeObj = jQuery('#'+outNoticeid);			
			if(noticeObj.size() == 0) return;
			if(data)
				noticeObj.html(data).show();
			else noticeObj.hide();				
		}
	);
}
	

