// JavaScript Document
function dispAbout()
{
	$('abt_sub_menus').style.display="block";
	return false;
}
function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}//end of trim functions
	
//checking for empty fields
function is_field_empty(txtfield,errmsg,errdiv)
{
	if("" == trim($(txtfield).value))
	{
		$(errdiv).style.display="block";
		$(errdiv).innerHTML=errmsg;
		$(txtfield).value='';
		$(txtfield).focus();
		return false;
	}
	else
	{
		$(errdiv).innerHTML="";
		$(errdiv).style.display="none";
	}
}
function isValidEmail(email)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(email))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function check_email(txtfield,errmsg,errdiv)
{
	if(!isValidEmail($(txtfield).value))
	{
		$(errdiv).style.display="block";
		$(errdiv).innerHTML=errmsg;
		$(txtfield).select();
		return false;
	}
	return true;
}//end of email validation functions

function check_numeric(txtfield,errmsg,errdiv)
{
	if(isNaN($(txtfield).value))
	{
		$(errdiv).style.display="block";
		$(errdiv).innerHTML=errmsg;
		$(txtfield).select();
		return false;
	}
	else
	{
		$(errdiv).style.display="none";
	}
}//end of number validation function

var curMeasurement = ' m<sup>2</sup>';
function changeMeasurement(){
	var selectedMeasurment = $('measurement').value;
	if(1==selectedMeasurment){
		$('divRoomWidth').innerHTML = 'Room Width (Metres)';
		$('divRoomLength').innerHTML = 'our Length (Metres)';
		curMeasurement = ' m<sup>2</sup>';
	}else if(2==selectedMeasurment){
		$('divRoomWidth').innerHTML = 'Room Width (Feet)';
		$('divRoomLength').innerHTML = 'our Length (Feet)';
		curMeasurement = ' ft<sup>2</sup>';
	}else if(3==selectedMeasurment){
		$('divRoomWidth').innerHTML = 'Room Width (Inches)';
		$('divRoomLength').innerHTML = 'our Length (Inches)';
		curMeasurement = ' in<sup>2</sup>';
	}
	if(('' != $('roomwidth').value) && ($('roomlength').value != ''))calculate();
}
function calculate()
{
	if($('roomwidth').value	== '')
	{
		alert('Please Enter width');
		$('roomwidth').focus();
		return false;
	}
	if(isNaN($('roomwidth').value))
	{
		alert('Please Enter Valid width');
		$('roomwidth').focus();
		return false;
	}
	if($('roomlength').value	== '')
	{
		alert('Please Enter length');
		$('roomlength').focus();
		return false;
	}
	if(isNaN($('roomlength').value))
	{
		alert('Please Enter Valid length');
		$('roomlength').focus();
		return false;
	}
	
	var width	=	$('roomwidth').value;
	var length	=	$('roomlength').value;
	
	
	var resulttext  = 	parseFloat(width) * parseFloat(length);
	$('resultval').innerHTML = resulttext + curMeasurement;
}
function checkneumericlength()
{
	if(isNaN($('roomlength').value))
	{
		alert('Please Enter Valid length');
		$('roomlength').select();
		return false;
	}
	
}
function checkneumericwidth()
{
	if(isNaN($('roomwidth').value))
	{
		alert('Please Enter Valid width');
		$('roomwidth').select();
		return false;
	}
}
	
function showaboutsubmenu(){
	$('aboutussub').style.display="block";
}
function hideaboutsubmenu(){
	$('aboutussub').style.display="none";
}
function showflooringsubmenu(){
	$('flooringsub').style.display="block";
}
function hideflooringsubmenu(){
	$('flooringsub').style.display="none";
}
function newsDetailStory(newsid)
{
	$('newslistform').action = base_url+'/user/Disp_news/' + newsid;
	$('hiddennews').value	=	newsid;
	$('newslistform').submit();
}
function ShowDropDownMenu(count)
{   var passVariable;
	if ($('popup_container').style.display == 'block')
	{
		for (passVariable = 1; passVariable <= count ; passVariable++)
		{
			$('drop_down'+passVariable).style.display = 'none';	
		}
		$('popup_container').style.display = 'none';
	}
	else
	{
		for (passVariable = 1; passVariable <= count ; passVariable++)
		{
			$('drop_down'+passVariable).style.display = 'block';
		}
		$('popup_container').style.display = 'block';
	}
}
function SetSelectedValue(thisVar,CategoryId,totalCount)
{
	ShowDropDownMenu(totalCount);
	$('selected_option').innerHTML = thisVar.innerHTML;
	$('measurement').value = CategoryId;
}
function changeOption(thisVar,CategoryId)
{
	thisVar.className='active_contact_list';
	$('selected_option').innerHTML = thisVar.innerHTML;
	$('measurement').value = CategoryId;
}
function getimgdesc(imgId)
{
	url		   = base_url+'/user/get_image_description/';
	var	params = "imgid=" + escape(imgId);
	new Ajax.Request(url,{method:"post",parameters:params,onSuccess:onsuccess_div,onFailure:disp_error})
}

