/*
*******************************************************************                                                 
 *  Com1 (www.com1uk.com), helpdesk@com1uk.com                    *
 *  Registered in England, Wales & India 
 *  Site -  Housingnet.co.uk *
 *  Program Name – rsljsfunctions.js, Created By –  , Created Date*
 *  Purpose –
 *  Modification Note – Applied link and class to Gaz email on line 90*   
 *  Modified Date – 07/08/08  Inserted By – Jyoti on line 319 & 418   * 
 *  Modification Date – 2/09/08                                       *  
 *  Modified by – Jyoti Wadhwani                                      *  
 *  Modification Note – Inserted Validation() in validate_form() function
                        if Logo field is Blank on  
 *  Modification Date – 6/09/08                                       *  
 *  Modified by – Jyoti Wadhwani                                      *  
 *  Modification Note – Modification note added on line 473           *  
 *  Modification Date – 10/11/2008                                       *  
 *  Modified by – Gajendra Umale                                      *  
 *  Modification Note – Removed alerts from Properties Maintained and Address from C&C    
 *  Modified by – Jyoti Wadhwani                                      *  
 *  Modification Note – Replaced images span_up and span_down by span_up_new.gif and by span_up_down.gif *  
 *  Modification Date – 5/2/2009                                       *  
 *  Modified by – Gajendra Umale                                      *  
 *  Modification Note – Added one condition in showhidefields() function for showing MOre link for Housing stock By Local Area.
 *  Modification Date – 2/9/2009                                       *  
 *  Modified by – Gajendra Umale                                      *  
 *  Modification Note – Hide the image in Housing Stock By Local Area.
 *  Modification Date – 2/21/2009                                       *  
 *  Modified by – Gajendra Umale                                      *  
 *  Modification Note – For anchoring Housing stock by local area section
*******************************************************************

*/
/*function ChkRSL(formnm,rslid)        {
        var rsltype = formnm.cmb_rsltype.options[formnm.cmb_rsltype.options.selectedIndex].value;
        if (formnm.txt_parent.value !="" && formnm.txt_parent.value !="0") {

                if (rsltype=="P")        {
                        formnm.status.value="RSLchanged";
                        formnm.txt_parent.value="";
                        //formnm.submit();
						alert("RSLchanged");
                }
        }        else if(formnm.txt_parent.value == "" || formnm.txt_parent.value == "0")        {

                if (rsltype == "S" || rsltype == "A" || rsltype == "B" || rsltype=="C" || rsltype=="O")        {
                        if(confirm("Do you want to add related Housing Association?"))        {
                               
							viewrsllisting("http://www.housingnet.co.uk/selectrsl_21P.php?cmb_rsltype="+formnm.cmb_rsltype.value+"&rsl_id="+rslid);	//window.open("selectrsl_21P.php?cmb_rsltype="+formnm.cmb_rsltype.value,'SelectRSL',"scrollbars=yes,menubar=no,width=700,height=550");
							//alert("opening select rsl popup");
                        }
                }
        }
}*/
function accessSubmitRSL_21P(formnm,actiontype,id,randomno)
{
    if(actiontype=="addjob")
    {
        formnm.action="http://www.housingnet.co.uk/jobsubmit.php";
        formnm.rsl_id.value=id;
        formnm.random_no.value=randomno;
        formnm.submit();
    }
    if(actiontype=="addnews")
    {
        formnm.action="postnews.php";
        formnm.rsl_id.value=id;
        formnm.random_no.value=randomno;
        formnm.submit();
    }
    if(actiontype=="editrsl")
    {
        formnm.action="updatersl.php";
        formnm.rsl_id.value=id;
        formnm.random_no.value=randomno;
        formnm.submit();
    }
}
function DeleteLogo()
{
   if(confirm("Are you sure you want to delete this logo?"))
   {
	   d = new Date;
	   document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	   document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
       document.forms[1].actiontype.value="deletelogo";
	   document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
	   document.forms[1].submit();
   }
}
function canceldetails(rslid,random_no)
{
		document.forms[1].flag_details.value="";
		document.forms[1].action="http://www.housingnet.co.uk/rsldetails_update.php?rsl_id="+rslid+"&random_no="+random_no+"#details";
		document.forms[1].submit();
}
function onfb(field)
{
	var newclass=document.getElementById(field).className;
	if(newclass.substr(0,2) == "wb")
	{
		originalclass=newclass.substr(2,newclass.length);
		document.getElementById(field).className=originalclass;
	}
	else
	{
		var originalclass=document.getElementById(field).className;
		document.getElementById(field).className=originalclass;
	}
	
}
function addnewha(path)
{
	document.forms[1].addnewho.value="addnew";
	document.forms[1].action=path+"addnewho.php?rsl_id="+document.forms[1].rsl_id.value+"&random_no="+document.forms[1].random_no.value+"&addnew=y";
	document.forms[1].submit();
}  
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function savestocks()
{
	var error=false;
	for (var i=0;i<document.forms[1].elements.length ;i++ )
	{
		if(document.forms[1].elements[i].type=="text" && document.forms[1].elements[i].name=="units[]")
		{
			if(!IsNumeric(document.forms[1].elements[i].value) || parseInt(document.forms[1].elements[i].value)==0)
			{
				alert("Please enter valid Units.");
				document.forms[1].elements[i].focus();
				error=true;
				break;
			}	
		}
		if(document.forms[1].elements[i].type=="text" && document.forms[1].elements[i].name=="beds[]")
		{
			if(!IsNumeric(document.forms[1].elements[i].value) || parseInt(document.forms[1].elements[i].value)==0)
			{
				alert("Please enter valid Bedspaces.");
				document.forms[1].elements[i].focus();
				error=true;
				break;
			}	
		}
	}
	d = new Date;
	document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
	document.forms[1].actiontype.value="stocks";
	document.forms[1].stocks_status.value="edit_stocks";
	if(!error)
	{
		document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
		document.forms[1].submit();	
	}
}
function deletestocks(country,lgo,units,beds)
{
	if(confirm("Are you sure you want to delete this stock?"))
	{
		d = new Date;
		document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
		document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
		document.forms[1].cmb_country_area_E.value=country;
		document.forms[1].txt_units_E.value=units;
		document.forms[1].txt_beds_E.value=beds;
		document.forms[1].cmb_localgovt_E.value=lgo;
		document.forms[1].actiontype.value="stocks";
		document.forms[1].stocks_status.value="delete_stocks";
		document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
		document.forms[1].submit();
	}
}
function addeditstocks()
{
	var formnm=document.forms[1];
	var error=false,error_message="";
	if(formnm.cmb_country_area.options[formnm.cmb_country_area.options.selectedIndex].value=="")
	{
		error_message+="Please select Country.\n";
		error=true;
	}
	if(formnm.cmb_localgovt.options[formnm.cmb_localgovt.options.selectedIndex].value=="")
	{
		error_message+="Please select an Area.\n";
		error=true;
	}
	if(!IsNumeric(document.forms[1].txt_units.value) || parseInt(document.forms[1].txt_units.value)==0 || document.forms[1].txt_units.value=="")
	{
		error_message+="Please enter valid Units.\n";
		document.forms[1].txt_units.focus();
		error=true;
	}
	if(document.forms[1].txt_beds.value!="")
	{
	if(!IsNumeric(document.forms[1].txt_beds.value) || parseInt(document.forms[1].txt_beds.value)==0)
	{
		error_message+="Please enter valid Bedspaces.\n";
		document.forms[1].txt_beds.focus();
		error=true;
	}
	}
	for(i=0;i<document.forms[1].elements.length;i++)
	{
		if(document.forms[1].elements[i].name=="localgovtid[]")
		{
			if(document.forms[1].elements[i].value==formnm.cmb_localgovt.options[formnm.cmb_localgovt.options.selectedIndex].value)
			{
			error_message+="Please enter units with different Local area.\n";
			error=true;
			}
		}
	}
	d = new Date;
	document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
	document.forms[1].actiontype.value="stocks";
	if(!error)
	{
		document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
		document.forms[1].submit();	
	}
	else
	{
		alert(error_message);
	}
}
function chk_field_empty(field,caption,value_check)
{
	if(document.getElementById(field).value==value_check)
	{
		
		return "* "+caption+" should not be empty.\n";
	}
	else
	{
		return "";
	}
}
var remail=/^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;
function checkEmail(field) 
{
	if(document.getElementById(field).value!='')
	{
	if(remail.test(document.getElementById(field).value))
		return false;
	else
		return true;
	}
	else
		return false;
}

