// JavaScript Document

var ajaxPath='/wp-content/themes/SGR/realestate/ajax';
 

function addListener(element, type, expression, bubbling){	

bubbling = bubbling || false; 	if(window.addEventListener)	{ // Standard		
element.addEventListener(type, expression, bubbling);		
return true;	} else if(element.attachEvent) { // IE	
//alert('addlisten');
element.attachEvent('on' + type, expression);		
return true;	} else return false;

}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function checkKeyAll(e,keycode){
   //event = event || window.event;
   //event=e;
   //alert(e.keyCode);
     if (e.keyCode == keycode) {
       //  alert(e.keyCode +'--'+ keycode);
		// checkLogin(theform);
      return true;  
     }
     return false;
}

	function quickSearchChange(formid){
				if(document.getElementById(formid).onsubmit()){
				setTimeout("UpdateQuickSearch(document.getElementById('"+ formid +"'))",200);
				}	

	}

function RequestMore(thelink,mlsnumber,frand,agentid,sidebar){
	document.getElementById('propertyContactBox').innerHTML='<img src="/wp-includes/js/thickbox/loadingAnimation.gif" style="margin:15px;">';
	hide('propertyMapSingle');
	UpdateData('propertyContactBox','requestInfoForm.php?mlsnumber='+mlsnumber+'&FRAND='+frand+'&agentid='+agentid);
	//console.log(thelink);
	//alert(thelink.OffsetTop);
	pos=findPos(thelink);
	
	if(sidebar){
		pos['top']=pos['top']-document.getElementById('quickSearchResults').scrollTop;
	}
	
	document.getElementById('propertyContactBox').style.top=(pos['top']+ thelink.offsetHeight)+'px';
	document.getElementById('propertyContactBox').style.left=(pos['left']-250)+'px';
	show('propertyContactBox');
}


function MapSingleProperty(thelink,mlsnumber,lat,long,frand,agentid,sidebar){
		
	hide('propertyContactBox');
	UpdateData('singleMapLoader','mapsingleproperty.php?mlsnumber='+mlsnumber+'&FRAND='+frand+'&agentid='+agentid);
	//console.log(thelink);
	//alert(thelink.OffsetTop);
	pos=findPos(thelink);
	
	if(sidebar){
		pos['top']=pos['top']-document.getElementById('quickSearchResults').scrollTop;
	}
	
	document.getElementById('propertyMapSingle').style.top=(pos['top']+ thelink.offsetHeight)+'px';
	document.getElementById('propertyMapSingle').style.left=(pos['left']-450)+'px';
	
	//load and move
	
	ZoomSetSingle(lat,long,mlsnumber);
	show('propertyMapSingle');
}
	



function ScheduleShowing(thelink,mlsnumber,frand,agentid){
	document.getElementById('propertyContactBox').innerHTML='<img src="/wp-includes/js/thickbox/loadingAnimation.gif"  style="margin:15px;">';
	hide('propertyMapSingle');
		UpdateData('propertyContactBox','scheduleShowing.php?mlsnumber='+mlsnumber+'&FRAND='+frand+'&agentid='+agentid);
	//console.log(thelink);
	//alert(thelink.OffsetTop);
	pos=findPos(thelink);
	
	document.getElementById('propertyContactBox').style.top=(pos['top']+ thelink.offsetHeight)+'px';
	document.getElementById('propertyContactBox').style.left=(pos['left']-250)+'px';
	show('propertyContactBox');
}

function UpdateSearchResults(theform,box,page){
	UpdateData(box,page,theform);
}
function ViewListing(theform,box,page){
	hide('propertyContactBox');
	UpdateData(box,page,theform);
}


function addPropMap(thecheck){
	if(thecheck.checked){
		UpdateData('emptyBox','addToMapList.php?',document.getElementById('resultsForm'));
	}else{
		UpdateData('emptyBox','addToMapList.php?remove=true',document.getElementById('resultsForm'));
	}
}

function loadSuburbs(theform){
	UpdateData('suburbListBox','suburbList.php?',theform);
}
function UpdateQuickSearch(theform){
	UpdateData('searchResultsPreview','updateQuickSearchSession.php?',theform);
}

function AlterQuickSearch(which,formid){
	
	UpdateData('neighborhoodQuickSearch','quicksearchNhood.php?which='+which+'&formid='+formid);
	
}

