var r={
  'special':/[\W]/g,
  'quotes':/['\''&'\"']/g,
  'notnumbers':/[^\d]/g
}

function valid(o,w){
  o.value = o.value.replace(r[w],'');
}

function textCounter(field, countfield, maxlimit)
{
   if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
	else 	
	countfield.value = maxlimit - field.value.length;
}
function assign_value(tocontrol,valueto)
{
	tocontrol.value= valueto;
}


function Email(str)
		{
			var supported = 0;
			if (window.RegExp)
			{
			var tStr = "a";
			var tReg = new RegExp(tStr);
			if (tReg.test(tStr)) supported = 1;
			}
			if (!supported)
			return (str.indexOf(".") <= 5) || (str.indexOf("@") < 0);
			var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
			var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
			return (r1.test(str) || !r2.test(str));
		}
function EmailAddr(str) 
		{
		    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
		}

//------------------------------------------------XXXX------------------------------------------------------////
function form_submit(form)
{
	document.form.submit();
}



function register()
{
		
	if (document.registration.cat_id.value==0)
	{
	alert("Please Select Category");
	document.registration.cat_id.focus();
	document.registration.cat_id.select();
	return false;
	}		
	if (document.registration.title.value==0)
	{
	alert("Please enter your title");
	document.registration.title.focus();
	document.registration.title.select();
	return false;
	}
	if (document.registration.ad_info.value==0)
	{
	alert("Please enter your info");
	document.registration.ad_info.focus();
	document.registration.ad_info.select();
	return false;
	}
	if (document.registration.address.value==0)
	{
	alert("Please enter your address");
	document.registration.address.focus();
	document.registration.address.select();
	return false;
	}
	if (document.registration.first_name.value==0)
	{
	alert("Please enter your Name");
	document.registration.first_name.focus();
	document.registration.first_name.select();
	return false;
	}
	if (Email(document.registration.user_id.value))
	{
	alert("Please enter valid User Id");
	document.registration.user_id.focus();
	document.registration.user_id.select();
	return false;
	}	
	if (document.registration.phone.value==0)
	{
	alert("Please select your phone");
	document.registration.phone.focus();
	document.registration.phone.select();
	return false;
	}
	if (document.registration.mobile.value==0)
	{
	alert("Please select your mobile");
	document.registration.mobile.focus();
	document.registration.mobile.select();
	return false;
	}	
	document.registration.submit();
}