function validate_form(actiontype)
{
	var error;
	var error_string="";
	d = new Date;
	document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
	if(actiontype=="addr")
	{
		error1=chk_field_empty("txt_addr1","Address 1","");
		error2=chk_field_empty("txt_postcode","Post Code","");
		error3=chk_field_empty("cmb_county","County","");
		error4=chk_field_empty("cmb_country","Country","");
		if(error1=="" && error2=="" && error3=="" && error4=="")
		{
			document.forms[1].actiontype.value="addr";
		}
		else
		{
			error_string=error1+error2+error3+error4;
		}
	}
	else if(actiontype=="type")
	{
		error5=chk_field_empty("cmb_rsl_types2","H.O. Type","0");
		if(error5=="")
		{
			document.forms[1].actiontype.value="type";
		}
		else
		{
			error_string=error5;
		}
	}
	else if(actiontype=="govtid")
	{
		error5=chk_field_empty("cmb_govtid","Local Authority Area","0");
		if(error5=="")
		{
			document.forms[1].actiontype.value="govtid";			
		}
		else
		{
			error_string=error5;
		}
	}
	else if(actiontype=="email")
	{
		if(!checkEmail("txt_email"))
		{
			//document.forms[1].actiontype.value="email";
		}
		else
		{
			//error_string="* Please enter a valid email address.";
			//error_string=document.getElementById("txt_email").value;

		}
	
		//added condition to remove the email and let form submit
		if(document.getElementById("txt_email").value !="")
		{
			if(remail.test(document.getElementById("txt_email").value))
			{
				//return false;
				
				document.forms[1].actiontype.value="email";
			}
			else
			{
				//return true;
				error_string="* Please enter a valid email address.";
			}
		}
		else
		{
			document.forms[1].actiontype.value="email";
		}

	}
	else if(actiontype=="chk_add_confirm")
	{
		//if(confirm("Are you sure you want to save."))
		//	{	
			    document.forms[1].actiontype.value=actiontype;
				document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
				document.forms[1].submit();
			/*}
			else
			{
				if(document.getElementById("chk_contacts").checked==true)
				{
					document.getElementById("chk_contacts").checked=false;
				}
				else
				{
					document.getElementById("chk_contacts").checked=true;
				}
				return false;
			}*/
	}
	else if(actiontype=="web")
	{
		checkwebaddr();
		document.forms[1].actiontype.value="web";
	}
	//Code added by Jyoti on 7/08/08 to insert comment box validation for its 8lines
    else if(actiontype=="comment")
	{   
		var newlineCount = document.getElementById("txt_comment").value.split('\n'); 
		var len=0;
	   for(i=0;i<newlineCount.length;i++)
	   {
			if(newlineCount[i]!=null && newlineCount[i]!="")
		    {
				len++;//len has actual number of newline chracters.
			
			}
	   }
	   if(len>8)
	   {
         error_string="* Maximum length of comment should be 8 lines.";
	   }
	    else
		{
		 document.forms[1].actiontype.value="comment";
		}
	  
	}

	else if(actiontype=="contact_email")
	{
		if(!checkEmail("txt_contact_email"))
		{
			//document.forms[1].actiontype.value="contact_email";
		}
		else
		{
			//error_string="* Please enter a valid email address.";

		}
		if(document.getElementById("txt_contact_email").value=="")
		{
			document.forms[1].actiontype.value="contact_email";
		}
		else
		{
			if(remail.test(document.getElementById("txt_contact_email").value))
			{
				//return false;
			
				document.forms[1].actiontype.value="contact_email";
			}
			else
			{
				//return true;
				error_string="* Please enter a valid email address.";
			}
		}
	}
	else if(actiontype=="rsl_type")
	{
		error6=chk_field_empty("rel_name","Name of HA to which you are related","");
		error7=chk_field_empty("cmb_rsltype","Relationship Type","");
		//alert(error6+error7);
		if(error6=="" && error7=="")
		{
			if(confirm("Are you sure you want to save your request to change Housing Organisation Relationship?"))
			{
				document.forms[1].actiontype.value=actiontype;
			}
			//alert("HI");
		}
		else 
		{
			error_string=error_string+error6+error7;
		}
	}
	else if(actiontype=="rslmail")
	{
		error8=chk_field_empty("txtar_message","Your Message","");
		if(!checkEmail("rslemail") && error8=="")
		{
			document.forms[1].actiontype.value="rslmail";
		}
		else
		{
			error9="* Please enter a valid email address.";
			error_string=error8+error9;
		}
	}
	else if(actiontype=="title")
	{
		error10=chk_field_empty("txt_title","Housing Association title","");
		if(error10=="")
		{
			document.forms[1].actiontype.value="title";
		}
		else
		{
			error_string=error10;
		}
	}
	else if(actiontype=="property")
	{
		//if(confirm("Are you sure you want to save."))
		//{	
				document.forms[1].actiontype.value=actiontype;
			
				document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
				document.forms[1].submit();
		/*}
		else
		{
			return false;
		}*/
		
	}
	/* validation for Logo -Added- Jyoti 2/09/08*/
    else if(actiontype=="logo")
	{
		if (chk_field_empty("txt_logo","logo",""))
		{
           error_string="Please choose the Logo first and then save.";
		}
		else 
			document.forms[1].actiontype.value="logo";
	}
	else if(actiontype=="rating")
	{
		if(chk_field_empty("inspreport","",""))
		{
			 error_string="* Please upload inspection report first";
		}
		else
		{
			document.forms[1].actiontype.value="rating";
		}
	}
	/*else if(actiontype=="serqlty")
	{
		if(chk_field_empty("drpservqty","",""))
		{
			 error_string="Please select the service quality value";
		}
		else
		{
			document.forms[1].actiontype.value="serqlty";
		}
	}*/
	else if(actiontype=="imprpros")
	{
		if(chk_field_empty("inspreport","",""))
		{
			 error_string="* Please upload inspection report first";
		}
		else
		{
			document.forms[1].actiontype.value="imprpros";
		}
	}
	else
	{	
		
		document.forms[1].actiontype.value=actiontype;
		document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
		document.forms[1].submit();
		

	}
	if(error_string!="")
	{
		error="Please make following corrections:\n"+error_string;
		alert(error);
	}
	else
	{
		
		document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php";
		document.forms[1].submit();
		
	}
	
}
function checkwebaddr() 
{
	var path = document.forms[1].txt_web.value;
	if(path!="")
	{
		if(path.substr(0,7) != "http://") 
		{
			if(path.substr(0,8) == "https://")
			{
				document.forms[1].txt_web.value=document.forms[1].txt_web.value;
			}
			else
			{
				document.forms[1].txt_web.value="http://"+document.forms[1].txt_web.value;
			}
		} 
	}
}