function AlterReviseSearch(which,formid){
	
	UpdateData('neighborhoodBox','revisesearchNhood.php?which='+which+'&formid='+formid);
	
}
function AlterComPrice(which,formid){
	
	UpdateData('comPriceBox','reviseComPrice.php?which='+which+'&formid='+formid);
	
}

function EmailFriend(mls,agentid,thelink){
		document.getElementById('propertyContactBox').innerHTML='<img src="/wp-includes/js/thickbox/loadingAnimation.gif"  style="margin:15px;">';
	hide('propertyMapSingle');
	UpdateData('propertyContactBox','emailFriend.php?mlsnumber='+mls+'&agentid='+agentid);
	pos=findPos(thelink);
	
	document.getElementById('propertyContactBox').style.top=((pos['top']+ thelink.offsetHeight))+'px';
	document.getElementById('propertyContactBox').style.left=(pos['left']-250)+'px';
	show('propertyContactBox');
}




function ContactAgent(mls,agentid,thelink){
	document.getElementById('propertyContactBox').innerHTML='';
	UpdateData('propertyContactBox','contactAgent.php?mlsnumber='+mls+'&agentid='+agentid);
	pos=findPos(thelink);
	
	document.getElementById('propertyContactBox').style.top=((pos['top']+ thelink.offsetHeight)-20)+'px';
	document.getElementById('propertyContactBox').style.left=(pos['left']-10)+'px';
	show('propertyContactBox');

}

	function submitAgentContact(theform){
		if(theform.onsubmit()){
		UpdateData('propertyContactBox','contactAgent.php?fromself=true',theform);
		
		}
								  
	}


function submitScheduleShowing(theform,frand){
		if(theform.onsubmit()){
		UpdateData('propertyContactBox','scheduleShowing.php?fromself=true&FRAND='+frand,theform);
		
		}								 
								 }

function submitInformationRequest(theform,frand){
	
	if(theform.onsubmit()){
		UpdateData('propertyContactBox','requestInfoForm.php?fromself=true&FRAND='+frand,theform);
		
		}	
}

	function submitEmailFriend(theform){
		if(theform.onsubmit()){
		UpdateData('propertyContactBox','emailFriend.php?fromself=true',theform);
		
		}
								  
	}
function UpdateSearch(theform){
	UpdateData('searchResultsPreview','updateSearchSession.php?',theform);
}

function UpdateSort(theform,box,page){
	UpdateData(box,page,theform);
}