function onsuccess_div(reqObj)
{ 
	var desc	=	reqObj.responseText.split('#');
	$('imgtitlediv').innerHTML = desc[0];
	$('imgmesgdiv').innerHTML = desc[1];
}
function disp_error()
{
	$('imgtitlediv').innerHTML = "Error while sending the request.";
}//end of ajax functions for user_existence	
function getrugimgdesc(imgId)
{
	url		   = base_url+'/user/get_rugimage_description/';
	var	params = "imgid=" + escape(imgId);
	new Ajax.Request(url,{method:"post",parameters:params,onSuccess:onsuccess_rugdiv,onFailure:disp_rugerror})
}
function onsuccess_rugdiv(reqObj)
{ 
	var desc	=	reqObj.responseText.split('#');
	$('imgtitlediv').innerHTML = desc[0];
	$('imgmesgdiv').innerHTML  = desc[1];
	$('pricediv').innerHTML    = "Price : &pound; "+desc[3];
	$('hidrugid').value		   = desc[2]
}
function disp_rugerror()
{
	$('imgtitlediv').innerHTML = "Error while sending the request.";
}//end of ajax functions for user_existence	

function disp_contact_form()
{
	$('hidcontact').value	=	'1';
	$('contactusform').submit();
}
function disp_rug_contact_form()
{
	$('hidcontact').value	=	'1';
	$('rugsform').submit();
}
function dspContact()
{
	$('hidcontact').value	=	'1';
	$('promotionform').submit();
}
function sendcontact()
{
	if(is_field_empty("contactname","Please Enter Contact Name.","contact_err")==false){return false;}
	if(is_field_empty("contactemail","Please Enter Contact Email.","contact_err")==false){return false;}
	if(check_email("contactemail","Please Enter Valid Email.","contact_err")==false){return false;}
	if(is_field_empty("contactnumber","Please Enter Contact Number.","contact_err")==false){return false;}
	if($("contactnumber").value.length != 13 )
	{
		$("contact_err").style.display="block";
		$("contact_err").innerHTML="Please Enter Your  Valid Phone Number.";
		$("contactnumber").select();
		return false
	}
	$('contactusform').action	   = base_url+'/user/send_contact_details/';
	$('contactusform').submit();
}
function resetcontact()
{
	$('contactusform').reset();
}
function showaboutsubmenu(){
	$('aboutussub').style.display="block";
}
function hideaboutsubmenu(){
	$('aboutussub').style.display="none";
}
function showflooringsubmenu(){
	$('flooringsub').style.display="block";
}
function hideflooringsubmenu(){
	$('flooringsub').style.display="none";
}

function sendcricketform()
{
	if(is_field_empty("contactname","Please Enter Contact Name.","contact_err")==false){return false;}
	if(is_field_empty("contactemail","Please Enter Contact Email.","contact_err")==false){return false;}
	if(check_email("contactemail","Please Enter Valid Email.","contact_err")==false){return false;}
	if(is_field_empty("contactnumber","Please Enter Contact Number.","contact_err")==false){return false;}
	if($("contactnumber").value.length != 13 )
	{
		$("contact_err").style.display="block";
		$("contact_err").innerHTML="Please Enter Your Valid Phone Number.";
		$("contactnumber").select();
		return false
	}
	$('cricketform').action	   = base_url+'/user/send_cricketform_details/';
	$('cricketform').submit();
}
