var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var ph = /^([0-9]){3}\-([0-9]){3}\-([0-9]{4})$/;
function phone_CONTACT(e,t,id) {
	var keycode;
	if(window.event)
		keycode = window.event.keyCode;
	else if(e)
		keycode = e.which;		
	if((t.length==3 || t.length==7) && keycode!=8 )
		document.getElementById(id).value=t+"-";
}

function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

function getID(id)
{
	return document.getElementById(id);
}
function getName(id)
{
	return document.getElementsByName(id);
}

function IsChar(sText)

{
   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
   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 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 printFor(id)
{
	var content = $('#'+id).html();/*document.getElementById(id).innerHTML;*/
	var pwin	= window.open('','front_print_content','width=700,height=500,scrollbars=yes');
	pwin.document.open();
	pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
	pwin.document.close();
}
function captcha()
{	
	getID('img_captcha').src=base_url+'ajax/captcha_load/'+Math.random();	
}

function validatenewsletter(base_url)
{
	var email=document.getElementById('email');
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(email.value=='' || email.value=='Enter your email here')
	{
	    document.getElementById('email').focus();
		document.getElementById('errornews').innerHTML='Please enter your Email Address';
		return false;
	}
	else if(!reg.test(email.value)){
		document.getElementById('errornews').innerHTML='Please enter a valid Email Address';
		email.focus();
		return false;
	}
	$.post(base_url+"front/newsletter", {email:document.getElementById('email').value},
				   function(data){	
				   document.getElementById('email').value='';
				   	if(data==1){document.getElementById('errornews').innerHTML='Email Address already exists';}
					else if(data==3){ document.getElementById('errornews').innerHTML='Please Enter the Correct Email address';}
					else{ 
					document.getElementById('errornews').innerHTML='Thanks for subscribing.';		
					
					}
				   });
	return false;
	
}
// contact form validation
function contact_valid(base_url)
{
	var name=document.getElementById('name').value;	
	var email=document.getElementById('email').value;	
	var phone=document.getElementById('phone').value;	
	var comment=document.getElementById('comments').value;	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var phonevalue=/(^\d{10}$)/;
	if(name=='' || name=='Your Name' )
	{
		
	    var fl= $('#span_name').position();
		var flTOP=parseInt(fl.top)+-10;
	    var flLeft=parseInt(fl.left)+10;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'180px'});
	    document.getElementById('name').focus();
		jQuery.flash.error('', 'Please enter your  Name')
		$("#cverror").html('');	
        $("#sererror").html('');
		return false;

	}
	if(email=='' || email=='E-mail' )
	{
		
	   var fl= $('#span_email').position();
		var flTOP=parseInt(fl.top)+-10;
	    var flLeft=parseInt(fl.left)+3;				
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'205px'});
	    document.getElementById('email').focus();
		jQuery.flash.error('', 'Please enter your Email Address')
		$("#cverror").html('');	
        $("#sererror").html('');
		return false;
	
		
	}
	else if(!reg.test(email)){
		var fl= $('#span_email').position();
		var flTOP=parseInt(fl.top)+-10;
	    var flLeft=parseInt(fl.left)+3;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'205px'});
	    document.getElementById('email').focus();
		jQuery.flash.error('', 'Please enter a valid Email Address')
		$("#cverror").html('');	
        $("#sererror").html('');
		return false;
	}
	if(document.getElementById('comments').value=='' ||document.getElementById('comments').value=='Comments')
	{
	    var fl= $('#csterr').position();
		var flTOP=parseInt(fl.top)+-10;
	    var flLeft=parseInt(fl.left)+10;		
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'200px'});
	    document.getElementById('comments').focus();
		jQuery.flash.error('', ' Please enter Your Comments')
		$("#cverror").html('');	
        $("#sererror").html('');
		return false;	
	}

	var cap=document.getElementById('captcha_txt').value;
	if(cap==''){ 
		var fl= $('#span_captcha').position();
		var flTOP=parseInt(fl.top)+-10;
	    var flLeft=parseInt(fl.left)+10;			
		$("#flash").css({top:flTOP+"px",left:flLeft+'px',width:'220px'});
	    document.getElementById('captcha_txt').focus();
		jQuery.flash.error('', 'Please enter your Verification code')
		$("#cverror").html('');	
        $("#sererror").html('');
		return false;
		}
	$.post(base_url+"front/contactus", {name:name,phone:phone, email:email,comments:comment,captcha:cap,sub_hid:'submit' },
				   function(data){	
				   	if(data==0){
					 clear_value()
					 document.getElementById('img_captcha').src=base_url+'front/captcha_load/'+Math.random();
					 document.getElementById('cverror').innerHTML='Sorry, Your request could not process. Please Try again';

					}
					else if(data==2)
					{
					 document.getElementById('captcha_txt').value='';	
					 document.getElementById('img_captcha').src=base_url+'front/captcha_load/'+Math.random();
					 document.getElementById('cverror').innerHTML='Invalid Verification Code';

					}
					else{ 
					clear_value()
					document.getElementById('cverror').innerHTML='Your request has been sent successfully. We will contact you soon';
					}
					//alert(data);
				   });
	
	return false;
	
}
function clear_value()
{
	document.getElementById('name').value='Your Name';
	document.getElementById('email').value='E-mail';
	document.getElementById('phone').value='Phone Number';
	document.getElementById('comments').value='Comments';
	document.getElementById('captcha_txt').value='';
	
}
// End of the contact form validation

function search_result(base_url)
{
var stext =$("#search").val();
if(stext=="")
{
	//document.getElementById('errorsearch').innerHTML='Please enter Seach Value';
	//$("#search").focus();
	
	
	document.getElementById('search').value='Please enter Seach Value';
    document.getElementById('search').style.color="red";
    return false;
}
}