function UpdateData(targetBox,url,theform){
	//this function will save the current form data into the db via ajax
	targetBox.innerHTML='Saving Data';
	parameters='';
	if(theform){
	for(i =0 ; i <theform.elements.length;i++){
	if(theform.elements[i].type=='checkbox'  ){
	// fix for checkbox
		if(theform.elements[i].checked){
			parameters= parameters+'&'+theform.elements[i].id+'='+ theform.elements[i].value;
		}else{
			parameters= parameters+'&'+theform.elements[i].id+'=N';
		}
	}else if(theform.elements[i].type=='radio' ){
				if(theform.elements[i].checked){
			parameters= parameters+'&'+theform.elements[i].id+'='+ theform.elements[i].value;
		}else{
			//parameters= parameters+'&'+theform.elements[i].id+'=N';
		}
	}else if(theform.elements[i].type=='select' ||  theform.elements[i].type=='select-multiple' ){
		if(theform.elements[i].multiple){
			for(o=0;o<theform.elements[i].options.length;o++){
				if(theform.elements[i].options[o].selected){
				parameters= parameters+'&'+theform.elements[i].id+'|'+theform.elements[i].options[o].value+'='+ theform.elements[i].options[o].value;
				}else{
					parameters= parameters+'&'+theform.elements[i].id+'|'+theform.elements[i].options[o].value+'=N';
				}
			}
			
		}else{
			parameters= parameters+'&'+theform.elements[i].id+'='+ theform.elements[i].value;
		}
		
	}else{
		parameters= parameters+'&'+theform.elements[i].id+'='+ theform.elements[i].value;
	}
	}//end loop
	
	}//end if form
	//document.getElementById(targetBox).innerHTML='UPDATING...'
	divver(targetBox,ajaxPath+'/'+url+'&PHPSESSID='+readCookie('PHPSESSID') ,parameters)
}



	function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

	
		function updatepage(thetext,divver){
			//alert(thetext);
			if(document.getElementById(divver)){
			document.getElementById(divver).innerHTML=thetext;
			}
		}
	var self =new Array();
	
		 function divver(divnum,strURL,parameters) {
		 document.body.style.cursor = "wait";
	
		 		var parameters=(parameters==null)? new Array()  :parameters;
				var xmlHttpReq = false;
				
				
				
				 var newnum=self.length;
				//alert(newnum);
				 self[newnum] = this;
				// Mozilla/Safari
				if (window.XMLHttpRequest) {
					self[newnum].xmlHttpReq = new XMLHttpRequest();
				}
				// IE
				else if (window.ActiveXObject) {
					self[newnum].xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				}
				self[newnum].xmlHttpReq.open('POST', strURL, true);
				self[newnum].xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					self[newnum].xmlHttpReq.onreadystatechange = function() {
						//alert(this.readyState);
					if (this.readyState == 4 && this.status == 200) {
					updatepage(this.responseText,divnum);
					document.body.style.cursor = "auto";

						var re = /<script\b.*?>(.*?)<\//ig; // assumes HTML well formed
						var matchs;
						if(this.responseText){
						while (matchs = re.exec(this.responseText)) {
							//alert('run ajax script');
						//	alert(matchs[1]);
							eval(matchs[1]);
						}
						}
					
					
					}
				}
				if(parameters.length > 0){
				  self[newnum].xmlHttpReq.setRequestHeader("Content-length", parameters.length);
				  self[newnum].xmlHttpReq.setRequestHeader("Connection", "close");
				  self[newnum].xmlHttpReq.send(parameters);
				}else{
					self[newnum].xmlHttpReq.send('test');
				}
	
	delete(self[newnum]);
	}

	function checkScheduleShowing(theform){
		if(theform.fname.value == ''){
			alert('You Must Enter Your First Name');
			theform.fname.focus()
			return false;
		}else 	if(theform.lname.value == ''){
			alert('You Must Enter Your Last Name');
			theform.lname.focus()
			return false;
		}else if(theform.email.value == ''){
			alert('Please Enter Your  Current E-mail Address!');
			theform.email.focus();
		}else if(!isEMailAddress(theform.email.value)){
			alert('Please Enter a Valid E-mail Address!');
			theform.email.focus();	
			return false;
		}else 	if(theform.scheduledate.value == '' || theform.scheduledate.value == 'Select Date'){
			alert('You Must Select a Date');
			theform.scheduledate.focus()
			return false;
				}else 	if(theform.scheduletime.value == ''){
			alert('You Must Enter a Showing Time');
			theform.scheduletime.focus()
			
			return false;
			}else{
			return true;	
		}
	}
	

	
	function checkRequestInfo(theform){
		if(theform.fname.value == ''){
			alert('You Must Enter Your First Name');
			theform.fname.focus()
			return false;
		}else 	if(theform.lname.value == ''){
			alert('You Must Enter Your Last Name');
			theform.lname.focus()
			return false;
		}else if(theform.email.value == ''){
			alert('Please Enter Your  Current E-mail Address!');
			theform.email.focus();
		}else if(!isEMailAddress(theform.email.value)){
			alert('Please Enter a Valid E-mail Address!');
			theform.email.focus();	

			return false;
			}else{
			return true;	
		}
	}
	
	
	
	function checkEmailFriend(theform){
		
		if(theform.fname.value == ''){
			alert('You Must Enter Your First Name');
			theform.fname.focus()
			return false;
		}else 	if(theform.lname.value == ''){
			alert('You Must Enter Your Last Name');
			theform.lname.focus()
			return false;
		}else if(theform.email.value == ''){
			alert('Please Enter Your  Current E-mail Address!');
			theform.email.focus();
		}else if(!isEMailAddress(theform.email.value)){
			alert('Please Enter a Valid E-mail Address!');
			theform.email.focus();	
		}else if(theform.friend_fname.value == ''){
			alert('You Must Enter Your Friend\'s First Name');
			theform.friend_fname.focus()
			return false;
		}else 	if(theform.friend_lname.value == ''){
			alert('You Must Enter Your Friend\'s Last Name');
			theform.friend_lname.focus()
			return false;
		}else if(theform.friend_email.value == ''){
			alert('Please Enter Your   Friend\'s E-mail Address!');
			theform.friend_email.focus();
		}else if(!isEMailAddress(theform.friend_email.value)){
			alert('Please Enter a Valid E-mail Address!');
			theform.friend_email.focus();	
			
		}else{
			return true;	
		}
		
		
	}
	
	
	
	function checkAgentContact(theform){
		
		if(theform.fname.value == ''){
			alert('You Must Enter Your First Name');
			theform.fname.focus()
			return false;
		}else 	if(theform.lname.value == ''){
			alert('You Must Enter Your Last Name');
			theform.lname.focus()
			return false;
		}else if(theform.email.value == ''){
			alert('Please Enter Your  Current E-mail Address!');
			theform.email.focus();
		}else if(!isEMailAddress(theform.email.value)){
			alert('Please Enter a Valid E-mail Address!');
			theform.email.focus();	
		}else{
			return true;	
		}
		
		
	}
	
	
	function validateStreetNameSearch(theform){
		
		return true;
		
	}
	
	function  validateSuburb(theform){
		//alert('validate');
			return true;
		
	}
	
	function validateStreetCoordSearch(theform){
		
		return true;
		
	}
	function validateNeighborhoodSearch(theform){
		return true;
	}
	
	function validateZipSearch(theform){
		
		if(theform.zipCode.value == ''){
			alert('Please Enter A Zip Code');	
			theform.zipCode.focus();
			return false;
		} else{
			
			parts=theform.zipCode.value.split(",");
			nums=parts.length;
			for(i=0;i<nums;i++){
				//alert(parts[i]);
				if( parts[i] != ''&& parts[i] != null && !isZIPCode(parts[i]) ){
					alert('Zip Code Enterd is Invalid '+parts[i]);
					start=theform.zipCode.value.indexOf(parts[i]);
					end=theform.zipCode.value.indexOf(',',start);
					if(end <0){end=theform.zipCode.value.length;}
					len=Math.abs(end-start);
					//alert(start+'--'+len);
					selectRange(theform.zipCode,start,end);
					theform.zipCode.focus();
					return false;
					break;
				}
								
			}
		
		}
		
		return true;
	}
	
	function selectRange(field,start, end) {
     if( field.createTextRange ) {
            var selRange = field.createTextRange();
            selRange.collapse(true);
            selRange.moveStart('character', start);
            selRange.moveEnd('character', end);
            selRange.select();
        } else if( field.setSelectionRange ) {
            field.setSelectionRange(start, end);
        } else if( field.selectionStart ) {
            field.selectionStart = start;
            field.selectionEnd = end;
        }

    
	}
	
	
	
	function isValidText(str,regex)
		{
			if (window.RegExp){
				if (typeof(regex)=='string')
					regex=new RegExp(regex);
				return regex.test(str);
			}else{
				window.alert("RegExp not available!");
				return true;
			}
		}
	
	
	function isZIPCode(str)
		{
			return isValidText(str,"^\\d{5}(-\\d{4})?$");
		}
	
	
	
	

	
	
	function submitRegistration(theform){
		
		if(theform.fname.value  == ''){
			alert('Please Enter Your First Name');	
			theform.fname.focus();
		}else if(theform.lname.value == ''){
				alert('Please Enter Your Last Name');	
			theform.lname.focus();
							
		}else if(theform.email.value == ''){
		alert('Please Enter Your  Current E-mail Address!');
		theform.email.focus();
		}else if(!isEMailAddress(theform.email.value)){
		alert('Please Enter a Valid E-mail Address!');
		theform.email.focus();
		
		
		}else if(theform.pword.value == ''){
		alert('Please Enter Your Password!');
		theform.pword.focus();
		
		}else if(theform.pword.value == theform.email.value){
		alert('Your Username and Password can not match');
		theform.pword.focus();
		
		}else if(theform.pword.value.length < 4 ){
		alert('Your Passord must be a least 4 characters!');
		theform.pword.focus();
		
		//}else if(!isAlphaNumeric(theform.pword.value)){
		//alert('Your Password can not include punctuation.');
		//theform.pword.focus();
		//return false;
		}else if(theform.pword2.value == ''){
		alert('Please Confirm Your Password!');
		theform.pword2.focus();
		
		}else if(theform.pword.value != theform.pword2.value){
		alert('Your Password and Confirm Password do not match');
		theform.pword2.value='';
		theform.pword2.focus();
		
		}else{
			theform.submit();
		}
				
		
		
				  
	}// end function
	
	
		
		
	function checkLogin(theform){

if(theform.username.value == ''){
	alert('Please Enter Your Username.');
	theform.username.focus();
	return false;
}
if(theform.password.value == ''){
	alert('Please Enter Your Password.');
	theform.password.focus();
	return false;
}

theform.submit();
}
	
	
	
	
	function isEMailAddress(str)
{
	return isValidText(str,"^([\\w\\._-]+)@([\\w_-]+\\.)+([\\w_]+)$");
}


