function normalizeTextArea(srcElement){
    var text = srcElement.value;
    for(var i=0; i<text.length;i++){
        if(text.charAt(i)!=' '&& text.charAt(i)!='\n'){
            return;
        }
    }
    srcElement.value='';
}


function createPopUp(path){
	if(document.cookie.indexOf(is_popup_created=true)==-1){
		document.cookie="is_popup_created=true;";
		window.open(path+'/popup.html','popup',"height=20,width=20,resizable=1,scrollbars=0,toolbar=0,location=0,status=0,menubar=0");
		if((navigator.userAgent.indexOf("MSIE") == -1)){
			window.open(path+'/popup.html','popup',"height=20,width=20,resizable=1,scrollbars=0,toolbar=0,location=0,status=0,menubar=0");			
		}
    }
}

function popUp(url) 
{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin"; 
}


//function to ensure that value is between int1 and int2.
function validate(anyval,int1,int2,object,text) {
	anyval = ""+anyval
	a = 0;
	for(i=0; i<anyval.length; i++){
     	if (anyval.substring(i,i+1) < "0" || anyval.substring(i,i+1) > "9") {
		if (anyval.substring(i,i+1) == "."){a = a+1; if( a > 1){ anyval = "-1"}}
		if (anyval.substring(i,i+1) != "."){
          	anyval = "-1"}
     	}
	}
	if (anyval != ""){
	     if (anyval <int1 || anyval > int2) {
			object.value = '';	
			alert (text+" ("+int1+" - "+int2+")");		
			return false;
     	}
	}
	return true;
}

function register_form_submit()
{
    if ((document.forms.register_form.isagree1['true'].checked) && (document.forms.register_form.isagree2['true'].checked) && (document.forms.register_form.isagree3['true'].checked))
	{
		document.forms.register_form.isagree.value='true';
	}
	else
	{
		document.forms.register_form.isagree.value='false';
	}
}

//used by forms with deadlines (for example, additionalAskExpertForm)
function validatedeadline(formref, defaultdays, defaulthours, maxdays, text)
{	if (formref.deadlinetype['0'].selected)
	{	if (validate(formref.deadline.value, 0, maxdays, formref.deadline, text))
			formref.days.value = formref.deadline.value;
		else
		{	formref.days.value = defaultdays;
			formref.deadline.value = defaultdays;
		}	
	}	 
	else
	{	if (validate(formref.deadline.value, 0, maxdays*24, formref.deadline, text))
			formref.hours.value = formref.deadline.value;
		else
		{	formref.hours.value = defaulthours;
			formref.deadline.value = defaulthours;
		}								
	}	 
}

//used by forms with deadlines (for example, additionalAskExpertForm)
function changedeadlinetype(formref, defaultdays, defaulthours, maxdays, text)
{	if (formref.deadlinetype['0'].selected)
	{	formref.hours.value = formref.deadline.value;
		validate(formref.deadline.value, 0, maxdays*24, formref.deadline, text);
		formref.hours.value = 0;
	}
	else
	{	formref.hours.value = formref.deadline.value;
		validate(formref.deadline.value, 0, maxdays, formref.deadline, text);	
		formref.days.value = 0;
		}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


function invert_bool_field(field){
	if(field.value == "true")
		field.value = "false";
	else if(field.value == "false")
		field.value = "true";
}
function check_on_emptystring (field, text) {
   if (field.value == "") {                                        
     alert(text);
     return false  
   }
   else {
     return true  
   }
}

function printMain(href)
{
		print_popup=window.open(href,'print_popup',"resizable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=1");
        print_popup.window.print();
}