///new parameter added Here By Rupali
function disable_span(field,nodatafield)
{
	document.getElementById(field).innerHTML = "";
	document.getElementById(field).style.visibility = "hidden";
	
	///following line added By Rupali
	document.getElementById(nodatafield).style.display="block";
	
	if(field=="spproperty")
	{
		document.getElementById("propertysp").src="http://www.housingnet.co.uk/images/span_up_new.gif";
		window.location.hash="property";// changed from top to property to cause Anchoring for cancel button of properties maintained section


	}
	
	if(field=="sprsl_type")
	{
		document.getElementById("rsl_typesp").src="http://www.housingnet.co.uk/images/span_up_new.gif";
		window.location.hash="top";
	}
	if(field=="spstocks")
	{
		window.location.hash="property";
	}
}
function check_span_open(sp_name)
{
	if(document.getElementById(sp_name).style.visibility=="hidden" || document.getElementById(sp_name).style.visibility=="")
	{
		
		return "hidden";
	}
	else
		return "visible";
}
// Added condition for Comment Box - Jyoti on 7\08\08
function showhidefields(rslid,actiontype,f1,f2,f3,f4,f5,f6,f7)
{

	if(actiontype=="addr" || actiontype=="fax" || actiontype=="phone" || actiontype=="web" || actiontype=="FBURL" || actiontype=="twitter" || actiontype=="email" || actiontype=="type" || actiontype=="govtid" || actiontype=="reg" || actiontype=="logo" || actiontype=="contact_name" || actiontype=="contact_email" || actiontype=="contact_email" || actiontype=="title" || actiontype=="rslmail" || actiontype=="comment" || actiontype=="rating" || actiontype=="imprpros" || actiontype=="serqlty")
	{	
		showfields(rslid,actiontype,f1,f2,f3,f4,f5,f6,f7);
	}
	else if(actiontype=="property")
	{

		if(check_span_open("spproperty")=="hidden")
		{
			document.getElementById("propertysp").src="http://www.housingnet.co.uk/images/span_down_new.gif";
			showfields(rslid,actiontype,f1,f2,f3,f4,f5,f6,f7);
			
		}
		else
		{
			document.getElementById("propertysp").src="http://www.housingnet.co.uk/images/span_up_new.gif";
			disable_span("spproperty","spproperty");
			
		}
	}
	else if(actiontype=="sp_more_link")
	{

		if(check_span_open("sp_more_link")=="hidden")
		{
			//document.getElementById("sp_more_link1").src="http://www.housingnet.co.uk/images/span_down_new.gif";
			
			document.getElementById("sp_total_unit").style.visibility = "hidden";
			showfields(rslid,actiontype,f1,f2,f3,f4,f5,f6,f7);
			
		}
		else
		{
		
			document.getElementById("sp_total_unit").style.visibility = "visible";
			//document.getElementById("sp_more_link1").src="http://www.housingnet.co.uk/images/span_up_new.gif";
			
			disable_span("sp_more_link","sp_more_link");
			
		}
	}
	else if(actiontype=="details")
	{
		if(document.forms[1].flag_details.value=="")
			showfields(rslid,actiontype,f1,f2,f3,f4,f5,f6,f7);
		else
			canceldetails(rslid);
	}
	else if(actiontype=="rsl_type")
	{
		if(check_span_open("sprsl_type")=="hidden")
		{
			document.getElementById("rsl_typesp").src="http://www.housingnet.co.uk/images/span_down_new.gif";
			showfields(rslid,actiontype,f1,f2,f3,f4,f5,f6,f7);
			
		}
		else
		{
			document.getElementById("rsl_typesp").src="http://www.housingnet.co.uk/images/span_up_new.gif";
			disable_span("sprsl_type");
			
		}
	}
	else if(actiontype=="stocks")
	{
		if(check_span_open("spstocks")=="hidden")
		{
			document.getElementById("stockssp").src="http://www.housingnet.co.uk/images/span_down_new.gif";
			showfields(rslid,actiontype,f1,f2,f3,f4,f5,f6,f7);
			
		}
		else
		{
			document.getElementById("stockssp").src="http://www.housingnet.co.uk/images/span_up_new.gif";
			disable_span("spstocks","spstocks");
			
		}
	}
}
function getboxopen()
{
	showhidefields(document.forms[1].rsl_id.value,document.forms[1].flag_show1.value,'','','','','','','');
}
function DeleteRSR(str_year)
{
	if(str_year=="")
	{
		alert("Please select year.");
		return false;
	}
   if(confirm("Are you sure you want to delete RSR Survey?"))
   {
	   //d = new Date;
	   //document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	  // document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
       document.forms[1].actiontype.value="deletersr";
	   document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php?str_year="+str_year;
	   document.forms[1].submit();
   }
}