function isPhoneNumber(str)
{
	return isValidText(str,"^\\(?\\d{3}\\)?[-\\. ]?\\d{3}[-\\. ]?\\d{4}$");
}


function isAlpha(str)
{
	return isValidText(str.toUpperCase(),"^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]+$");
}



function isAlphaNumeric(str)
{
	return isValidText(str.toUpperCase(),"^[ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890]+$");
}


function isValidText(str,regex)
{
	if (window.RegExp){
		if (typeof(regex)=='string')
			regex=new RegExp(regex);
		return regex.test(str);
	}else{
		window.alert("RegExp not available!");
		return true;
	}
}

function checkKey(e,theform){
   //event = event || window.event;
   //event=e;
   //alert(e.keyCode);
     if (e.keyCode == 13) {
        // alert('Enter key pressed');
		 checkLogin(theform);
        return false;
     }
     return true;
}

function show(object) 
  {
  if(navigator.vendor && navigator.vendor.indexOf("Apple") >=0){
  document.getElementById(object).style.display = 'inline-block';
  }else{
  document.getElementById(object).style.display = 'block';
  }
   
   document.getElementById(object).style.visibility = 'visible';
 
  }
           
 function hide(object) 
  {
  
   document.getElementById(object).style.display = 'none';
   document.getElementById(object).style.visibility = 'hidden';

  }
