
var counter;
function onChkClick(a){

	
	if(a.checked==true){

			counter++;
			chk=true;
			
	}else{

			counter--;
			chk=false;

	}
	
	//alert(document.frmFeatureHome.chk.length);

	/*if (counter==document.frmFeatureHome.chk.length){

			document.frmFeatureHome.main.checked=true;

	}else{

		if (document.frmFeatureHome.main.checked=true){
		
			document.frmFeatureHome.main.checked=false;
		}

	}*/
}

function trim(text){

	var chr=false;
	var len;

	for(i=0;i<text.value.length;i++){
		
		if(text.value.substr(i,1) != " "){
			chr=true;
			len = i;
			break;

		}

	}
	
	if(chr == false){

		text.value="";
	
	}else{

		text.value = text.value.substr(len,text.value.length);
	
	}


	for(i = text.value.length ; i>0 ; i--){
		
		if(text.value.substr(i-1,1) != " "){
			len = i;
			break;

		}

	}
	
	text.value = text.value.substr(0,len);

}





//FOR VALIDATING EMAIL
/*function checkEmail(txt){
	trim(txt);
	var value=txt.value;
	
	if( (value.indexOf("@") != -1) &&  (value.indexOf(".") != -1) ){

			return true;

	}else{
		txt.focus();
		return false;
		
	}

}*/
var testresults;
function checkEmail(txt){
	trim(txt);
	var str=txt.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,3}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
	testresults=true
	}else{
		
		testresults=false
	}
	return (testresults)

}

function checkUrl(txt){
	trim(txt);
	var value=txt.value;
	value = value.toLowerCase();
	
	if( (value.length >= 11) && (value.substr(0,11) == "http://www.") && (value.length>=15) ){
	
			return true;
	
	}else return false;

}


function checkUrlContact(txt){
	trim(txt);
	var value=txt.value;
	value = value.toLowerCase();
	
	if( (value.length >= 4) && (value.substr(0,4) == "www.") && (value.length>=9) && (value.indexOf(".") > 2)){
	
			return true;
	
	}else return false;

}




//FOR VALIDATION OF THE EACH TYPE OF THE FIELDS
var type;
function validate(t){

	type=t;
	if (navigator.appName.indexOf("Microsoft") == -1){

	
		window.captureEvents(Event.KEYPRESS);
		window.onkeypress = validate2;

	}else{
	
		validate2(window.event);
	}


}


function validate2(e){

	var validString;
	var code;

	if (navigator.appName.indexOf("Microsoft")!= -1){

			code = e.keyCode;

	}else{
		
		code = e.which;
	}

	var ch = String.fromCharCode(code);

	if(type == "ALPHA_NUMERIC"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 ";
	
	}else if(type == "EMAIL"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789@._";

	}else if(type == "ALPHA_NUMERIC_COMMA"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789@._,-";

	}else if(type == "NUMBER"){

		validString="0123456789 .";

	}else if(type == "ALPHA"){

		validString="abcdefghijklmnopqrstuvwxyz ";

	}else if(type == "ALPHA_NUMERIC_SPECIALCHAR"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,";

	}else if(type == "URL"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789.:/";

	}else if(type == "PHONE"){
	
		validString="1234567890()-abcdefghijklmnopqrstuvwxyz";
	
	}else if(type == "ALPHA_NUMERIC_SPECIALCHAR_WITH_QUOTES"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,'\"";

	}else if(type == "TIME"){
		
		validString="1234567890:";
		
	}else if(type == "COMPANYNAME"){
		
		validString="abcdefghijklmnopqrstuvwxyz0123456789 '()";
		
	}else if(type == "ONLY_NUMBER"){

		validString="0123456789";

	}else if(type == "HOST"){
		
		validString="abcdefghijklmnopqrstuvwxyz0123456789.";
	}

	
	//code of ENTER key
	if( code != 13){

		if( validString.indexOf( ch.toLowerCase() ) == -1 ){

			if(e.keyCode){

				e.keyCode=0;

			}else{
				
				return false;

			}

		}
	
	}

}


function replaceQuotes(textBox){
	
	for(i=0; i < textBox.value.length; i++){
	
		textBox.value = textBox.value.replace("'","&#39;");
		textBox.value = textBox.value.replace("\"","&#34;");
		
	}	

}

function stretch(selectedImage,requiredWidth,requiredHeight){
	
	
	if( selectedImage.width > requiredWidth ){
		selectedImage.width = requiredWidth;
	
	}


	if( selectedImage.height > requiredHeight ) {
				selectedImage.width = selectedImage.width - 1;

				stretch(selectedImage,selectedImage.width,requiredHeight);

	}
	selectedImage.style.display="block";

}



function finalCheck(){

	e = document.forms[0].elements;

	for(i=0; i< e.length ; i ++){

		if(e[i].type == "text"){

			if( e[i].onkeypress != null){
				
				validator = e[i].onkeypress.toString();

				if( validator.indexOf("\"") != -1 ){
			
						type = validator.substring( validator.indexOf("\"")+1 ,validator.lastIndexOf("\"") );

				}else{
		
						type = validator.substring( validator.indexOf("'")+1 , validator.lastIndexOf("'") ) ;

				}	


				if( validateStr(type,e[i].value) == false){

					alert("Invalid value.");
					e[i].focus();
					return false;

				}

			}

		}

	}

	return true;

}


function validateStr(type,str){
		
		var validString;

		if(type == "ALPHA_NUMERIC"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 ";
		
		}else if(type == "EMAIL"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789@._";

		}else if(type == "ALPHA_NUMERIC_COMMA"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789@._,-";

		}else if(type == "NUMBER"){

			validString="0123456789 .";

		}else if(type == "ALPHA"){

			validString="abcdefghijklmnopqrstuvwxyz ";

		}else if(type == "ALPHA_NUMERIC_SPECIALCHAR"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,";

		}else if(type == "URL"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789.:/";

		}else if(type == "PHONE"){
		
			validString="1234567890()-abcdefghijklmnopqrstuvwxyz";
		
		}else if(type == "ALPHA_NUMERIC_SPECIALCHAR_WITH_QUOTES"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,'\"";

		}else if(type == "TIME"){
			
			validString="1234567890:";
			
		}else if(type == "COMPANYNAME"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 '()";

		}else if(type == "ONLY_NUMBER"){

			validString="0123456789";

		}else if(type == "HOST"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789.";
		
		}


		for(var i=0 ; i < str.length; i++){

			if( validString.indexOf( str.charAt(i).toLowerCase()) == -1  ){
			
				return false;

			}

		}

		return true;


}