function DeleteAnn(str_year)
{
	if(str_year=="")
	{
		alert("Please select year.");
		return false;
	}
   if(confirm("Are you sure you want to delete Annual Report?"))
   {
	   //d = new Date;
	   //document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	  // document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
       document.forms[1].actiontype.value="deleteann";
	   document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php?str_year="+str_year;
	   document.forms[1].submit();
   }
}
function DeleteFin(str_year)
{
	if(str_year=="")
	{
		alert("Please select year.");
		return false;
	}
   if(confirm("Are you sure you want to delete Financial Report?"))
   {
	   //d = new Date;
	   //document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	  // document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
       document.forms[1].actiontype.value="deletefin";
	   document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php?str_year="+str_year;
	   document.forms[1].submit();
   }
}
function DeleteOt1(str_year)
{
	if(str_year=="")
	{
		alert("Please select year.");
		return false;
	}
   if(confirm("Are you sure you want to delete the Report?"))
   {
	   //d = new Date;
	   //document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	  // document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
       document.forms[1].actiontype.value="deleteot1";
	   document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php?str_year="+str_year;
	   document.forms[1].submit();
   }
}
function DeleteOt2(str_year)
{
	if(str_year=="")
	{
		alert("Please select year.");
		return false;
	}
   if(confirm("Are you sure you want to delete the Report?"))
   {
	   //d = new Date;
	   //document.forms[1].hiddate.value = d.formatDate("Y-m-d") ;
	  // document.forms[1].hidtime.value = d.formatDate("h:i:s:a");
       document.forms[1].actiontype.value="deleteot2";
	   document.forms[1].action="http://www.housingnet.co.uk/bkupdatersldetails.php?str_year="+str_year;
	   document.forms[1].submit();
   }
}