function fPass(){
if(document.getElementById('forgotPasswordForm').style.display =='none'){


show('forgotPasswordForm');
}else{
hide('forgotPasswordForm');
}
}


function findPos(obj) {
	var curleft = curtop = 0;
	var pos= new Array();

	if (obj.offsetParent) {


	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;


		} while (obj = obj.offsetParent);
	pos['top']=curtop;
	pos['left']=curleft;
	
	return pos;
	}
	
}

// DATE SELECTOR INPUT FUNCTIONS

var dateformat = 'mdy';  //Take care. It has to be EXACTLY the same at datedialog-server.php, line 14


var last_div_showed='';

function show_datedialog(
                    date_dialog_div,
                    selected_date_hidden_var,
                    selected_date_showed_div   ){

    if(document.getElementById(date_dialog_div)){

       if(document.getElementById(date_dialog_div).style.display == 'block')
          document.getElementById(date_dialog_div).style.display = 'none';
       else{

          if(last_div_showed!='') close_datedialog(last_div_showed);

          var coordinates = findPos(document.getElementById(selected_date_showed_div));
		  newtop=document.getElementById(selected_date_showed_div).offsetTop;
         // document.getElementById(date_dialog_div).style.left=coordinates.left + "px";
          coordinates.top+=17;
          document.getElementById(date_dialog_div).style.top=newtop + "px"; 

          document.getElementById(date_dialog_div).style.zIndex = 200;

          document.getElementById(date_dialog_div).style.display = 'block';
          last_div_showed = date_dialog_div;
          print_calendar(
                       date_dialog_div,
                       selected_date_hidden_var,
                       selected_date_showed_div  );
       }
    }
}

function update_content(id,content){
     if (document.getElementById){
	 //console.log(document.getElementById(id));
	 	if(document.getElementById(id).nodeName == "INPUT"){
			 document.getElementById(id).value=content;
		}else{
			
			document.getElementById(id).innerHTML=content;
		}
		
	 }else if (document.layers)
		 document[id].innerHTML=content;
	 else if (document.all)
		 document.all[id].innerHTML=content;
}

function call_server(url, vars){
     var xml = null;
     try{
         xml = new ActiveXObject("Microsoft.XMLHTTP");
     }catch(exception){
         xml = new XMLHttpRequest();
     }

     if(xml!=null){
        xml.open("GET",url + vars, false);
        xml.send(null);
        if(xml.status == 404) alert("Error 404: Incorrect url.");
        return xml.responseText;
     }
     else
        alert("Your browser does not support XMLHTTP.")
}