function modify()
{
	if (document.frm_listing.cat_id.value==0)
	{
	alert("Please Select Category");
	document.frm_listing.cat_id.focus();
	document.frm_listing.cat_id.select();
	return false;
	}
		
	if (document.frm_listing.title.value==0)
	{
	alert("Please enter your title");
	document.frm_listing.title.focus();
	document.frm_listing.title.select();
	return false;
	}
	if (document.frm_listing.ad_info.value==0)
	{
	alert("Please enter your info");
	document.frm_listing.ad_info.focus();
	document.frm_listing.ad_info.select();
	return false;
	}
	if (document.frm_listing.address.value==0)
	{
	alert("Please enter your address");
	document.frm_listing.address.focus();
	document.frm_listing.address.select();
	return false;
	}
	if (document.frm_listing.first_name.value==0)
	{
	alert("Please enter your Name");
	document.frm_listing.first_name.focus();
	document.frm_listing.first_name.select();
	return false;
	}
	 
	
	if (document.frm_listing.phone.value==0)
	{
	alert("Please select your phone");
	document.frm_listing.phone.focus();
	document.frm_listing.phone.select();
	return false;
	}
 
	document.frm_listing.submit();
}
function blood_register()
{
		
	if (document.blooddonor_reg.first_name.value==0)
	{
	alert("Please Enter your First Name");
	document.blooddonor_reg.first_name.focus();
	document.blooddonor_reg.first_name.select();
	return false;
	}		
	if (document.blooddonor_reg.blood_group.value==0)
	{
	alert("Please Enter your Blood Group");
	document.blooddonor_reg.blood_group.focus();
	document.blooddonor_reg.blood_group.select();
	return false;
	}
	if (document.blooddonor_reg.gender.value==0)
	{
	alert("Please Enter your Gender");
	document.blooddonor_reg.gender.focus();
	document.blooddonor_reg.gender.select();
	return false;
	}
	if (document.blooddonor_reg.phone.value==0)
	{
	alert("Please Enter your Phone No.");
	document.blooddonor_reg.phone.focus();
	document.blooddonor_reg.phone.select();
	return false;
	}
	if (document.blooddonor_reg.city.value==0)
	{
	alert("Please Enter your City");
	document.blooddonor_reg.city.focus();
	document.blooddonor_reg.city.select();
	return false;	
	}
	if (Email(document.blooddonor_reg.user_id.value))
	{
	alert("Please enter valid Email Id");
	document.blooddonor_reg.user_id.focus();
	document.blooddonor_reg.user_id.select();
	return false;
	}
	if (document.blooddonor_reg.city.value==0)
	{
	alert("Please Enter your City");
	document.blooddonor_reg.city.focus();
	document.blooddonor_reg.city.select();
	return false;	
	}
	if (document.blooddonor_reg.address.value==0)
	{
	alert("Please Enter your Address");
	document.blooddonor_reg.address.focus();
	document.blooddonor_reg.address.select();
	return false;	
	}
	if (document.blooddonor_reg.availability.value==0)
	{
	alert("Please enter blood availablity");
	document.blooddonor_reg.availability.focus();
	document.blooddonor_reg.availability.select();
	return false;	
	} 		
 	
		document.blooddonor_reg.submit();
}
 function wholesaleenquiry()
		{
		
			if (document.enquiry.cname.value==0)
				{
					alert("Please enter Compamy name");
					document.silk.cname.focus();
					document.silk.cname.select();
					return false;
				}
			if (document.enquiry.fname.value==0)
				{
					alert("Please Enter First name");
					document.silk.fname.focus();
					document.silk.fname.select();
					return false;
				}
				if (document.enquiry.phone.value==0)
				{
					alert("Please Enter Phone no");
					document.silk.phone.focus();
					document.silk.phone.select();
					return false;
				}
				if (document.enquiry.mail.value==0)
				{
					alert("Please enter Mail Address");
					document.silk.mail.focus();
					document.silk.mail.select();
					return false;
				}
				if (document.enquiry.city.value==0)
				{
					alert("Please enter the city");
					document.silk.city.focus();
					document.silk.city.select();
					return false;
				}
				if (document.enquiry.email.value==0)
				{
					alert("Please enter EMail Address");
					document.silk.email.focus();
					document.silk.email.select();
					return false;
				}
				if (document.enquiry.state.value==0)
				{
					alert("Please enter State Address");
					document.silk.state.focus();
					document.silk.state.select();
					return false;
				}
				if (document.enquiry.url.value==0)
				{
					alert("Please enter url Address");
					document.silk.url.focus();
					document.silk.url.select();
					return false;
				}
				document.enquiry.submit();
				
		}	
		function feedback()
		{
		
			if (document.conatct.cname.value==0)
				{
					alert("Please enter Compamy name");
					document.conatct.cname.focus();
					document.conatct.cname.select();
					return false;
				}
			if (document.conatct.contact_person.value==0)
				{
					alert("Please Enter Contact person");
					document.silk.contact_person.focus();
					document.silk.contact_person.select();
					return false;
				}
				if (document.conatct.address.value==0)
				{
					alert("Please Enter Address");
					document.conatct.address.focus();
					document.conatct.address.select();
					return false;
				}
				if (document.conatct.email.value==0)
				{
					alert("Please Enter Mail Address");
					document.conatct.email.focus();
					document.conatct.email.select();
					return false;
				}
				if (document.conatct.comments.value==0)
				{
					alert("Please Enter the Comments");
					document.conatct.comments.focus();
					document.conatct.comments.select();
					return false;
				}
				
				document.conatct.submit();
				
		}			
