﻿myArray = new Array("howmuch")
myArray["howmuch"] = new Array("how_much_fee__")
function ValidDate (currdate, toAlert) {
veryTmp=currdate
var tmpDate = currdate.split("/");
	if ((tmpDate.length < 3 && currdate !="") || tmpDate.length > 3) {
	currdate = "";}
	else if (isNaN(tmpDate[0]) || isNaN(tmpDate[1]) || isNaN(tmpDate[2])) {
		currdate = "";}
	else { 
		tmpDate[0] = GetNumFromStr (tmpDate[0])
		tmpDate[1] = GetNumFromStr (tmpDate[1])
		
		if (!(parseInt(tmpDate[1]) >0 && parseInt(tmpDate[1])<13 && parseInt(tmpDate[0]) >0 && parseInt(tmpDate[0]) <32 && 	parseInt(tmpDate[2])>1900 && parseInt(tmpDate[2])<2050 && ValidDateForMonth (tmpDate[0], tmpDate[1],tmpDate[2]))) {
			currdate = "";
		}
		else {			
			var r1,r2;
			r1=""; r2=""
			if (parseInt(tmpDate[0]) < 10) {r1 = "0";}
			if (parseInt(tmpDate[1]) < 10) {r2 = "0";}
			currdate = r1+parseInt(tmpDate[0]) + "/" + r2 + parseInt(tmpDate[1]) + "/" + parseInt(tmpDate[2])
			var f=ValidDateForMonth(parseInt(tmpDate[0]),parseInt(tmpDate[1]),parseInt(tmpDate[2]))		
		}
	}
	if (currdate == "" && toAlert) {alert("You must enter a valid date format: DD/MM/YYYY. Please, go back and try again. Thank you!")}
return currdate;
}
function GetNumFromStr (str) {
	var pos=str.indexOf("0")
	if (pos == 0 ) {str = str.substring(1,str.length);}
return str;
}

function ValidDateForMonth (dayIs, monthIs,yearIs) {
var mDays= new Array (31,28,31,30,31,30,31,31,30,31,30,31)
if (parseInt(yearIs) % 400 == 0 ) {mDays[1]=29;}
if (parseInt(yearIs) % 4 == 0 && parseInt(yearIs) % 100 != 0) {mDays[1]=29;}

if (parseInt(dayIs)>mDays[parseInt(monthIs)-1]) {return false;}
else {return true;}
}	
function calendar(t,fromyear,toyear,GW)
{
elementname=t.name;

currdate=window.document.getElementsByName(elementname)[0].value;
tmpCurrdate = ValidDate (currdate,false)
if (tmpCurrdate!=currdate) {
window.document.getElementsByName(elementname)[0].value=tmpCurrdate;
currdate = tmpCurrdate;
}
wnd = window.open('/MakeCalendar.asp?elementname='+elementname+'&fromyear='+fromyear+'&toyear='+toyear+'&currdate='+currdate+'&quest='+GW,'Calendar','toolbar=no,width=410,height=250,resizable=yes',true);

if (!wnd.closed) {wnd.focus();}
}
function rollover(atag) {
	var node;
	if (!atag.nodeName) {
		return true;
	} 
	
	// Buttons
	if (atag.nodeName == 'INPUT') {
		if (atag.className == 'button') { atag.className = 'button-hover'; } 
		else if (atag.className == 'button-hover') {atag.className = 'button'; } 
	}
	
	// image rollovers
	for (i = 0; i < atag.childNodes.length; i++) {
    node = atag.childNodes[i];
    if (node.nodeName == 'IMG') {
      if (node.src.indexOf('1') != -1) { node.src = node.src.replace('1.', '2.');}	
	  else { node.src = node.src.replace('2.','1.');}
    }
  }
}

function OnOver(img,type) {
img.src = img.src.substring(0,img.src.length-5)+'2.'+type;
}

function OnOut(img,type) {
img.src = img.src.substring(0,img.src.length-5)+'1.'+type;
}