function get_calendar(
                    m,y,
                    date_dialog_div,
                    selected_date_hidden_var,
                    selected_date_showed_div
                      ){

    var selectedday='';
	//alert('getcal');
    if(document.getElementById(selected_date_hidden_var)){
       selectedday = document.getElementById(selected_date_hidden_var).value;

    var response = call_server( ajaxPath+"/datedialog-server.php",
                                "?y="+y+
                                "&m="+m+
                                "&divname="+date_dialog_div+
                                "&hiddenvar="+selected_date_hidden_var+
                                "&showeddiv="+selected_date_showed_div+
                                "&selectedday="+selectedday
                              );
	}
    var did = 'htmlcalendar'+date_dialog_div; 
    update_content(did,response);
}

function print_calendar(
                    date_dialog_div,
                    selected_date_hidden_var,
                    selected_date_showed_div
                       ){
	
    var y=document.getElementById("year"+date_dialog_div);
    var m=document.getElementById("month"+date_dialog_div);
    if( y && m ){
		//alert('print_calendar');
        var year=y.options[y.selectedIndex].value;
        var month=m.options[m.selectedIndex].value;
        get_calendar( month,year,
                      date_dialog_div,
                      selected_date_hidden_var,
                      selected_date_showed_div );
    }
}

function print_calendar2(
                    themonth,
                    theyear,
                    date_dialog_div,
                    selected_date_hidden_var,
                    selected_date_showed_div
                       ){
     get_calendar( themonth,
                   theyear,
                   date_dialog_div,
                   selected_date_hidden_var,
                   selected_date_showed_div );

     //Select month and year for comboboxes
    var y=document.getElementById("year"+date_dialog_div);
    var m=document.getElementById("month"+date_dialog_div);
    if( y && m ){
        //Select month
        for(var i=0; i<m.options.length; i++)
          if(m.options[i].value==themonth){
             m.options[i].selected=true;
             break;
          }

        //Select year
        for(var i=0; i<y.options.length; i++)
          if(y.options[i].value==theyear){
             y.options[i].selected=true;
             break;
          }
    }
}

function print_today(
                    theday,
                    themonth,
                    theyear,
                    date_dialog_div,
                    selected_date_hidden_var,
                    selected_date_showed_div
                       ){

     get_calendar( themonth,
                   theyear,
                   date_dialog_div,
                   selected_date_hidden_var,
                   selected_date_showed_div );

     //Select month and year for comboboxes
    var y=document.getElementById("year"+date_dialog_div);
    var m=document.getElementById("month"+date_dialog_div);
    if( y && m ){
        //Select month
        for(var i=0; i<m.options.length; i++)
          if(m.options[i].value==themonth){
             m.options[i].selected=true;
             break;
          }

        //Select year
        for(var i=0; i<y.options.length; i++)
          if(y.options[i].value==theyear){
             y.options[i].selected=true;
             break;
          }
    }

    if(themonth<10) themonth="0"+themonth;
    if(theday<10) theday="0"+theday;

    var thedate='';
    if(dateformat=='ymd')
       thedate=theyear+"/"+themonth+"/"+theday;
    else if(dateformat=='dmy')
       thedate=theyear+"/"+themonth+"/"+theday;
    else
       thedate=themonth+"/"+theday+"/"+theyear; //US format

    if(document.getElementById(selected_date_hidden_var))
       document.getElementById(selected_date_hidden_var).value=thedate
    update_content(selected_date_showed_div, thedate);
    close_datedialog(date_dialog_div);
}

function print_day( d,
                    date_dialog_div,
                    selected_date_hidden_var,
                    selected_date_showed_div  
                   ){
    var y=document.getElementById("year"+date_dialog_div);
    var m=document.getElementById("month"+date_dialog_div);
    if( y && m ){
        var year=y.options[y.selectedIndex].value;
        var month=m.options[m.selectedIndex].value;
        if(month<10) month="0"+month;
        if(d<10) d="0"+d;

        var thedate='';
        if(dateformat=='ymd')
           thedate=year+"/"+month+"/"+d;
        else if(dateformat=='dmy')
           thedate=year+"/"+month+"/"+d;
        else
           thedate=month+"/"+d+"/"+year; //US format

        if(document.getElementById(selected_date_hidden_var))
           document.getElementById(selected_date_hidden_var).value=thedate
        update_content(selected_date_showed_div, thedate);
        close_datedialog(date_dialog_div);
    }
}

function close_datedialog(date_dialog_div){
    if(document.getElementById(date_dialog_div))
       document.getElementById(date_dialog_div).style.display = 'none';
}