function blood_modify()
{
		
	if (document.blooddonor_reg.first_name.value==0)
	{
	alert("Please Enter your First Name");
	document.blooddonor_reg.first_name.focus();
	document.blooddonor_reg.first_name.select();
	return false;
	}		
	if (document.blooddonor_reg.blood_group.value==0)
	{
	alert("Please Enter your Blood Group");
	document.blooddonor_reg.blood_group.focus();
	document.blooddonor_reg.blood_group.select();
	return false;
	}
	if (document.blooddonor_reg.gender.value==0)
	{
	alert("Please Enter your Gender");
	document.blooddonor_reg.gender.focus();
	document.blooddonor_reg.gender.select();
	return false;
	}
	if (document.blooddonor_reg.phone.value==0)
	{
	alert("Please Enter your Phone No.");
	document.blooddonor_reg.phone.focus();
	document.blooddonor_reg.phone.select();
	return false;
	}
	if (document.blooddonor_reg.city.value==0)
	{
	alert("Please Enter your City");
	document.blooddonor_reg.city.focus();
	document.blooddonor_reg.city.select();
	return false;	
	}
	if (document.blooddonor_reg.city.value==0)
	{
	alert("Please Enter your City");
	document.blooddonor_reg.city.focus();
	document.blooddonor_reg.city.select();
	return false;	
	}
	if (document.blooddonor_reg.address.value==0)
	{
	alert("Please Enter your Address");
	document.blooddonor_reg.address.focus();
	document.blooddonor_reg.address.select();
	return false;	
	}
	if (document.blooddonor_reg.availability.value==0)
	{
	alert("Please enter blood availablity");
	document.blooddonor_reg.availability.focus();
	document.blooddonor_reg.availability.select();
	return false;	
	} 		
 	
		document.blooddonor_reg.submit();
}
function mag_register(mode,frm)
{		
	if (document.frm.first_name.value==0)
	{
		alert("Please enter your name");
		document.frm.first_name.focus();
		document.frm.first_name.select();
		return false;
	}
	if (document.frm.address1.value==0)
	{
		alert("Please enter your address1");
		document.frm.address1.focus();
		document.frm.address1.select();
	return false;
	}
	if (document.frm.state.value==0)
	{
		alert("Please enter your state");
		document.frm.state.focus();
		document.frm.state.select();
	return false;
	}
	if (document.frm.city.value==0)
	{
	alert("Please enter your city");
	document.frm.city.focus();
	document.frm.city.select();
	return false;
	}
	
	if (document.frm.pincode.value==0)
	{
	alert("Please select your mobile");
	document.frm.pincode.focus();
	document.frm.pincode.select();
	return false;
	}
	if (document.frm.phone.value==0)
	{
		alert("Please select your phone");
		document.frm.phone.focus();
		document.frm.phone.select();
	return false;
	}
	if (mode=='new')
	   {
			if (Email(document.frm.user_id.value))
			{
			alert("Please enter valid User Id");
			document.frm.user_id.focus();
			document.frm.user_id.select();
			return false;
			}
	   }		
	
	document.frm.submit();
}
function login1()
{		
	if (Email(document.frm_login.user_id.value))
	{
	alert("Please enter valid User Id");
	document.frm_login.user_id.focus();
	document.frm_login.user_id.select();
	return false;
	}
	if (document.frm_login.password.value==0)
	{
	alert("Your password should not be empty");
	document.frm_login.password.focus();
	document.frm_login.password.select();
	return false;
	}
	if(document.frm_login.password.value.length < 6)
	{ 
	alert('Invalid!Please enter your Correct Password');
	document.frm_login.password.focus();
	document.frm_login.password.select();
	return false;
	}	
    document.frm_login.submit();
}		
 

function changepwd1()
{		
   
	if(document.frmchangepwd.old_password.value==0)
	{ 
	alert('please enter your old password.');
	document.frmchangepwd.old_password.focus();
	document.frmchangepwd.old_password.select();
	return false;
	}

	if(document.frmchangepwd.password.value==0)
	{ 
	alert('Please enter your new password.');
	document.frmchangepwd.password.focus();
	document.frmchangepwd.password.select();
	return false;
	}
	
	if (document.frmchangepwd.confirm_password.value==0)
	{
	alert("Please enter confirm Password");
	document.frmchangepwd.confirm_password.focus();
	document.frmchangepwd.confirm_password.select();
	return false;
	}
	if ((document.frmchangepwd.password.value) != (document.frmchangepwd.confirm_password.value))
	{
	alert("Password mismatch retype your password");
	document.frmchangepwd.confirm_password.focus();
	document.frmchangepwd.confirm_password.select();
	return false;
	}
	if(document.frmchangepwd.password.value.length < 6)
	{ 
	alert('Password should be 6 characters Long.!');
	document.frmchangepwd.password.focus();
	document.frmchangepwd.password.select();
	return false;
	}	
	document.frmchangepwd.submit();
}		