function check_fields(form_data) {
alertCheck = 0
for(i = 0; i < form_data.elements.length; i++)
 {
  atPos = form_data.elements[i].name.indexOf("__",1)
  if(atPos != -1)
   {
	form_data.elements[i].parentNode.parentNode.style.color = "";
    if(form_data.elements[i].value=="" || ((form_data.elements[i].type=="checkbox") && (!form_data.elements[i].checked))	)
   {
	alertCheck=alertCheck+1;
	   form_data.elements[i].parentNode.parentNode.style.color = "#D1182D";
	   
	}else if(form_data.elements[i].type=="radio") {
		if((check_fields_radio_PP(form_data.elements[i].name)) == false) {
			alertCheck=alertCheck+1;
			   form_data.elements[i].parentNode.parentNode.style.color = "#D1182D";
		}
   }

 }
}

if (alertCheck > 0) { alert("Please complete all required fields marked with red asterix."); return false; } 

 //validizaciq za popylvane na formata samo s latinski bukvi i cifri
	for(i = 0; i < form_data.elements.length; i++) {
		//alert(form_data.elements[i].type);
		if (form_data.elements[i].type == "text" || form_data.elements[i].type == "textarea") {
			str = form_data.elements[i].value;
			//alert(str);
			check=str.replace(eval(/[a-zA-Z0-9{`| |!|@|$|%|&|*|\n|\t|\r|\(|\)|-|?|\\|\.|\"|\:|\;|\-|\_|\/|\~|\#|\^|\'|\<|\>|\=|\[|\]|+|,|£|¥|₣|₤|€|日|月|年}]+/),"");
			if(check.length > 0){
				check = check.substr(0,1);
				//alert(str);  //check the field which returns the false value
				alert("Please fill in the form with Latin characters only! \n " + "You have entered non-Latin character '" +check+ "'");
				return false
			}
		}
	}
 //
return true
}

function check_fields_all_symbols(form_data) {

alertCheck = 0

for(i = 0; i < form_data.elements.length; i++)
 {
		 //alert(form_data.elements[i].name);
  atPos = form_data.elements[i].name.indexOf("__",1)
	if(atPos != -1)
	{
		form_data.elements[i].parentNode.parentNode.style.color = "";
		if(form_data.elements[i].value=="" || ((form_data.elements[i].type=="checkbox") && (!form_data.elements[i].checked))	)
		{
			alertCheck=alertCheck+1;
			form_data.elements[i].parentNode.parentNode.style.color = "#D1182D";
	   
		}else if(form_data.elements[i].type=="radio") {
			if((check_fields_radio_PP(form_data.elements[i].name)) == false) {
				alertCheck=alertCheck+1;
				form_data.elements[i].parentNode.parentNode.style.color = "#D1182D";
			}
		}

	}
}
if (alertCheck > 0) { alert("Please complete all required fields marked with red asterix."); return false; } 
return true
}

function check_fields_radio_PP(radioar) {
//alert(radioar);
var bul = 0
	if (document.forms['RegFrm'].elements[radioar].length != null) {
		for (j=0;j<document.forms['RegFrm'].elements[radioar].length;j++)
		{
			if (document.forms['RegFrm'].elements[radioar][j].checked)
			{	
				bul = 1;
			}
		}
	} else {
		if (document.forms['RegFrm'].elements[radioar].checked)
		{
			bul = 1;
		}
	}
if (bul > 0) { 
	return true; 
}
//var regexp = /_/g
//user_input2 = document.forms['RegFrm'].elements[radioar].name;
//user_input2 = user_input2.replace(regexp," ");
//user_input = "Please, go back and choose the " + user_input2;
//alert(user_input);
return false;
}

function check_fields_1(form_data) {
		for(var j = 0; j < DivArr.length; j++){
			try
			{
				if(document.getElementById(DivArr[j]).style.display == "none"){
					for(var i = 0; i < DivArr[j].length; i++){
						document.getElementsByName(myArray[DivArr[j]][i]).item(0).disabled = true;
					}
				}
			}
			catch(err)
			{
			} 

		}
	
  for(i = 0; i < form_data.elements.length; i++)
 {
  atPos = form_data.elements[i].name.indexOf("__",1);
  if(atPos != -1)
   {
    if(form_data.elements[i].value=="" && form_data.elements[i].disabled==false)
    {
	   if(form_data.elements[i].style.display != "none"){
		    alert("Ooops, It seems like you have not completed all the mandatory fields (these are marked with red asterix). Please, go back and try again. Thank you! ");
		    form_data.elements[i].focus();
		    return false;
	   } else {
		   
	   }
    }
   }
 }
 //validizaciq za popylvane na formata samo s latinski bukvi i cifri
	for(i = 0; i < form_data.elements.length; i++) {
		//alert(form_data.elements[i].type);
		if (form_data.elements[i].type == "text" || form_data.elements[i].type == "textarea") {
			str = form_data.elements[i].value;
			//alert(str);
			//check=str.replace(eval(/[a-zA-Z0-9{`| |!|@|$|%|&|*|\(|\)|-|?|\\|\.|\"|\:|\;|\-|\_|\/}]+/),"");
			check=str.replace(eval(/[a-zA-Z0-9{`| |!|@|$|%|&|*|\n|\t|\r|\(|\)|-|?|\\|\.|\"|\:|\;|\-|\_|\/|\~|\#|\^|\'|\<|\>|\=|\[|\]|+|,|£|¥|₣|₤|€|日|月|年}]+/),"");
			if(check.length > 0){
				check = check.substr(0,1);
				//alert(str);  //check the field which returns the false value
				alert("Please fill in the form with Latin characters only! \n " + "You have entered non-Latin character '" +check+ "'");
				return false
			}
		}
	}
 //
return true
}

function check_fields_radio(radioar) {

var bul = 0;
if(typeof(document.forms[0].elements[radioar]) != "undefined")
for (i=0;i<document.forms[0].elements[radioar].length;i++)
{
	if (document.forms[0].elements[radioar][i].checked)
	{	
	    bul = 1;			
	}
}
else bul=1;
if (bul > 0) { 
	return true; 
}
var regexp = /_/g
user_input2 = document.forms[0].elements[radioar][0].name
user_input2 = user_input2.replace(regexp," ")
user_input = "Please, go back and choose the " + user_input2;
//alert(user_input);
return false;
}

function ValidateEmail(theinput)
{
	s=theinput.value
	if(s.search)
	{
		return (s.search(new RegExp('^([-!#$%&\'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&\'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}$','gi'))>=0)
	}
	if(s.indexOf)
	{
		at_character=s.indexOf('@')
		if(at_character<=0 || at_character+4>s.length)
			return false
	}
	if(s.length<6)
		return false
	else
		return true
}

function validEmail(email) {
	wrong = ValidateEmail(email)
if (wrong == false){alert("You must enter a valid e-mail address. Please, go back and try again. Thank you!"); email.value=""; return false}
return true
}

/*
function validEmail(email) {
  email1=email.value;
  wrong=0;
  atPos = email1.indexOf("@",1)
  if (atPos == -1){wrong=1}
  if (email1.indexOf("@",atPos+1) > -1){wrong=1}
  periodPos = email1.indexOf(".",atPos)
  if (periodPos == -1){wrong=1}
  if (periodPos+3 > email1.length){wrong=1}
if (wrong != 0){alert("You must enter a valid e-mail address. Please, go back and try again. Thank you!"); email.value=""; return false}
return true
}
*/

function showhidedivelements(curdivelement,flg){
	if(flg == 1){
		document.getElementById(curdivelement).innerHTML = "";
	}
	else{
		document.getElementById(curdivelement).innerHTML = eval(curdivelement);
	}
}

function showhidedivelementsStyle(curdivelement,flg){
	if(flg == 1){
		document.getElementById(curdivelement).style.display = "none";
	}
	else{
		document.getElementById(curdivelement).style.display = "";
	}
}

function showhidedropdown(curdivelement,elemvalue,elemname){
var oElem = document.getElementsByName(elemname);
var elementValue = document.forms['RegFrm'].elements[elemname].options[oElem.item(0).selectedIndex].value; 

	if (elementValue != elemvalue) {
		document.getElementById(curdivelement).innerHTML = "";
	}
	else{
		document.getElementById(curdivelement).innerHTML = eval(curdivelement);
	}
}
//////////////////////////////////
div_array = new Array();
/*
function showhideIT(checkElement){
	for (var i=0; i < div_array.length; i++) {
		//if (checkElement.name == "bank_a") { alert(checkElement.name+" => "+checkElement.value); }
		//alert("if (div_array["+i+"]["+checkElement.name+"] == "+checkElement.value+"){"+checkElement.name);
		//alert(checkElement.name);
		var type = checkElement.type;
		if ((div_array[i][checkElement.name] == checkElement.value && type != "checkbox") || (checkElement.checked && div_array[i][checkElement.name] == checkElement.value && type == "checkbox")){
			for(var property in div_array[i]) {
			   var value = div_array[i][property];
			   if (property != checkElement.name) {
				   document.getElementById(property).style.display="";
				   document.getElementById(property).innerHTML = div_array[i][property];
			   }
			}
		} else {
			for(var property in div_array[i]) {
				var value = div_array[i][property];
				if (property != checkElement.name) {
						alert(property);
				   document.getElementById(property).style.display="none";
				   document.getElementById(property).innerHTML = "";
				}
			}
		}
	}
}
*/

function showhideIT_old(checkElement){
	var action = -1;
	//searching the array ID for which the function was called
	for (var i=0; i < div_array.length; i++) {
		for(var prop in div_array[i]){
			if(prop == checkElement.name){
				action = i;
				break;
			}
		}
	}
	if (action >= 0){
		var type = checkElement.type;
		//if the value writed in the div is the same with the current value of the field it shows it
		//if the value writed in the div is NOT the same with the current value of the field it hides it
		//za sega v array-a se zapisvat 2 property-ta. 1-voto e imeto na cykalkata sys stionost za pokazvane na div-a, a 2-roto e imeto na diva sys stoinost negoviq innerHTML.
		//if-a hva6ta stoinostite za dropdown, radio, checkbox 
		if ((div_array[action][checkElement.name] == checkElement.value && type != "checkbox") || (checkElement.checked && div_array[action][checkElement.name] == checkElement.value && type == "checkbox")){
			for(var property in div_array[action]) {
			   var value = div_array[action][property];
			   //setva property da e ravno na id-to na div-a, za da moje da go pokaje.
			   if (property != checkElement.name) {
				   document.getElementById(property).style.display="";
				   document.getElementById(property).innerHTML = div_array[action][property];
			   }
			}
		} else {
			for(var property in div_array[action]) {
				var value = div_array[action][property];
				//setva property da e ravno na id-to na div-a, za da moje da go skrie.
				if (property != checkElement.name) {
				   document.getElementById(property).style.display="none";
				   document.getElementById(property).innerHTML = "";
				}
			}
		}
	}
}

function hidefirstIT_oldP(selName, divName, valShow) {
	var p, splArr;
	var curEll = document.RegFrm.elements[selName];
	var valInnerHtml = 	document.getElementById(divName).innerHTML;
		
		if (typeof(valShow) != "string") {
			valShow = valShow.toString(10);
		}
		
		splArr = valShow.split(";"); 
		
		document.getElementById(divName).style.display = "none"; 
		document.getElementById(divName).innerHTML = "";
	
	for ( p=0; p<splArr.length; p++) {
		//alert(splArr[p]+" - "+ curEll.options[document.getElementsByName(selName).item(0).selectedIndex].value );
		if(curEll.options[document.getElementsByName(selName).item(0).selectedIndex].value == splArr[p]) {
			document.getElementById(divName).style.display = ""; 
			document.getElementById(divName).innerHTML = valInnerHtml;
		}
	}
}

function hidefirstIT(selName, divName, valShow) {
	var p, splArr, checkedElm;
	var curEll = document.RegFrm.elements[selName];
	var len = curEll.length;
	var valInnerHtml = 	document.getElementById(divName).innerHTML;
		
		if (typeof(valShow) != "string") {
			valShow = valShow.toString(10);
		}
		
		splArr = valShow.split(";"); 
		splArr_vv = valShow.split("#"); 
	
	if (valShow.indexOf("-") >= 0 ) {	

		for ( p=0; p<splArr_vv.length; p++) {
			for (k=0; k<len; k++) {
				if (curEll[k].checked) {
					checkedElm = curEll[k].value;
				}
			}
			if (!checkedElm) {
				for (k=0; k<len; k++) {
				if (curEll[k].selected) {
					checkedElm = curEll[k].value;
				}
			}
			}
			//alert(checkedElm + "   "+ splArr_vv[p]);
			if(checkedElm == splArr_vv[p].replace("-","")) {
			
				document.getElementById(divName).style.display = "none"; 
				document.getElementById(divName).innerHTML = "";
			}
		}
	} 
	
	if (valShow.indexOf("-") == -1) {
		
		document.getElementById(divName).style.display = "none"; 
		document.getElementById(divName).innerHTML = "";
	
		for ( p=0; p<splArr.length; p++) {
			for (k=0; k<len; k++) {
				if (curEll[k].checked) {
					checkedElm = curEll[k].value;
				}
			}
			if (!checkedElm) {
				for (k=0; k<len; k++) {
				if (curEll[k].selected) {
					checkedElm = curEll[k].value;
				}
			}
			}
			if(checkedElm == splArr[p]) {
				document.getElementById(divName).style.display = ""; 
				document.getElementById(divName).innerHTML = valInnerHtml;
			}
		}
	}
}

function hidefirstIT2(selName, divName, valShow) {
	var p, splArr, checkedElm;
	var curEll = document.RegFrmX.elements[selName];
	var len = curEll.length;
	var valInnerHtml = 	document.getElementById(divName).innerHTML;
		
		if (typeof(valShow) != "string") {
			valShow = valShow.toString(10);
		}
		
		splArr = valShow.split(";"); 
		
		document.getElementById(divName).style.display = "none"; 
		document.getElementById(divName).innerHTML = "";
	
	for ( p=0; p<splArr.length; p++) {
		for (k=0; k<len; k++) {
			if (curEll[k].checked) {
				checkedElm = curEll[k].value;
			}
		}
		if (!checkedElm) {
			for (k=0; k<len; k++) {
			if (curEll[k].selected) {
				checkedElm = curEll[k].value;
			}
		}
		}
		if(checkedElm == splArr[p]) {
			document.getElementById(divName).style.display = ""; 
			document.getElementById(divName).innerHTML = valInnerHtml;
		}
	}
}


function showhideIT(checkElement){
	//var action = -1;
	var flaghide = false;
	var arr_action = new Array();
	var t = 0;
	//searching the array ID for which the function was called
	for (var i=0; i < div_array.length; i++) {
		for(var prop in div_array[i]){
			if(prop == checkElement.name) {flaghide=true;}
			
			if((prop == checkElement.name) && ((div_array[i][prop] == checkElement.value) ||  div_array[i][prop].indexOf("-") == 0)){
					
				arr_action[t] = i; 
				t = t+1;
				
			}
		}
	}
	
	if (flaghide) {
		var NameOfTheDiv="";
		var flag = false;
		var iprev=0;
		for (var i=0; i < div_array.length; i++) {
				flag = false;
				for(var prop in div_array[i]){
						if(prop == checkElement.name){
							flag = true;
							iprev = i;
							}
						if(prop != checkElement.name){
								//alert(prop);
								NameOfTheDiv = document.getElementById(prop);
								if  (!(isUndefined(NameOfTheDiv))) {
										if ((flag) && (iprev == i)) {
										    		//alert(prop+document.getElementById(prop).innerHTML);
												document.getElementById(prop).style.display="none";
												document.getElementById(prop).innerHTML = "";
										}
								}
						}
				}
		}
	}

for (var i=0; i < arr_action.length; i++) {
action = arr_action[i];
//	if (action >= 0){
		var type = checkElement.type;
		//if the value writed in the div is the same with the current value of the field it shows it
		//if the value writed in the div is NOT the same with the current value of the field it hides it
		//za sega v array-a se zapisvat 2 property-ta. 1-voto e imeto na cykalkata sys stionost za pokazvane na div-a, a 2-roto e imeto na diva sys stoinost negoviq innerHTML.
		//if-a hva6ta stoinostite za dropdown, radio, checkbox 
		if ((div_array[action][checkElement.name] == checkElement.value && type != "checkbox" && div_array[action][checkElement.name].indexOf("-") != 0) || (checkElement.checked && div_array[action][checkElement.name] == checkElement.value && type == "checkbox") || (div_array[action][checkElement.name] != "-"+checkElement.value  && div_array[action][checkElement.name].indexOf("-") == 0)){	
	
			for(var property in div_array[action]) {
			   var value = div_array[action][property];
			   //setva property da e ravno na id-to na div-a, za da moje da go pokaje.
			   if (property != checkElement.name) {
			      // alert("Yes")
				   document.getElementById(property).style.display="";
				   document.getElementById(property).innerHTML = div_array[action][property];
			   }
			}
		} else {
			for(var property in div_array[action]) {
				var value = div_array[action][property];
				//alert(property);
				//setva property da e ravno na id-to na div-a, za da moje da go skrie.
				if (property != checkElement.name) {
				   document.getElementById(property).style.display="none";
				   document.getElementById(property).innerHTML = "";
				}
			}
		}
	}
}

function writeInnerHtml(nameOfDiv){
// funkciqta zapisva v div_array-a innerHTML-a za vseki div za koito otgovarqt kriteriite. Tova stava pri divend ot mkForm
	for (var i=0; i<div_array.length; i++) {
		for(var property in div_array[i]) {
		//tyrsi syvpadenie na imenata da e sigyrno 4e innerHTML-a se dobavq za verniq div
		   if (property == nameOfDiv){
			div_array[i][nameOfDiv] = document.getElementById(nameOfDiv).innerHTML;
		   }
		}
	}
}

function mkBubbles(bubblesArr, divId, output){
	//kogato se izpolzva tazi funkciq trqbva da se importnat -->  /CSS/new.css  &  /CSS/bubble.js
	//....
	//za bubblesArr  --> chetnite nomera v masiva predstavlqvat textyt koito se izpisva v lqvo ot input poletata
	//nechetnite nomera v masiva predsatavlqvat texta koito se poqvqva v baloncheto
	//chetni nechetni se qvqvat kato edna dvoika. t.e. 0 s 1, 2 s 3, i t.n
	//....
	//v tablicata se pravi div start ot kydeto da zapochne da gleda i div end kyde da spre ... podava se v divId
	//output parametyra se qvqva stringa koito se pechata v browsera.
	var data = document.getElementById(divId);
	if (data != null) {
		data = document.getElementById(divId).getElementsByTagName("td");
		if (typeof(bubblesArr) == "object") {
			for (var i=0; i<data.length; i++) {
				var str = data[i].innerHTML;
				for(var j=0; j<bubblesArr.length; j+=2){
				
					var str2 = bubblesArr[j];
					// tova se pravi za6toto mkForm v nqkoi sluchei zamestva edinichna s dvoina kavichka.
					//Zamestvaneto se pravi samo za da se validira dali tova e tyrseniqt string. V krainiq HTML ne se pravqt tezi promeni
					str3 = str;
					str2 = str2.replace(/'/g, "\"");
					str3 = str3.replace(/'/g, "\"");
					str2 = str2.replace(/ & /g, " &amp; ");
					str3 = str3.replace(/ & /g, " &amp; ");
					
					str2 = str2.toLowerCase();
					str3 = str3.toLowerCase();
					
					if (str3.indexOf(str2) > -1){
						data[i].innerHTML = str + " <span onmouseover=\"showhint("+ bubblesArr[j+1] +", this, event, '180px')\" class='hintanchor' style='color:#DB1C17;'>"+output+"</span>"
					}
				}
			}
		}
	}
}
//////////////////////////////////////
function showhidecheckbox(curdivelement,elemn){

alert (elemn.checked)
	if (elemn.checked) {
		
		alert(document.getElementById(curdivelement).innerHTML);
		document.getElementById(curdivelement).innerHTML = eval(curdivelement);
		
		document.getElementById(curdivelement).style.display="";
	}
	else{
		document.getElementById(curdivelement).innerHTML = "";
		document.getElementById(curdivelement).style.display="none";
	}
}
function showhideradio(curdivelement,test){

	a=curdivelement+"test1";
	m=eval(a);
	if (test.value=='No') 
	{
		document.getElementById(curdivelement).innerHTML =m;
		document.getElementById(curdivelement).style.display="";
		test.value='Yes';
	}else{
		document.getElementById(curdivelement).innerHTML = "";
		document.getElementById(curdivelement).style.display="none";
		test.value='No';
	}
	
}

function showhidedropdownStyle(curdivelement,elemvalue,elemname){
var bolVar
//var ChildCol
var oElem = document.getElementsByName(elemname);
//var elementValue = document.forms[0].elements[elemname].options[oElem.item(0).selectedIndex].value; 
var elementValue = document.getElementsByName(elemname).item(0).value;
//alert(elementValue + "  " + elemvalue);
	if (elementValue != elemvalue) {
		document.getElementById(curdivelement).style.display = "none";
		bolVar = true;
	}
	else{
		document.getElementById(curdivelement).style.display = "";
		bolVar = false;
	}
	for(var i = 0; i < myArray[curdivelement].length; i++){
		//alert("The tag: " + document.getElementsByName(myArray[curdivelement][i]).item(0).name + ".disable = " + bolVar);
		document.getElementsByName(myArray[curdivelement][i]).item(0).disabled = bolVar;
	}
}

function showhidedropdownStyleTest(curdivelement,elemvalue,elemname){ //maj triabva da se iztrie
var bolVar
//var ChildCol
var oElem = document.getElementsByName(elemname);
var elementValue = document.forms[0].elements[elemname].options[oElem.item(0).selectedIndex].value; 

	if (elementValue != elemvalue) {
		document.getElementById(curdivelement).style.display = "none";
		bolVar = true;
		
	}
	else{
		document.getElementById(curdivelement).style.display = "";
		bolVar = false;
		
	}
	alert(curdivelement+"                   "+ myArray[curdivelement].length);
	for(var i = 0; i < myArray[curdivelement].length; i++){
		//alert("The tag: "+i + document.getElementsByName(myArray[curdivelement][i]).item(0).name + ".disable = " + bolVar);
		alert(document.getElementsByName(myArray[curdivelement][i]).item(0) + "                "+i+"                    "+bolVar)
		document.getElementsByName(myArray[curdivelement][i]).item(0).disabled = bolVar;
		//document.getElementsByName(myArray[curdivelement][i]).disabled = bolVar;
	}
}

function showhidedropdownStyle1(curdivelement,elemvalue,elemname,formname){
var oElem = document.getElementsByName(elemname);
var elementValue = document.forms[formname].elements[elemname].options[oElem.item(0).selectedIndex].value; 
	if (elementValue != elemvalue) {
		document.getElementById(curdivelement).style.display = "none";
	}
	else{
		document.getElementById(curdivelement).style.display = "";
	}
}

function showhidedropdownStyle2(curdivelement,elemvalue,elem){
var elementValue = elem.value; 
	//alert(elem.value);
	if (elementValue != elemvalue) {
		document.getElementById(curdivelement).style.display = "none";
	}
	else{
		document.getElementById(curdivelement).style.display = "";
	}
}

function showhidedropdownseveraldivs(curdivelement,elemvalue,elemname,elemnameGetNnumber,maxValue){
var oElem = document.getElementsByName(elemname);
var elementValue = document.forms[0].elements[elemname].options[oElem.item(0).selectedIndex].text; //vrashata tekushtata stojnost na dropdown-a
var oElemGN = document.getElementsByName(elemnameGetNnumber);
var elementValueGN = document.forms[0].elements[elemnameGetNnumber].options[oElemGN.item(0).selectedIndex].text;
	if (elementValue != elemvalue) {
					for(i=1; i<(parseInt(maxValue) + 1); i++){
							//document.getElementById(curdivelement+i).innerHTML = "";
							document.getElementById(curdivelement+i).style.display = "none";
					}
	}
	else{
		if (elementValueGN >= 1 ) {
			for(i=1; i< (parseInt(elementValueGN) + 1); i++) {
				//document.getElementById(curdivelement+i).innerHTML = eval(curdivelement+i);
				document.getElementById(curdivelement+i).style.display = "";
		    }
		}
	}
}

function showhidedropdownNumValRange(curdivelement,elemvalueStart,elemvalueEnd,elemname){
var oElem = document.getElementsByName(elemname);
var bolVar;
var elementValue = document.forms[0].elements[elemname].options[oElem.item(0).selectedIndex].text; //vrashata tekushtata stojnost na dropdown-a
	var Flag = 0;
	if ((parseInt(elementValue) <= parseInt(elemvalueStart)) || (parseInt(elementValue) >= parseInt(elemvalueEnd))) Flag = 1;
	if (Flag == 1) {
		document.getElementById(curdivelement).style.display = "none";
		bolVar = true;
	}
	else{
		document.getElementById(curdivelement).style.display = "";
		bolVar = false;
	}
	for(var i = 0; i < myArray[curdivelement].length; i++){
		//alert("The tag: " + document.getElementsByName(myArray[curdivelement][i]).item(0).name + ".disable = " + bolVar);
		document.getElementsByName(myArray[curdivelement][i]).item(0).disabled = bolVar;
	}
}


//ot taxback international
/*
function removeOneDiv (divName , divInd, trueVal, curVal) {
//primer za polzvane removeOneDiv('business',1,9,this.options[this.selectedIndex].value)
if (trueVal ==curVal) {
	if (eval(divName + '_' +divInd) != '') { document.getElementById(divName+divInd).innerHTML = eval(divName + '_'+divInd); eval('_'+divInd+'=\'\''); }
}
else {
	eval(divName + '_'+divInd+'=document.getElementById(divName+divInd).innerHTML');
	document.getElementById(divName + divInd).innerHTML = '';
}
}
*/

function howmanyemployers(curdivelem,curfield){
	var MyArr = new Array(contactdetailsdiv1,contactdetailsdiv2,contactdetailsdiv3)
	var emplnumber = document.forms['RegFrm'].elements[curfield].value;
			  		document.getElementById(curdivelem+1).innerHTML="";
	if(emplnumber == 1){document.getElementById(curdivelem+emplnumber).innerHTML=MyArr[0];}
	if(emplnumber > 1){
			  var b = 0;
			  if  (emplnumber > 3){emplnumber = 3}; 
			  for(a=0; a < emplnumber; a++){
						 b = b + 1;
			  		document.getElementById(curdivelem+b).innerHTML=MyArr[a];
			  }
	}
}
function rmvelements(frmName,curdivelem,dependElement){
		  if (dependElement){
					 exstngElement = dependElement;
		  }
		  else{
					 exstngElement = curdivelem;
		  }
		  if(document.forms[frmName].elements[exstngElement]){
			  for(a=1; a <= 3; a++){
			  		document.getElementById(curdivelem+a).innerHTML="";
			  }
		  }
}
function checkuncheckradiobuttons(frmName,elmntName,elmntNumber,status){
		  if (document.forms[frmName].elements[elmntName]){
					 document.forms[frmName].elements[elmntName][elmntNumber].checked=status;
		  }
}
function hidedivs(elementNames,elementNumbers) {
tmpStr1 = elementNames;
tmpStr2 = elementNumbers
tmpArray1 = tmpStr1.split("/");
tmpArray2 = tmpStr2.split("/");
if(tmpArray1[0])
{
  //  alert(tmpArray1[0]);
  //  alert(myArray['entries4']);
    for (w=0;w<=tmpArray1.length-1;w++)
	{
		if (document.getElementById)
		{
			removeDivUniv (1,tmpArray1[w],tmpArray2[w]);
		}
    }
}
else
{
	
    removeDivUniv (1,elementNames,elementNumbers);
}
}

function hideAlldivs(elementNames,elementNumbers) {
tmpStr1 = elementNames;
tmpStr2 = elementNumbers
tmpArray1 = tmpStr1.split("/");
tmpArray2 = tmpStr2.split("/");
if(tmpArray1[0]){
		  for (w=0;w<=tmpArray1.length-1;w++){
					 if (document.getElementById){
								removeDivUniv (0,tmpArray1[w],tmpArray2[w]);
					 }
		  }
}

else{
		  removeDivUniv (0,elementNames,elementNumbers);
}
}


function removeOption(elemname)
{
	if (document.forms[0].elements[elemname]) {
		document.forms[0].elements[elemname].value="";
	}
}

//skriva div-ove ot tipa na emploer-ite - div1, div2, div3 ..
function HideSeveralDivs(curdivelement,startValue,maxValue)
{
		for (i=startValue; i<=maxValue; i++) {
				document.getElementById(curdivelement+i).style.display = "none";
				//eval('var '+ divname+i +'= document.getElementById("'+ divname+i +'").innerHTML;');
				//eval('document.getElementById("' + divname+i + '").innerHTML="";')
		}
		
}

function IsNumeric(fieldname)
{
		var val = window.document.getElementsByName(fieldname)[0].value;
		val = val.replace(",",".");
		if(isNaN(val))
		   {
			 alert("Invalid data format.\n\nOnly numbers are allowed.");
			 window.document.getElementsByName(fieldname)[0].value="";
			 window.document.getElementsByName(fieldname)[0].focus();
			 return (false);
		   }
}

function isIntegerInRange(fieldname,startOfRange,endOfRange) {
	//var val = field.value;
	var val = window.document.getElementsByName(fieldname)[0].value;
	if ( !isInteger(val) && val != "") {
		 alert("Invalid data format.\n\nOnly numbers are allowed.");
		 window.document.getElementsByName(fieldname)[0].value="";
		 window.document.getElementsByName(fieldname)[0].focus();
		 return (false);
	} 
	
	if ( (parseInt(val) >= parseInt(startOfRange)) && (parseInt(val) <= parseInt(endOfRange)) ) {
		
	} else {
		alert("Invalid data format.\n\nDays must be between 0 and 365.");
		window.document.getElementsByName(fieldname)[0].value="";
		window.document.getElementsByName(fieldname)[0].focus();
		return (false);
	}
}

function FormatNumericVal(fieldname)
{
		var val = window.document.getElementsByName(fieldname)[0].value;
		val = val.replace(/,/g,"");
		window.document.getElementsByName(fieldname)[0].value = val;
}

function ValidateMandatoryIEFQ(form_data,arrradiobutt)
{
		var result = false;
		result = check_fields(form_data); 
		len = arrradiobutt.length;
		for (j=0; j<len; j++) 
		{
		   result = result & check_fields_radio(arrradiobutt[j]); 
		}
		if (result) 
		  {
		    //this.form.submit();
			return true;
		  }
		  else {
		   return false;
		  }
}


function checkPhoneNumber(phoneNo,fieldname) { 
 //var phoneRE = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
 var val = window.document.getElementsByName(fieldname)[0].value;
//var phoneRE = /^([\(\)-+ ])*([0-9]){1}([\(\)-+ ])*([0-9]){1}([\(\)-+ ])*([0-9]){1}([\(\)-+ ])*([0-9]){1}/; 
 var valS = phoneNo;
 valS = valS.replace (/[0-9]/g,"");
 valS = valS.replace (/[-+\(\) ]/g,"");
//alert("!"+valS+"!");
 if (valS=="") { 
   return true; 
 } else { 
   //alert("The phone number entered is invalid!"); 
   window.document.getElementsByName(fieldname)[0].value = "";
   return false; 
 } 
}

function validatePhoneNumber(fieldname) { 
 var val = window.document.getElementsByName(fieldname)[0].value;
 val = val.replace (/[0-9]/g,"");
 if (val=="") { 
   return true; 
 } else { 
   alert("The phone number entered is invalid!"); 
   window.document.getElementsByName(fieldname)[0].value = "";
   return false; 
 }
}

/*ajax fuctions----------------------------------------------------------start---------------------------------------------------------*/
function LoadXMLDocDubl(url) {
    // branch for native XMLHttpRequest object
   
    if (window.XMLHttpRequest) {
	
     	req = new XMLHttpRequest;
		req.onreadystatechange = processReqChangeCount;
        	req.open("GET", url, true);
        	req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        	isIE = true;
        	req = new ActiveXObject("Microsoft.XMLHTTP");
        	req.onreadystatechange = processReqChangeCount;
          req.open("GET", url, true);
          req.send();
        }
}

function loadXMLContentPost(url,postparams) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest;
		req.open("POST", url, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		req.onreadystatechange = processReqChangeCount;
		req.send(postparams);
		//"msg="+document.getElementById('msg').value+"&user_to="+document.getElementById('user_to').value
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
			req.open("POST", url, true);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
            req.onreadystatechange = processReqChangeCount;
            req.send(postparams);
			
        }
    }
}

function processReqChangeCount() {
    // only if req shows "loaded"
     if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			//CountDub=0;
			//alert(req.responseText);
				var a=req.responseText;
				var re;
				re = /<\/script>/ig;
				a = a.replace(re, "[]");
				
				re = /<script language=\"javascript\">/ig;
				a = a.replace(re, "[]");
				
				re = /<script language=\'javascript\'>/ig;
				a = a.replace(re, "[]");
				
				m=a.split("[]");
				var p;
				p="";
				if (m.length>1)
				{
					for (i=0; i<m.length; i++)
					{
							if ((i % 2) == 0 ) {p= p + m[i];}
					}
					document.getElementById("ajaxelement").innerHTML = p;
					for (i=0; i<m.length; i++)
					{
							if ((i % 2) == 1 ) {eval(m[i]);}
					}
				//p=m[0]+m[2];
				//document.getElementById("ajaxelement").innerHTML=m[0];
				//alert(m[1]);
				////document.getElementById("ajaxelement").innerHTML+=m[1];
				//document.getElementById("ajaxelement").innerHTML+=m[2];
				//eval(m[1]);
				} else
				{
					document.getElementById("ajaxelement").innerHTML=a;
				}
            	//document.getElementById("ajaxelement").innerHTML=req.responseText;
			//alert(CountDub);		
         } else {
            	alert("There was a problem retrieving the XML data:\n" +
               req.statusText);
         	  }
    }
}


//function LoadXMLDocDublInDiv works with global variable ajaxdiv_element!!! called form processReqChangeCountInDiv
var ajaxdiv_element;
function LoadXMLDocDublInDiv(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
     	req = new XMLHttpRequest;
		if (ajaxdiv_element =="emailstatus") {document.getElementById(ajaxdiv_element).innerHTML="<img src='/Images/searching.gif' />";}
		req.onreadystatechange = processReqChangeCountInDiv;
        	req.open("GET", url, true);
        	req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        	isIE = true;
        	req = new ActiveXObject("Microsoft.XMLHTTP");
			if (ajaxdiv_element =="emailstatus") {document.getElementById(ajaxdiv_element).innerHTML="<img src='/Images/searching.gif' />";}
        	req.onreadystatechange = processReqChangeCountInDiv;
          req.open("GET", url, true);
          req.send();
        }
}

function processReqChangeCountInDiv() {
    // only if req shows "loaded"
     if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			//CountDub=0;
			//alert(req.responseText);
			//alert(ajaxdiv_element);
				var a=req.responseText;
				document.getElementById(ajaxdiv_element).innerHTML=a;
			//alert(CountDub);		
         } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
         }
    }
}

//check_dubl(query_check);

function check_dubl(query_check,selelement,elvalue)
{
	//query_check="/ajaxtext.asp";
	
//	selelement.disabled = true;
	//alert(query_check+elvalue);
	LoadXMLDocDubl(query_check+elvalue);
//	selelement.disabled = false;
}


/*ajax fuctions -----------------------------------------------------------------------------end-------------------------*/
/*get hash for ajax funtionality ------------------------------------------------------------start-----------------------*/
var expectedHash = "";

function makeHistory(newHash)
{
if (newHash != "") {
  window.location.hash = newHash;
  expectedHash = window.location.hash;
  return true;
}
}

function reportOptionValue()
{
  var myForm = document.RegFrm;
  var mySelect = myForm.typeofempl__;
  return mySelect.options[mySelect.selectedIndex].value;
}

function setOptionValue(value)
{
  var myForm = document.RegFrm;
  var mySelect = myForm.typeofempl__;
  var arr1= mySelect.options;
  for (i=0; i<arr1.length; i++) {
  if (mySelect.options[i].value==value) {mySelect.options[i].selected=true }
  }
  //mySelect.options[value-1].selected = true;
  return true;
}

function reportOptionValueUkFrm()
{
  var myForm = document.RegFrm;
  var mySelect = myForm.area__;
  return mySelect.options[mySelect.selectedIndex].value;
}

function handleHistory(param)
{
  if ( window.location.hash != expectedHash )
  {
    expectedHash = window.location.hash;
  // tuka maj tr da se napravi split i da se vzema stojnosta sle # i sled tova v zavisimost ot neya se zaregda saotvetnata forma
    var newoption = expectedHash;
	var re;
	re = /#/i;
	newoption = newoption.replace(re, "");
	//alert (newoption);
    setOptionValue( newoption );
	var el=document.getElementsByName("typeofempl__");
	if (param==1) {	check_dubl("/estimations/uk_FQ_Form_1.asp?StepUK=",el,newoption);}
	if (param==2) {	check_dubl("/estimations/uk_FQ_Form_1.asp?Type=farm&StepUK=",el,newoption);}
  }
  return true;
}

function handleHistoryIe2(param)
{
  if ( window.location.hash != expectedHash )
  {
    expectedHash = window.location.hash;
  // tuka maj tr da se napravi split i da se vzema stojnosta sle # i sled tova v zavisimost ot neya se zaregda saotvetnata forma
    var newoption = expectedHash;
	var re;
	re = /#/i;
	newoption = newoption.replace(re, "");
	//alert (newoption);
    setOptionValue( newoption );
	var el=document.getElementsByName("typeofempl__");
	if (param == "FQ") {
		check_dubl("/estimations/ie_FQ_Form_1.asp?StepIE=",el,newoption);
	} else {
		check_dubl("/estimations/ie_Frm_Form_1.asp?StepIE=",el,newoption);
	}
  }
  return true;
}
function pollHashIe2(param) {
  handleHistoryIe2(param);
  window.setInterval("handleHistoryIe2('"+param+"')", 1000);
  return true;
}


function pollHash() {
  handleHistory(1);
  window.setInterval("handleHistory(1)", 1000);
  return true;
}

function pollHashFarms() {
  handleHistory(2);
  window.setInterval("handleHistory(2)", 1000);
  return true;
}

function pollHashIe() {
  handleHistoryIe();
  window.setInterval("handleHistoryIe()", 1000);
  return true;
}

function pollHashUKFrm() {
  handleHistoryUkFrm();
  window.setInterval("handleHistoryUkFrm()", 1000);
  return true;
}

function reportOptionValueIe()
{
  var myForm = document.RegFrm;
  var mySelect = myForm.area__;
  return mySelect.options[mySelect.selectedIndex].value;
}

function setOptionValueIe(value)
{
  var myForm = document.RegFrm;
  var mySelect = myForm.area__;
  var arr1= mySelect.options;
  for (i=0; i<arr1.length; i++) {
  if (mySelect.options[i].value==value) {mySelect.options[i].selected=true }
  }
  //mySelect.options[value-1].selected = true;
  return true;
}

function setOptionValueUkFrm(value)
{
  var myForm = document.RegFrm;
  var mySelect = myForm.area__;
  var arr1= mySelect.options;
  for (i=0; i<arr1.length; i++) {
  if (mySelect.options[i].value==value) {mySelect.options[i].selected=true; }
  }
  //mySelect.options[value-1].selected = true;
  return true;
}
function handleHistoryIe(param)
{
  if ( window.location.hash != expectedHash )
  {
    expectedHash = window.location.hash;
  // tuka maj tr da se napravi split i da se vzema stojnosta sle # i sled tova v zavisimost ot neya se zaregda saotvetnata forma
    var newoption = expectedHash;
	var re;
	re = /#/i;
	newoption = newoption.replace(re, "");
	//alert (newoption);
    setOptionValueIe( newoption );
  	LoadXMLDocDublInDiv("/ajaxquery/ie_fq_areas.asp?area="+newoption);
  }
  return true;
}

function handleHistoryUkFrm()
{
  var j;
  if ( window.location.hash != expectedHash )
  {
    expectedHash = window.location.hash;
	//alert(expectedHash);
  // tuka maj tr da se napravi split i da se vzema stojnosta sle # i sled tova v zavisimost ot neya se zaregda saotvetnata forma
    var newoption = expectedHash;
	var re;
	re = /#/i;
	newoption = newoption.replace(re, "");
	setOptionValueUkFrm( newoption );
	ajaxdiv_element = "posdiv";
  	LoadXMLDocDublInDiv("/ajaxquery/uk_position.asp?area="+newoption);
  }
  return true;
}

/*get hash for ajax funtionality ------------------------------------------------------------end-----------------------*/
// ot tuka zapo4vata functions za novite logvaniya i razni te mu tam proverki
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function CheckAspUser(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
		req1 = new XMLHttpRequest;
		req1.onreadystatechange = processUser;
        	req1.open("GET", url, true);
        	req1.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        	isIE = true;
        	req1 = new ActiveXObject("Microsoft.XMLHTTP");
        	req1.onreadystatechange = processUser;
          req1.open("GET", url, true);
          req1.send();
        }
}

function processUser() {
    // only if req shows "loaded"
     if (req1.readyState == 4) {
        // only if "OK"
        if (req1.status == 200) {
	        			var countUser=1;
				 countUsers=req1.responseText;
				 //alert (countUsers);
				 if(countUsers !=0){
			          alert ("Please insert new username. The one you have chosen already exists.");
						}
				
            	//document.getElementById("ajaxelement").innerHTML=req.responseText;
			//alert(CountDub);		
         } else {
            	alert("There was a problem retrieving the XML data:\n" + req1.statusText);
         	  }
    }
}
var check_change_pass=0;
function check_valid_user_name(user){
	var struser=user.value;
	if(struser.length>24 || struser.length<2)
	{
		alert("Your username should consist of 6 to 24 symbols");
		check_change_pass++;
	}else{
		var regexpr=/[A-Za-z]{1,}/
		var regexpr1=/^[A-Za-z0-9_\.\?!@#\-_]{5,5}[A-Za-z0-9_\.\?!@#\-_]{1,19}$/
		if(regexpr.test(struser)) {
				if(regexpr1.test(struser))CheckAspUser("/reports/check_user.asp?user="+user.value);
			else {
					alert("Your username must contain of letters (a-z,A-Z), numbers (0-9), _, ., ?, !, @, #, _, - ");
					check_change_pass++;
				}
			}
			else{
				alert ("Your username must contain at least one letter.!");
				check_change_pass++;
			}
	}
}
function check_valid_pass(pass){
	var strpass=pass.value;
	if(strpass.length>24 || strpass.length<6)
	{
		alert("Your password should consist of 6 to 24 symbols!");
		check_change_pass++;
	}else{
		var regexpr1=/^[A-Za-z0-9~!@#\$%\^&\*\(\)_\+\':;\/\,\{\}\[\]|\\<>\?`=\"\.£¬-]{5,5}[A-Za-z0-9~!@#\$%\^&\*\(\)_\+\':;\/\,\{\}\[\]|\\<>\?`=\"\.£¬-]{1,19}$/
		//alert(strpass);
		//alert(regexpr1.exec(strpass));
		if(!regexpr1.test(strpass)){
					alert("Your password can consist of letters and numbers only.");
					check_change_pass++;
				}
	}
}
function check_pass(pass, conpass,user){
	check_change_pass=0;
	check_valid_pass(pass);
	check_valid_pass(conpass);
	check_valid_user_name(user);
	if (check_change_pass == 0){
		if(pass.value==conpass.value){
			//alert ("test");
			document.changeUP.submit();
		}else
		{
			alert ("The passwords you entered do not match.");
		}
	}else alert ("You have errors");
}
//sledvashtata function e za zadavane na biskvitki
function set_login_coockies(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function isNull(a) 
 {
      return typeof a == 'object' && !a;
 }

function get_cookie(cookie_name)
{
	//alert (cookie_name +"   "+document.cookie);
	if(document.cookie)
	{
		var cookies=unescape(document.cookie);
		//alert ( cookies);
		//alert ( cookie_name);
		arr_cookies=cookies.split(";");
		ret_cook=0;
		for(i=0;i<arr_cookies.length;i++)
		{
			if(arr_cookies[i] !=""  ){
				var cook = arr_cookies[i];
				//alert (cook);
				thecookie=cook.split("=");
				//alert (thecookie[0] + "="+thecookie[1]);
				if (trim(thecookie[0])==cookie_name) {
					ret_cook++;
					//alert (thecookie[0] + "="+thecookie[1]);
					return thecookie[1];
				}
			}
		}
		if (ret_cook == 0) return "";
		
	} else return "";
}

function disable_field(valueDisabled, value, NameDisabledField, DissabledDefaultValue)
{
		if (value==valueDisabled) {
			document.getElementsByName(NameDisabledField).item(0).value=DissabledDefaultValue;
			document.getElementsByName(NameDisabledField).item(0).disabled=true;
		} else {
			document.getElementsByName(NameDisabledField).item(0).value="";
			document.getElementsByName(NameDisabledField).item(0).disabled=false;
		}
}

function readOnly_field_old(valueReadOnly, value, NameReadOnlyField, ReadOnlyDefaultValue)
{
		if (value==valueReadOnly) {
			document.getElementsByName(NameReadOnlyField).item(0).value=ReadOnlyDefaultValue;
			document.getElementsByName(NameReadOnlyField).item(0).style.backgroundColor = "#BBBBBB";
			document.getElementsByName(NameReadOnlyField).item(0).readOnly=true;
		} else {
			document.getElementsByName(NameReadOnlyField).item(0).value="";
			document.getElementsByName(NameReadOnlyField).item(0).style.backgroundColor = "#FFFFFF";
			document.getElementsByName(NameReadOnlyField).item(0).readOnly=false;
		}
}


function readOnly_field(valueReadOnly, value, NameReadOnlyField, ReadOnlyDefaultValue)
{
		if (value==valueReadOnly) {
		   var p=document.getElementsByName(NameReadOnlyField)[0];
		   p.value=ReadOnlyDefaultValue;
		    p.parentNode.style.display="none";
		} else {
		    var p=document.getElementsByName(NameReadOnlyField)[0];
			p.value="";
			p.parentNode.style.display="";
		}
}


function readOnly_fieldFirstLoad_old(FieldName, FieldForChange)
{
		if (document.getElementsByName(FieldName).item(0).value == "mobile") {
			document.getElementsByName(FieldForChange).item(0).value = "-";
			document.getElementsByName(FieldForChange).item(0).style.backgroundColor = "#BBBBBB";
			document.getElementsByName(FieldForChange).item(0).readOnly = true;
		}
}

function readOnly_fieldFirstLoad(FieldName, FieldForChange)
{
		if (document.getElementsByName(FieldName).item(0).value == "mobile") {
		    var p=document.getElementsByName(FieldForChange)[0];
		    p.parentNode.style.display="none";
		    p.value="-";
		}
}


function isUndefined(a) {
    return typeof a == 'undefined';
} 

function eregFilter(string,fieldname,RegExpTmp) {
		var s = string
		var r = new RegExp(RegExpTmp, "gi");
		var a = s.match(r) // Find matches.
		if(isNaN(a))
		   {
			 alert("Invalid data format.");
			 window.document.getElementsByName(fieldname)[0].value="";
			 window.document.getElementsByName(fieldname)[0].focus();
			 return (false);
		   }
		 return (true);
}

function RemDivChild(Elem, str)
{
	if (Elem[Elem.selectedIndex].value=='yes') 
	{
		for(a=1;a<=5;a++)
		{
			document.getElementById(str+a).style.display = 'none';
			document.getElementById(str+a).disabled = true;
		}
	}
}



function DateDiffJapan(startD, endD, diffD)
{
    	var startVal = document.getElementsByName(startD)[0].value;
	var endVal = document.getElementsByName(endD)[0].value;
	
	if ((startVal != '') && (endVal != '') && (diffD != '')) {
	    
	    var startArr = startVal.split("/");
	    var endArr = endVal.split("/");
	    var dateStart = new Date();
	    var dateEnd = new Date();
	    dateStart.setFullYear(startArr[2], startArr[1]-1, startArr[0]);
	    dateEnd.setFullYear(endArr[2], endArr[1]-1, endArr[0]);
	
	    var oneDay = 1000*60*60*24
	    var diffr = Math.ceil((dateEnd - dateStart)/(oneDay));
	    	    
	    //alert(diffr);
	    if (diffr < diffD) {
		
		alert("You will not be entitled to a refund, if you haven't spent at least one year in Japan.");
		document.getElementsByName(startD)[0].value = "";
		document.getElementsByName(endD)[0].value = "";		
	    }
	}
}
	
function datediff(startDate, endDate, taxYear, DivName, DivName1, SumYear)
{
	if ((startDate!='') && (endDate!='') && (taxYear!='') && (DivName!='') && (SumYear!=''))
	{
		var innHtmlDiv='';
		var innHtmlDiv1='';
		for (var i=0; i < div_array.length; i++) 
		{
			for(var prop in div_array[i])
			{
				if(prop == DivName) 
				{
					innHtmlDiv=div_array[i][prop]
				}
				if(prop == DivName1)
				{
					innHtmlDiv1=div_array[i][prop]
				}
			}
		}
		var SumY=parseInt(SumYear)
		var startDateArr = startDate.split("/");
		var endDateArr = endDate.split("/"); 
		if (taxYear==startDateArr[2])
		{
			//var dateTaxYear = new Date();
			var dateStart = new Date();
			var dateEnd = new Date();
			//dateTaxYear.setFullYear(taxYear, "01", "01");
			dateStart.setFullYear(startDateArr[2], startDateArr[1]-1, startDateArr[0]);
			dateEnd.setFullYear(endDateArr[2], endDateArr[1]-1, endDateArr[0]); 
			var one_day=((60*60)*24)*1000;
			//var taxYearDiff=Math.ceil((dateTaxYear.getTime()-dateStart.getTime())/one_day)
			var diff=Math.ceil((dateEnd.getTime()-dateStart.getTime())/one_day);		
			if (diff > SumY) 
			{
				document.RegFrm.datedifference.value = diff;
				document.getElementById(DivName).style.display = '';
				document.getElementById(DivName1).style.display = '';
				document.getElementById(DivName).innerHTML = innHtmlDiv;
				document.getElementById(DivName1).innerHTML = innHtmlDiv1;
				//alert(document.getElementById(DivName1).innerHTML);
				//alert(innHtmlDiv1);
			}
			else
			{
				document.RegFrm.datedifference.value = 0;
				document.getElementById(DivName).innerHTML = "";
				document.getElementById(DivName1).innerHTML = "";
			}		
		}
		else
		{
			document.RegFrm.datedifference.value = 0;
			document.getElementById(DivName).innerHTML = "";
			document.getElementById(DivName1).innerHTML = "";
		}
	}
}



function FormatNumericValJapan(fieldname)
{
		var val = window.document.getElementsByName(fieldname)[0].value;
		//val = val.replace(/,/g,"");
		//window.document.getElementsByName(fieldname)[0].value = val;
		var splitVal = val.split(".");
			if ( typeof splitVal[1] != "undefined") {
		    //alert(splitVal[1]);
		alert("You can enter whole numbers only.");
		window.document.getElementsByName(fieldname)[0].value = "";
		}//	else{
		 //alert("It's OK!");   
		//}
}

function ClearValueIfZero(field) {
	var el = field
	if (el.value==0) {el.value="";}
}

function showTTyps (elmName) {

	if (document.getElementById(elmName).style.display != "none") {
		Effect.SlideUp(elmName);
	} else {
		Effect.SlideDown(elmName); return false;
	}


}

function blinkingtext(div_name,ms) {
    var v=document.getElementById(div_name);
    if (v.style.display=='') {
        v.style.display="none";
        setTimeout("blinkingtext('"+div_name+"',"+ms+")",ms);
    } else {
         v.style.display="";
         setTimeout("blinkingtext('"+div_name+"',"+ms+")",ms);
    }
}

function get_radio_value(radioar, formname)
{
		var value;
		var elem;
		elem = document.forms[formname].elements[radioar]
		//alert(radioar + elem);
		if (elem != null) {
			if (elem.length != null) {
				for (j=0;j<elem.length;j++)
					{
						if (elem[j].checked)
						{
							value = (elem[j].value);
						}
					}
			} else {
				if (elem.checked)
						{
							value = (document.forms[formname].elements[radioar].value);
						}
			}
			return value;
		} else {
			return false;
		}
}

function get_input_value(el) {
		var elem;
		elem = el;
		if (elem != null) {
				return elem.value;
		} else {
				return false;
		}
}

// someArray.inArray(value)"
if (!Array.prototype.inArray) {
   Array.prototype.inArray=function(val) {
      for (key in this) {
         if (this[key]===val) {
            return true; // If you want the key of the matched value, change "true" to "key"
         }
      }
      return false;
   }
}

function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function SetOptionValueByName(NameOfTheElement, val) {
		var y=document.getElementsByName(NameOfTheElement)[0];
		var br = y.options.length;
		for (i=0; i<br; i++) {
			if (y.options[i].value==val) {
				y.options[i].selected=true;
			}
		}
}

function loadJSContent(file){
        var head = document.getElementsByTagName("head")[0];
        script = document.createElement('script');
        script.src = file;
        script.type = 'text/javascript';
        head.appendChild(script)
}