function forgetpwd()
{
	if (Email(document.frmforgetpwd.user_id.value))
	{
		alert("Please enter valid User Id");
		document.frmforgetpwd.user_id.focus();
		document.frmforgetpwd.user_id.selected();
		return false()
	}
	document.frmforgetpwd.submit()
}









function jobs_tellafriends()
{		
	if (document.jobs_tellafriends.name.value==0)
	{
	alert("Please enter your full name");
	document.jobs_tellafriends.name.focus();
	document.jobs_tellafriends.name.select();
	return false;
	}	
document.jobs_tellafriends.submit();
}	

function js_editprofile()
{		

	if (document.frmedit_profile.first_name.value==0)
	{
	alert("Please enter your first name");
	document.frmedit_profile.first_name.focus();
	document.frmedit_profile.first_name.select();
	return false;
	}	
	if (document.frmedit_profile.last_name.value==0)
	{
	alert("Please enter your last name");
	document.frmedit_profile.last_name.focus();
	document.frmedit_profile.last_name.select();
	return false;
	}
	if (document.frmedit_profile.country.value==0)
	{
	alert("Please enter your  Country");
	document.frmedit_profile.country.focus();
	document.frmedit_profile.country.select();
	return false;
	}
	if (document.frmedit_profile.city.value==0)
	{
	alert("Please enter your City");
	document.frmedit_profile.city.focus();
	document.frmedit_profile.city.select();
	return false;
	}			
	document.frmedit_profile.submit();
}	
	

function js_cond_details()
{		
	if (document.frm_cond_details.current_location.value==0)
	{
	alert("Please enter your Location");
	document.frm_cond_details.current_location.focus();
	document.frm_cond_details.current_location.select();
	return false;
	}	
	if (document.frm_cond_details.phone.value==0)
	{
	alert("Please enter your contact no");
	document.frm_cond_details.phone.focus();
	document.frm_cond_details.phone.select();
	return false;
	}			
	if (document.frm_cond_details.mobile.value==0)
	{
	alert("Please enter your mobile no");
	document.frm_cond_details.mobile.focus();
	document.frm_cond_details.mobile.select();
	return false;
	}	
	if (document.frm_cond_details.address.value==0)
	{
	alert("Please enter your address");
	document.frm_cond_details.address.focus();
	document.frm_cond_details.address.select();
	return false;
	}	
		
	document.frm_cond_details.submit();
}			
function js_edu_details()
{		
	document.frm_edu_details.submit();
}	
function js_expdetails()
{		
	document.frm_js_expdetails.submit();
}	

function js_spec_details()
{		
	document.frm_js_spec_details.submit();
}	
function js_summary()
{		

	if (document.frm_js_summary.subject.value==0)
	{
	alert("Please enter your subject of job summary");
	document.frm_js_summary.subject.focus();
	document.frm_js_summary.subject.select();
	return false;
	}	
	if (document.frm_js_summary.body.value==0)
	{
	alert("Please enter your job summary");
	document.frm_js_summary.body.focus();
	document.frm_js_summary.body.select();
	return false;
	}		
	document.frm_js_summary.submit();
} 

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Michael J. Damato | http://developing.damato.net/ */
// State lists
var states = new Array();
states['India'] = new Array('Tamil Nadu','Karanataka','Kerala','Andhra Pradesh');
states['Canada'] = new Array('Alberta','British Columbia','Ontario');
states['Mexico'] = new Array('Baja California','Chihuahua','Jalisco');
states['United States'] = new Array('California','Florida','New York');

// City lists
var cities = new Array();
cities['Canada'] = new Array();
cities['Canada']['Alberta']          = new Array('Edmonton','Calgary');

cities['Canada']['British Columbia'] = new Array('Victoria','Vancouver');
cities['Canada']['Ontario']          = new Array('Toronto','Hamilton');
cities['Mexico'] = new Array();
cities['Mexico']['Baja California'] = new Array('Tijauna','Mexicali');
cities['Mexico']['Chihuahua']       = new Array('Ciudad Juárez','Chihuahua');
cities['Mexico']['Jalisco']         = new Array('Guadalajara','Chapala');
cities['United States'] = new Array();
cities['United States']['California'] = new Array('Los Angeles','San Francisco');
cities['United States']['Florida']    = new Array('Miami','Orlando');
cities['United States']['New York']   = new Array('Buffalo','new York');
cities['India'] = new Array();
cities['India']['Tamil Nadu'] = new Array('Chennai','Coimbatore','Vellore','Madurai');
cities['India']['Karanataka']    = new Array('Bengaluru / Bangalore','Mangalore','Mysoru / Mysore','Hubli');
cities['India']['Kerala']   = new Array('Calicut','Cochin','Ernakulam','Trivandrum');
cities['India']['Andhra Pradesh'] = new Array('Hyderabad / Secunderabad','Nellore','Vijayawada','Visakhapatnam');

function setStates() { 
  cntrySel = document.getElementById('country');
  stateList = states[cntrySel.value];
  changeSelect('state', stateList, stateList);
  setCities();
}
function setCities() {
  cntrySel = document.getElementById('country');
  stateSel = document.getElementById('state');
  cityList = cities[cntrySel.value][stateSel.value];
  changeSelect('city', cityList, cityList);
}
function changeSelect(fieldID, newOptions, newValues) {
  selectField = document.getElementById(fieldID);
  selectField.options.length = 0;
  for (i=0; i<newOptions.length; i++) {
    selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);
  }
}
// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } 
else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(function() {
  setStates();
});
 
 
 //Div format new Rajiv
 function toggleLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if( vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined )
		vis.display = ( elem.offsetWidth != 0 && elem.offsetHeight != 0 ) ? 'block':'none';
	vis.display = ( vis.display == '' || vis.display == 'block' ) ? 'none':'block';
}

function disableSubmit(whichButton)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(whichButton).disabled = true;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[whichButton].disabled = true;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[whichButton].disabled = true;
	}
}

function confirmDelete()
{
    var agree=confirm("Are you sure you wish to delete this entry?");
    if (agree)
        return true;
    else
        return false;
}

function returnObjById( id )
{
	if (document.getElementById)
		var returnVar = document.getElementById(id);
	else if (document.all)
		var returnVar = document.all[id];
	else if (document.layers)
		var returnVar = document.layers[id];
	return returnVar;
}

function setHandler( tagType, clsName, eventType, func )
{
	elements = document.getElementsByTagName( tagType );
	for( var t = 0; t < elements.length; t++ )
	{
		if( elements[t].className.indexOf( clsName ) >= 0 )
		{
			var code = "elements[t]." + eventType + " = " + func;
			eval( code );
		}
	}
}

function toggleColor( )
{
	var style2 = this.style;
	style2.backgroundColor = style2.backgroundColor? "":"#FFFF00";
}

function toggleBgColor( elem )
{
	var style2 = elem.style;
	style2.backgroundColor = style2.backgroundColor? "":"#FFFF00";
}

function externalLinks( )
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

function initpage( )
{
	setHandler( 'tr', 'toggle', 'onclick', 'toggleColor' );
	setHandler( 'span', 'heading', 'onmouseover', 'toggleColor' );
	setHandler( 'span', 'heading', 'onmouseout', 'toggleColor' );
	externalLinks( );
}
if( top.location != self.location )
		top.location = self.location;
window.onload = initpage;


//new js for category like that
// close layer when click-out
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;
  
  // open hidden layer
  function m1open(id)
  {	
  	// cancel close timer
	
  	m1cancelclosetime();
  	// close old layer
  	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';  
  	// get new layer and show it
  	ddmenuitem = document.getElementById(id);
  	ddmenuitem.style.visibility = 'visible';
  
  }
  // close showed layer
  function m1close()
  {
      if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
  }  
  function m1cancelclosetime()
  {
  	if(closetimer)
  	{
      	window.clearTimeout(closetimer);
  		closetimer = null;
  	}
  }



 
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=500,left = 187,top = 134');");
}
 