// JavaScript Document

// function for bg image div click//


function bg_imagediv(gh)
{
	
document.getElementById('bgimgdiv'+gh).style.display='block';	
}

// close bgimage div//

function close_bgimgdiv(ghclose)
{
	//alert(ghclose);
document.getElementById('bgimgdiv'+ghclose).style.display='none';	
	
}

//function for search display or not//

function inclickcheck(field,def,val)
{
	if(field.value == def)
	{
		field.value = val;
	}
}

// for google search form submit//
function searchgoogle()
{

	
	document.googleform.submit();
	
}




// functions to remove extra spaces from a string
function LTrimAll(str) {
if (str==null){return str;}
for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
return str.substring(i,str.length);
}
function RTrimAll(str) {
if (str==null){return str;}
for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
return str.substring(0,i+1);
}
function TrimAll(str) {
return LTrimAll(RTrimAll(str));
}



// this function check the email validation.
function is_valid_email(e)
{
  e = (e.toLowerCase()).strip();
  if (e == '')
    return EMAIL_BLANK;
  regex = /^\s*[a-z0-9-+\_\.]+@[a-z0-9-_\.]+\.[a-z]{2,4}\s*$/;
  if(!regex.test(e))
    return EMAIL_BAD_SYNTAX;
  return EMAIL_OK;
}


// variable containing all special character
var iChars = "!@#$%^&*()=[]\\\'/{}|\":<>?~`";
function checkspchar(val)
{
  for (var i = 0; i < TrimAll(val).length; i++) 
  {
	  
  		if (iChars.indexOf(TrimAll(val).charAt(i)) != -1) 
		{
  			//alert ("Your name has special characters.\n Please remove them and try again.");
			//var obj = getObject(id);
			//obj.focus();
  			return false;
		}
   }
   return true;
}	


function hasWhiteSpace(s) 
{
 
     var slen = s.length;
	 
	 for( var i=0; i<slen ; i++)
	 {
	 	if(s.charAt(i)==' ')
		{ return false;
		}
	 }
	 
	 
	
return true;
}


// below three variable r using to define  the email validation states.
var EMAIL_OK = 0;
var EMAIL_BLANK = 1;
var EMAIL_BAD_SYNTAX = 2;




// function for check the user signup vaildation//

function validate_signup()
{ 
		
		 var reg_name = ($('signup_username').value);
		 var reg_password = $('password').value;
	  	 var reg_password_verify = $('password2').value;
		 var reg_email = ($('email').value.toLowerCase()).strip();
		 var reg_fname = $('f_name').value;
	  	 var reg_lname = $('l_name').value;
	  	 var reg_gender = $('gender').value;
		 var reg_captcha =  $('captcha').value;
		 var reg_country = $('country').value;
	  	 var reg_zipcode = $('zip').value; 
		 var reg_checkbox = $('tccheckbox').checked;
	  
	  	 var validate_error_message = '';
	  	 var reg_errors = new Array();
	  	 var field_to_focus = '';
		 
		 
		
		 
	var name_space =  hasWhiteSpace(reg_name);
	if(!name_space)
	{
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please space remove from Username';
	   return false;
	}
 

	  
  if(reg_name=='')
  {
	  //reg_errors.push('Please enter a username');
	  Element.show('r_name');
	   $('r_name').innerHTML = 'Please enter a Username';
	   field_focus('signup_username');
    
	return false;
  }
  
  if(!isNaN(reg_name))
		{
			Element.show('r_name');
	 $('r_name').innerHTML = "Your name has Numeric value.\n Please remove them and try again.";
	return false;
		}
		
		
		
  
  var rg_uname = reg_name.length;
  if (rg_uname > 0 && (rg_uname < 5 || rg_uname > 15) || (rg_uname > 0 && (rg_uname < 5 || rg_uname > 15)))
    { 
      //reg_errors.push('Your username should be between 5 and 15 characters.');
	    Element.show('r_name');
	  $('r_name').innerHTML = "Your username should be between 5 and 15 characters.";
     field_focus('signup_username');
		return false;
	}
	
	var schar = checkspchar(reg_name);
	
	if(!schar)
	{
	 Element.show('r_name');
	 $('r_name').innerHTML = "Your name has special characters.\n Please remove them and try again.";
	return false;
	}
	
	$('r_name').innerHTML ='';
  
	
	
  
  
  if (reg_password == '')
  {
    //reg_errors.push('Please enter a password.');
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please enter a password';
	   field_focus('password');
   
	  return false;
  }
  
  var name_pass =  hasWhiteSpace(reg_password);
	if(!name_pass)
	{
		
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please space remove from password';
	   return false;
	}
  
  if (reg_password_verify == '')
  {
    //reg_errors.push('Please enter your password again for verification.');
	
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please enter your password again for verification.';
	  
    field_focus('password2');
	  
	   return false;
  }
  
  var name_repass =  hasWhiteSpace(reg_password_verify);
	if(!name_repass)
	{
		
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please space remove from Retype-password';
	   return false;
	}
  
  rgl = reg_password.length;
  rglv = reg_password_verify.length;
  if (reg_password != '' && reg_password_verify != '' && reg_password != reg_password_verify)
  {
    //reg_errors.push('The passwords you entered do not match.');
	
	 Element.show('r_name');
	   $('r_name').innerHTML = 'The passwords you entered do not match';
	  
     field_focus('password');
	   return false;
  }
  else
  {
    if (rgl > 0 && (rgl < 6 || rgl > 15) || (rglv > 0 && (rglv < 5 || rglv > 15)))
    { 
      //reg_errors.push('Your password should be between 5 and 15 characters.');
	  Element.show('r_name');
	   $('r_name').innerHTML = 'Your password should be between 6 and 15 characters';
      field_focus('password');
		return false;
    }
  }
  /*if (  reg_password != '' && reg_password_verify != '' &&
        (reg_password.toLowerCase() == reg_email.toLowerCase() ||
        reg_password.toLowerCase() == reg_email.toLowerCase().substring(0, reg_email.indexOf('@'))) )
  {
    reg_errors.push('Your password is too easy to guess. Please try a different one.');
    if (field_to_focus == '')
      field_to_focus = 'password';
  }*/
  
  if (is_valid_email(reg_email) == EMAIL_BAD_SYNTAX)
  {
    //reg_errors.push('Please enter a valid email address, such as name@domain.com.');
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please enter a valid email address, such as name@domain.com.';
    field_focus('email');
	return false;
  }
  else
  {
    if (reg_email == '')
    {
     // reg_errors.push('Please enter an email address.');
	   Element.show('r_name');
	   $('r_name').innerHTML ='Please enter an email address.';
       field_focus('email');
	  return false;
    }
  }
  
  if (reg_fname == '')
    {
     // reg_errors.push('Please enter First Name.');
	   Element.show('r_name');
	   $('r_name').innerHTML ='Please enter First Name.';
      field_focus('f_name');
	  return false;
    }
	 var name_fname =  hasWhiteSpace(reg_fname);
	if(!name_fname)
	{
		
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please space remove from First name';
	   return false;
	}
  
   if (reg_lname == '')
    {
      //reg_errors.push('Please enter Last Name.');
	   Element.show('r_name');
	   $('r_name').innerHTML ='Please enter Last Name.';
      field_focus('l_name');
	  return false;
    }
  
  var name_lname =  hasWhiteSpace(reg_lname);
	if(!name_lname)
	{
		
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please space remove from Last Name.';
	   return false;
	}
   if (reg_gender == '')
    {
      //reg_errors.push('Please enter gender.');
	   Element.show('r_name');
	   $('r_name').innerHTML ='Please Select gender.';
      field_focus('gender');
	  return false;
    }
	
	
	
	
	
	
  if (reg_country == '')
    {
      //reg_errors.push('Please enter Country.');
	   Element.show('r_name');
	   $('r_name').innerHTML ='Please enter Country.';
      field_to_focus = 'country';
	  return false;
    }
	var name_cont = hasWhiteSpace(reg_country);
	if(!name_cont)
	{
		
	 Element.show('r_name');
	   $('r_name').innerHTML = 'Please space remove from country name.';
	   return false;
	}
	
	
	
	
	
   if (reg_captcha == '')
    {
     // reg_errors.push('Please enter image value.');
	  Element.show('r_name');
	   $('r_name').innerHTML ='Please enter image value.';
      field_to_focus = 'country';
	  return false;
    }
  
  if(reg_checkbox==false)
  {
	  Element.show('r_name');
	   $('r_name').innerHTML ='Please accept the Term & Condition.';
  //reg_errors.push('Please accept the Term & Condition.');
  return false;
  }
  
 /* if (reg_errors.length > 0)
  {
    for (i = 0; i < reg_errors.length; ++i)
      validate_error_message += reg_errors[i] + '\n';
    alert(validate_error_message);
    if (field_to_focus != '' && (ff = document.getElementById(field_to_focus)))
      ff.focus();
    return false;*/
  
  else
  {
  unique_user_check();
  }
  
}
// for focus particular field//

function field_focus(field_to_focus)
{
var ff = document.getElementById(field_to_focus);
      ff.focus();
    return false
}
// for signup check unique username//

function unique_user_check()
{
	
	 var user_check = ($('signup_username').value).strip();
	 
	var user_url = 'site_process.php';
	var user_pars = 'rq='+4+'&user_val=' + user_check;
		
		var myAjax = new Ajax.Request(
			user_url, 
			{
				method: 'get', 
				parameters: user_pars, 
				onComplete: user_showResponse
			});
	
	
}

function user_showResponse(originalRequest)
{
	
	//alert(originalRequest.responseText);
	if(originalRequest.responseText==1)
	{
		
		//alert("username allready exist pls change username");
		Element.show('r_name');
	   $('r_name').innerHTML ='Username already exist Please change Username.';
	}
	else
	{
	unique_mail_check()
	}
}

// for signup check unique mail//

function unique_mail_check()
{
	
	 var mail_check = ($('email').value.toLowerCase()).strip();
	 
	var mail_url = 'site_process.php';
	var mail_pars = 'rq='+3+'&mail_val=' + mail_check;
		
		var myAjax = new Ajax.Request(
			mail_url, 
			{
				method: 'get', 
				parameters: mail_pars, 
				onComplete: mail_showResponse
			});
	
	
}

function mail_showResponse(originalRequest)
{
	
	//alert(originalRequest.responseText);
	if(originalRequest.responseText==1)
	{
		
		//alert("email allready exist pls enter another email address");
		 Element.show('r_name');
	   $('r_name').innerHTML ='Email already exist please enter another email address.';
	}
	else
	{
	//captchaimg();
	signup_user();
	}
}



// function for check the captcha image is correct or not for signup//

/*function captchaimg()
{
	var captcha_val = $('captcha').value;
	
	//alert(captcha_val);
	
	var captcha_url = 'site_process.php';
	var captcha_pars = 'rq='+1+'&capt_val=' + captcha_val;
		
		var myAjax = new Ajax.Request(
			captcha_url, 
			{
				method: 'get', 
				parameters: captcha_pars, 
				onComplete: captcha_showResponse
			});
		
}
	
function captcha_showResponse(originalRequest)
{
	//alert(originalRequest.responseText);
	
	if(originalRequest.responseText==1)
	{
		
		signup_user();
	}
	else
	{
		 Element.show('r_name');
	   $('r_name').innerHTML ='Please enter again image Text.';
	//alert("pls enter again image text");
	}
}*/


// function for signup the new user///


function signup_user()
{
		//alert("insert");
		var signup_username = ($('signup_username').value.toLowerCase()).strip();
		 var signup_password = $('password').value;
	  	 var signup_cpassword = $('password2').value;
		 var signup_email = ($('email').value.toLowerCase()).strip();
		 var signup_fname = $('f_name').value;
	  	 var signup_lname = $('l_name').value;
	  	 var signup_gender = $('gender').value;
		 var signup_captcha =  $('captcha').value;
		 var signup_country = $('country').value;
	  	 var signup_zipcode = $('zip').value; 
		
		var signup_url = 'site_process.php';
	
	var signup_pars = 'rq='+2+'&username=' + signup_username +'&password='+ signup_password + '&cpassword='+ signup_cpassword +'&email='+ signup_email+'&fn='+signup_fname+'&ln='+signup_lname+'&con='+signup_country+'&zip='+signup_zipcode+'&gen='+signup_gender+'&capt='+signup_captcha;
	
	//alert(signup_pars);
		
		var signup_Ajax = new Ajax.Request(
			signup_url, 
			{
				method: 'get', 
				parameters: signup_pars, 
				onComplete: signup_showResponse
			});
		
}

function signup_showResponse(originalRequest)
{
	//alert(originalRequest.responseText);
	window.location = "joinfinal.php"
	
}


//function for unique user check on click button//

function unique_user_check_click()
{
	
	 var user_check = $('signup_username').value;
	 
	 if(user_check =='')
	 {
		$('r_name').innerHTML = "Please Enter Username";
		return false;
		
	 }
	 if(!hasWhiteSpace(user_check))
	 {
		 $('r_name').innerHTML = "In Username no space is allowed";
		return false;
	}
		
	  
	 var rg_uname = user_check.length;
  if (rg_uname > 0 && (rg_uname < 5 || rg_uname > 15) || (rg_uname > 0 && (rg_uname < 5 || rg_uname > 15)))
    { 
      //reg_errors.push('Your username should be between 5 and 15 characters.');
	  $('r_name').innerHTML = "Username should be between 5 and 15 characters";
	  return false;
     }
	 
	var user_url = 'site_process.php';
	var user_pars = 'rq='+5+'&user_val=' + user_check;
		
		var myAjax = new Ajax.Request(
			user_url, 
			{
				method: 'get', 
				parameters: user_pars, 
				onComplete: user_showResponse1
			});
	
}

function user_showResponse1(originalRequest)
{
	
	//alert(originalRequest.responseText);
	if(originalRequest.responseText==1)
	{
		
		//alert("username allready exist pls change username");
		$('r_name').innerHTML = "Username already exist";
	}
	else
	{
		//alert("username is Availble.");
		$('r_name').innerHTML ="Username is Available";
	}
}



// take a request number and pass to the genearlized function for ajax request//

function req_no(val)
{
	//alert(val);
	if(val==4)
		{
			//alert(val);
			var myurl = 'site_process.php';
			var mypars = 'rq='+41;
			myrequest_ajax(myurl,mypars);
		}
	
	if(val==8)
		{
			//alert("manish");
			var luser = $('login_username').value.toLowerCase();
			//alert(luser);
			var lpass = $('login_password').value;
			
			var login_checkbox = $('rme').checked;
			
			if(login_checkbox==true)
			{
				
				createCookie('siteuser',luser,'sitepassword',lpass,30);
				
			}
			
			
			//alert(lpass);
			var myurl = 'site_process.php';
			var mypars = 'rq='+8+'&lo_user='+luser+'&lo_pass='+lpass;
			myrequest_ajax(myurl,mypars);
		}
}



// Generalized ajax request function and also response //

function myrequest_ajax(gen_url,gen_pars)
{
	var request_url = gen_url;
	//alert(request_url);
	var request_pars = gen_pars;
	//alert(request_pars);
	var req_Ajax = new Ajax.Request(
			request_url, 
			{
				method: 'get', 
				parameters: request_pars, 
				onComplete: request_showResponse
			});
		
}

function request_showResponse(originalRequest)
	{
		var main_response = originalRequest.responseText;
		
		//alert(originalRequest.responseText);
		
		//for login//
		if(main_response==8)
			{
				//alert("successfully login")
				window.location="index.php";
			}
		if(main_response==81)
		
			{
				//alert("username and password is wrong pls login again");
				$('login_tpl_msg1').innerHTML = "Username or Password is wrong please login again";
				
				
			}
			
			
			if(main_response==82)
			{
				window.location = "joinfinal.php?kna=1&hkl=DFgdfgdfgDFGDFGDFTERxcvvxcv";
			}
			
			
			//for logout//
			if(main_response==4)
			{
				
				window.location = "index.php"
			}
			
			
			
			
			
	}
	
	
// remember me function for login //

function createCookie(name,namevalue,pass,passvalue,days) 
{
	//alert("create cokkie");
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+namevalue+expires+"; path=/";
	document.cookie = pass+"="+passvalue+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
		return c.substring(nameEQ.length,c.length);
	}
	return null;
}



// check the user session exist on not on the on load page //

function check_session()
{
	//alert("onl;oad");
	
 //alert("");
	var onload_url = 'site_process.php';
	var onload_pars = 'rq='+31;
		
		var onload_Ajax = new Ajax.Request(
			onload_url, 
			{
				method: 'get', 
				parameters: onload_pars, 
				onComplete: onload_showResponse
			});
		
}

function onload_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var onload_sess = originalRequest.responseText;
		if(onload_sess==0)
		{
			
			
			Element.hide("logoutdiv");
			Element.hide("profilediv");
		}
		else
		{
			
			Element.show("logoutdiv");
			Element.show("profilediv");
			Element.hide("logindiv");
			Element.hide("signupdiv");
			
		}
	}
//  login enter function//

function checkEnter(e)    			//e is event object passed from function invocation
{ 
	var characterCode; 				//literal character code will be stored in this variable
	if(e && e.which)
	{ 								//if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which ;	//character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode; 	//character code is contained in IE's keyCode property
	}

	if(characterCode == 13)
	{ 								//if generated character code is equal to enter key then function call for add new div.
		 
		req_no(8);
	}
	else
	{
		return true
	}

}

// for retrive pasword

function send_password()
{
	
var sendmail = ($('sendpassword').value.toLowerCase()).strip();	

 
 if(sendmail=='')
 {
	//alert("pls enter the email address"); 
	$('login_tpl_msg2').innerHTML = "Please enter the Email address!";
	return false;
	
 }
 if (is_valid_email(sendmail) == EMAIL_BAD_SYNTAX)
  {
    //alert('Please enter a valid email address, such as name@domain.com.');
	$('login_tpl_msg2').innerHTML = "Please enter a valid email address, such as name@domain.com";
	return false;
  }
  else
  {
	var sendmail_url = 'site_process.php';
	var sendmail_pars = 'rq='+81+'&se_mail='+sendmail;
		
		var sendmail_Ajax = new Ajax.Request(
			sendmail_url, 
			{
				method: 'get', 
				parameters: sendmail_pars, 
				onComplete: sendmail_showResponse2
			});	
  }
	
}

function sendmail_showResponse2(originalRequest)
	{
		//alert(originalRequest.responseText);
		var sendmail_respo = originalRequest.responseText;
		
		if(sendmail_respo ==0)
		{
			//alert("username and password send on your mail account");
		$('login_tpl_msg2').innerHTML = "Sent! Please check your email now!.";
		$('sendpassword').value='';

			
		}
		else
		{
			//alert("mail addrss not fount pls enter again");
			$('login_tpl_msg2').innerHTML = "Email address not found. Please try again.";
			$('sendpassword').value='';
		}
		
		
	}
	
	
// news submit url check correct or not //

function check_url(url)
{
 var theurl=url;
 //alert(theurl);
 var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
 if (tomatch.test(theurl))
 {
 
 return true;
 }
 else
 {
 
 return false; 
}
}

// for wait one second//
/*Date.ONE_SECOND = 5500;
function wait (m) 
{
	var then = new Date(new Date().getTime() + m); 
	while (new Date() < then) 
	{}
	
	}
*/


// news form validation//
//var checkurl=false;

function news_validation(k,previd)
{
	
	var news_url = $('news_url').value;
	var news_checkbox = $('news_checkbox').checked;
	var news_title = $('news_title').value;
	var news_desc = $('news_desc').value;
	
	var validate_error_message = '';
	var reg_errors = new Array();
	var field_to_focus = '';
	 var favpet ;
	
	for (i = 0; i < document.form1.radiobutton.length; i++)
		{
			if (document.form1.radiobutton[i].checked == true)
				{
					favpet = document.form1.radiobutton[i].value; 
					//alert(favpet);
					break;
				}
				 else
	 			{
		 
					favpet = 0;
	 			}
			
		}
	
	
	
	
	
	if (news_url  == '')
    {
      	reg_errors.push('Please enter News URL.');
      	field_to_focus = 'news_url';
     }
	else
	 {
        var checkurl_ans = check_url(news_url);
		if(checkurl_ans)
		{
		}
		else
		{
			reg_errors.push("URL invalid. Please enter a valid URL address, such as 'http://www.domain.com'.");
	 	}
	 }
	
	//checkuniqueurl(news_url);
	
  	if(news_checkbox==false)
  	 {
  		reg_errors.push('Please accept the Term & Condition.');
     }
	 
	 if(news_title=='')
  	 {
  		reg_errors.push('Please enter the News Title.');
     }
	  if(news_desc=='')
  	 {
  		reg_errors.push('Please enter the News Description.');
     }
	 
	
	 
	if(favpet == 0)
	{
		reg_errors.push('Please select the topic.');
		field_to_focus = 'news_url';
	}
  
  
   
  	
 	 //wait(Date.ONE_SECOND);

	//alert(checkurl);
 // if(checkurl==false)
  //{
	  //reg_errors.push('duplicate story pls change the url.');
	  
  //}
  
  
  
  if (reg_errors.length > 0)
  {
    for (i = 0; i < reg_errors.length; ++i)
	
      validate_error_message += reg_errors[i] + '\n';
    alert(validate_error_message);
	
    if (field_to_focus != '' && (ff = document.getElementById(field_to_focus)))
      ff.focus();
    return false;
	
  }
  else
  {
	  var check_way = k;
	  if(check_way==1)
	  {
		 news_preview();
	  }
	  else
	  {
		 if(check_way==2)
		 {
			var ids = previd;
			editnews_submit(ids);
		 }
	  }
	  
	  
  }
	
}


// function for check unique url for spred button//

/*function checkuniqueurl(news_url)
{
	
	//alert(news_url);
	var checkuniqueurl_url = 'site_process.php';
	var checkuniqueurl_pars = 'rqpost='+911+'&url='+news_url;
	//alert(newspreview_pars);	
		var checkuniqueurl_Ajax = new Ajax.Request(
			checkuniqueurl_url, 
			{
				method: 'post', 
				parameters: checkuniqueurl_pars, 
				onComplete: checkuniqueurlrespo
			});	
	
	
}

function checkuniqueurlrespo(originalRequest)
	{
		//alert(originalRequest.responseText);
		if(originalRequest.responseText==0)
		{
		checkurl=false; // global variable
		//alert(checkurl);
		}
		if(originalRequest.responseText==1)
		{
		checkurl=true;
		//alert(checkurl);
		}
		
}*/

// function for onbklur check url//

/*function myurlchecked()
{
	var news_url = $('news_url').value;
	
	
	if(news_url=='')
		{
			alert("pls enter the url");
			field_focus('news_url');
			
		}
		else
	 {
        var checkurl_ans = check_url(news_url);
		if(checkurl_ans)
		{
			var onblur_checkurl_url = 'site_process.php';
	var onblur_checkurl_pars = 'rqpost='+911+'&url='+news_url;
	//alert(newspreview_pars);	
		var onblur_checkurl_Ajax = new Ajax.Request(
			onblur_checkurl_url, 
			{
				method: 'post', 
				parameters: onblur_checkurl_pars, 
				onComplete: onblur_checkurlrespo
			});	
		}
	
		else
		{
			alert("URL invalid. Please enter a valid URL address, such as 'http://www.domain.com'.");
	 	}
	 }
	
	
	
}*/

/*function onblur_checkurlrespo(originalRequest)
	{
		//alert(originalRequest.responseText);
		if(originalRequest.responseText==0)
		{
		
		alert("duplicate story, pls enter different url");
		field_focus('news_url');
		}
		if(originalRequest.responseText==1)
		{
		
		}
		
}*/

// for check login cokkie
function check_cookie()
{
//alert("call");
	var cookieusername = readCookie('siteuser');
	//alert(cookieusername);
	var cookiepassword = readCookie('sitepassword');
	//alert(cookiepassword);
	if(cookieusername!='' && cookiepassword!='' && cookieusername !=null && cookiepassword!=null)
	{
	//alert(cookieusername);
		$('login_username').value = cookieusername;
		$('login_password').value = cookiepassword;
		$('rme').checked='checked';
	}

}


// for news section radio button checked//

function news_radioprocess()
{
var favpet ;
	
	for (i = 0; i < document.form1.radiobutton.length; i++)
		{
			if (document.form1.radiobutton[i].checked == true)
				{
					favpet = document.form1.radiobutton[i].value; 
					//alert(favpet);
					return favpat;
					break;
				}
				 else
	 			{
		 
					favpet = 0;
	 			}
			
		}
	
}

// function news preview insert//

function news_preview()
{
	
		var getnews_url = $('news_url').value;
		var getnews_title = $('news_title').value;
		var getnews_desc = $('news_desc').value;
		
		for (i = 0; i < document.form1.radiobutton.length; i++)
			{
				if (document.form1.radiobutton[i].checked == true)
					{
						var getnews_tag = document.form1.radiobutton[i].value; 
					
						
						break;
					}
			}
		
		var tagall = getnews_tag.split("#");
		var s =tagall[0];
		var m= tagall[1];
	
	
	var newspreview_url = 'site_process.php';
	var newspreview_pars = 'rqpost='+91+'&url='+getnews_url+'&title='+getnews_title+'&description='+getnews_desc+'&mtag='+m+'&stag='+s;
	//alert(newspreview_pars);	
		var newspreview_Ajax = new Ajax.Request(
			newspreview_url, 
			{
				method: 'post', 
				parameters: newspreview_pars, 
				onComplete: newspreview_showResponse
			});	
	
}

function newspreview_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var newspreview_respo = originalRequest.responseText;
		if(originalRequest.responseText==0)
			{
				//alert("Duplicate story please change the url.");
				$('du_url').innerHTML = 'Duplicate story please change the url.';
				$('news_url').focus();
				window.scrollBy(0,0);

			}
		
		if(originalRequest.responseText!=0000)
			{
				window.location="newspre.php?pid="+originalRequest.responseText;	
			}
	}

//function for news edit//

function editnews_preview(npreid)
{
	
	//alert(npreid);
	window.location = "editpreview.php?preid="+npreid;
	
}

// function editnews submit//


function editnews_submit(myeditnewsid)
	{
		
		var getnews_url = $('news_url').value;
		var getnews_title = $('news_title').value;
		var getnews_desc = $('news_desc').value;
	
	for (i = 0; i < document.form1.radiobutton.length; i++)
		{
			if (document.form1.radiobutton[i].checked == true)
				{
					var getnews_tag = document.form1.radiobutton[i].value; 
				
					
					break;
				}
		}
	
	var tagall = getnews_tag.split("#");
	var s =tagall[0];
	var m= tagall[1];
	
	
	var editpreview_url = 'site_process.php';
	var editpreview_pars = 'rqpost='+92+'&url='+getnews_url+'&title='+getnews_title+'&description='+getnews_desc+'&mtag='+m+'&stag='+s+'&deleteid='+myeditnewsid;
		
		var editpreview_Ajax = new Ajax.Request(
			editpreview_url, 
			{
				method: 'post', 
				parameters: editpreview_pars, 
				onComplete: editpreview_showResponse
			});	
	}
	
	function editpreview_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var editpreview_respo = originalRequest.responseText;
		if(originalRequest.responseText!='')
			{
				window.location="index.php";	
			}
	}
	
// function for reply comment change in news comment section//

function reply_divchange_news(repid,torepuname)
{
$('reply_hidden').value = repid; // repaly form id ( first level comment id).

Element.show("replytext");
$("replytext").innerHTML = 'Replying to comment by'+'  '+torepuname; 
Element.show("cancel_reply");
Element.show("reply_comment_div");	
Element.show("reply_comment_div_img");	
Element.hide("main_comment_div");
Element.hide("main_comment_div_img");

}

// function for come to again main comment//function reply_divchange_news()
function cancel_all()
{
Element.hide("replytext");
Element.hide("cancel_reply");
Element.hide("reply_comment_div");	
Element.hide("reply_comment_div_img");	
Element.show("main_comment_div");
Element.show("main_comment_div_img");

}

// function for main comment submit//

function main_comment_submit(comment_id)
{
	//alert(comment_id);
var descr = $('main_comments_textarea').value;	
//alert(descr);
var main_comment_news_url = 'site_process.php';
	var main_comment_news_pars = 'rq='+11+'&id='+comment_id+'&descr='+descr;
		
		var main_comment_news_Ajax = new Ajax.Request(
			main_comment_news_url, 
			{
				method: 'get', 
				parameters: main_comment_news_pars, 
				onComplete: main_comment_news_showResponse
			});
}

function main_comment_news_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		
		if(data1==0)
		{
			window.location='login.php';
		}
		else
		{
			window.location.reload( false );
		}
		
	}


//function for reply comment submit//

function reply_comment_submit()
{
		var first_lid = $('reply_hidden').value	// repaly form id ( first level comment id).
		//alert(first_lid);
		var descr = $('reply_comments_textarea').value;
		//alert(descr);
		var reply_comment_news_url = 'site_process.php';
		var reply_comment_news_pars = 'rq='+12+'&flcid='+first_lid+'&descr='+descr;
		var reply_comment_news_Ajax = new Ajax.Request(
			 reply_comment_news_url, 
			{
				method: 'get', 
				parameters: reply_comment_news_pars, 
				onComplete: reply_comment_news_showResponse
			});	
	
}
function reply_comment_news_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		if(data1==0)
		{
			window.location='login.php';
		}
		else
		{
			window.location.reload( false );
		}
		
	}
	

// check the email form validation//

function ValidationemailForm()
{
	
	var tomail = ($('txtEmailto0').value.toLowerCase()).strip();
	var tomail1 = ($('txtEmailto1').value.toLowerCase()).strip();
	var tomail2 = ($('txtEmailto2').value.toLowerCase()).strip();
	var tomail3 = ($('txtEmailto3').value.toLowerCase()).strip();
	var tomail4 = ($('txtEmailto4').value.toLowerCase()).strip();
	var tomail5 = ($('txtEmailto5').value.toLowerCase()).strip();
	var tomail6 = ($('txtEmailto6').value.toLowerCase()).strip();
	var tomail7 = ($('txtEmailto7').value.toLowerCase()).strip();
	var tomail8 = ($('txtEmailto8').value.toLowerCase()).strip();
	
	var subj = $('txtSub22').value;
	var validate_error_message = '';
	var reg_errors = new Array();
	var field_to_focus = '';

	if (is_valid_email(tomail) == EMAIL_BAD_SYNTAX)
  {
    reg_errors.push('Please enter a valid TO email address, such as name@domain.com.');
    field_to_focus = 'txtEmailto22';
  }
  else
  {
    if (tomail == ''){
	   if (tomail1 == ''){
	   		if (tomail2 == ''){
	   			if (tomail3 == ''){
	    			if (tomail4 == ''){
	    				if (tomail5 == ''){
	  						if (tomail6 == ''){ 
	   							if (tomail7 == ''){ 
    								if (tomail8 == ''){ 
      													reg_errors.push('One Email Required (TO).');
      													field_to_focus = 'txtEmailto0';
    												   }
												   }
											   }
   											}
   										}
   									}
   								}
   							}
   						}
	
	else{
		
		}
	}
	
	if (subj == '')
    {
      reg_errors.push('Please enter Subject.');
      field_to_focus = 'txtEmailto22';
    }
	
	if (reg_errors.length > 0)
  {
    for (i = 0; i < reg_errors.length; ++i)
      validate_error_message += reg_errors[i] + '\n';
    alert(validate_error_message);
    if (field_to_focus != '' && (ff = document.getElementById(field_to_focus)))
      ff.focus();
    return false;
  }
  else
  {
 
  }
	
}


// in appropiate news function//

function inappro_news(inappro_news_id)
{

//alert( inappro_news_id );

		
	
		var inappro_news_url = 'site_process.php';
		var inappro_news_pars = 'rq='+13+'&inapproid='+inappro_news_id;
		var inappro_news_Ajax = new Ajax.Request(
			 inappro_news_url, 
			{
				method: 'get', 
				parameters: inappro_news_pars, 
				onComplete: inappro_news_showResponse
			});	

}

function inappro_news_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		data1 = data1.split('#');
		inappro_video_id = "news_inappro"+data1[1];
		if(data1[0]==0)
		{
			//alert(data1[1]);
			//window.location='login.php';
			//Element.show("'"+data1[1]+"'");
			document.getElementById(data1[1]).style.display='block';
			//alert("");
		}
		if(data1[0]==1)
		{			
			$(inappro_video_id).innerHTML = "Thank you for notifying us!.  ";
		}
		if(data1[0]==2)
		{
			$(inappro_video_id).innerHTML = "You already voted for Inappropriate";
		}
		
	}

// broken news function//

function broken_news(broken_news_id)
{
	
	//alert( broken_news_id );
	
	var broken_news_url = 'site_process.php';
		var broken_news_pars = 'rq='+14+'&brid='+broken_news_id;
		var broken_news_Ajax = new Ajax.Request(
			 broken_news_url, 
			{
				method: 'get', 
				parameters: broken_news_pars, 
				onComplete: broken_news_showResponse
			});	
}

function broken_news_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		data1 = data1.split('#');
		inappro_video_id = "news_inappro"+data1[1];
		if(data1[0]==0)
		{
			//window.location='login.php';
			document.getElementById(data1[1]).style.display='block';
		}
		if(data1[0]==1)
		{			
			$(inappro_video_id).innerHTML = "Thank you for notifying us!.";
		}
		if(data1[0]==2)
		{
			$(inappro_video_id).innerHTML = "You already voted for Broken";
		}
		
	}
	
// mail from homepage//

function share_to_friend()
{
//alert('');	
var myname = $('y_name').value;
var f_name = $('friend_name').value;
var f_mail = ($('friend_mail').value.toLowerCase()).strip();
var validate_error_message = '';
	var reg_errors = new Array();
	var field_to_focus = '';

if (myname == '')
    {
      reg_errors.push('Please enter your name.');
      field_to_focus = 'y_name';
    }
if (f_name == '')
    {
      reg_errors.push('Please enter your friend name.');
      field_to_focus = 'friend_name';
    }
	
if (f_mail == '')
    {
      reg_errors.push('Please enter your friend mail address.');
      field_to_focus = 'friend_name';
    }	

if (is_valid_email(f_mail) == EMAIL_BAD_SYNTAX)
  {
    reg_errors.push('Please enter a valid email address, such as name@domain.com.');
	 field_to_focus = 'friend_mail';
  }
 if (reg_errors.length > 0)
  {
    for (i = 0; i < reg_errors.length; ++i)
      validate_error_message += reg_errors[i] + '\n';
    alert(validate_error_message);
    if (field_to_focus != '' && (ff = document.getElementById(field_to_focus)))
      ff.focus();
    return false;
  } 
  else
  {
	  
	  return true;
	/*var s_to_friend_url = 'site_process.php';
	var share_to_friend_pars = 'rq='+89+'&fe_mail='+f_mail+'&f_name='+f_name+'&my_name='+myname;
		
		var share_to_friend_Ajax = new Ajax.Request(
			share_to_friend_url, 
			{
				method: 'get', 
				parameters: share_to_friend_pars, 
				onComplete: share_to_friend_showResponse
			});	*/
		
		
		
		
		
		
  }
	
}


/*function share_to_friend_showResponse()
{
	
		alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		
		
		document.getElementById('tellfriend').style.display= "none";
		
	
}*/


// hot topics function //

function hot_news()
{
	
	//alert( broken_news_id );
	
	var hot_news_url = 'site_process.php';
		var hot_news_pars = 'rq='+83;
		var hot_news_Ajax = new Ajax.Request(
			 hot_news_url, 
			{
				method: 'get', 
				parameters: hot_news_pars, 
				onComplete: hot_news_showResponse
			});	
}

function hot_news_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		
		
			$('hot_newsk').innerHTML = data1;
	}
	
//add a friend link function//

function add_friend(f_id)
{
//alert(f_id);
var add_friend_url = 'site_process.php';
		var add_friend_pars = 'rq='+84+'&fr_id='+f_id;
		var add_friend_Ajax = new Ajax.Request(
			 add_friend_url, 
			{
				method: 'get', 
				parameters: add_friend_pars, 
				onComplete: add_friend_showResponse
			});	
}
function add_friend_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		if(data1==0)
		{
			window.location='login.php';
		}
		if(data1==1)
		{
			//alert("vcvcxv");
			$('add_frnd').innerHTML = "Already in your Friend List.";
		}
		if(data1==2)
		{
			$('add_frnd').innerHTML = "Add in your friend List";
		}
		
		
			
	}
	
	
	
	// for news ratings//

function news_rating(val,nidk)
{
	
//alert(val);	
//alert(nidk);
		var news_rating_url = 'site_process.php';
		var news_rating_pars = 'rq='+77+'&r_val='+val+'&n_id='+nidk;
		var news_rating_Ajax = new Ajax.Request(
			 news_rating_url, 
			{
				method: 'get', 
				parameters: news_rating_pars, 
				onComplete: news_rating_showResponse
			});	
	
}

function news_rating_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		var data1 = originalRequest.responseText;
		data1 = data1.split('#');
		
		
		
		if(data1[0]==0)
		{
			//window.location='login.php';
			document.getElementById(data1[1]).style.display='block';
		}
		if(data1[0]==2)
		{
			$(data1[1]+'news_r').innerHTML = "Thank you for voting!";
			$('vote_id'+data1[1]).innerHTML = data1[2];
			$('value_id'+data1[1]).innerHTML = data1[3];
		}
		if(data1[0]==3)
		{
			$(data1[1]+'news_r').innerHTML = "Thank you for voting!";
			$('vote_id'+data1[1]).innerHTML = data1[2];
			$('value_id'+data1[1]).innerHTML = data1[3];
		}
		if(data1[0]==1)
		{
			$(data1[1]+'news_r').innerHTML = "You already voted";
		}
		
	}
	
// function for preview submit//

function submitnews_preview()

{
	
		var p_url = $('urls').value;
		//alert(p_url);
		var p_title = $('title').value;
		var p_desc = $('description').value;
		var p_mtag = $('mtag').value;
		var p_stag = $('stag').value;
		var p_deleteid = $('deleteid').value;
		//alert(p_deleteid);
		
		var prev_url = 'site_process.php';
	var prev_pars = 'rqpost='+777+'&url='+p_url+'&title='+p_title+'&description='+p_desc+'&mtag='+p_mtag+'&stag='+p_stag+'&deleteid='+p_deleteid;
		
		var prev_Ajax = new Ajax.Request(
			prev_url, 
			{
				method: 'post', 
				parameters: prev_pars, 
				onComplete: prev_showResponse
			});	
		
}

function prev_showResponse(originalRequest)
	{
		//alert(originalRequest.responseText);
		
		if(originalRequest.responseText!='')
			{
				window.location="index.php";	
			}
	}
	
//////function for close effect login div/////

function close_effectlogin(valk)
{
	//alert(valk);
document.getElementById(valk).style.display='none';	
	
}

// tell a friend div open here//

function t_a_f_open()
{
document.getElementById('tellfriend').style.display='block';		
}


// function for feed back form//


function checkfeedbackform()
{
	
	var feed_name = $('feed_name').value;
	var feed_mail = $('feed_mail').value;
	var feed_subj = $('feed_subj').value;
	var feed_cate = $('feed_cate').value;
	var feed_comment = $('feed_comment').value;
	
	if (feed_name=='')
		{
			$('feed_error').innerHTML= 'Please enter your name.';
		field_focus('feed_name');
		return false;
		}
	if (feed_mail=='')
		{
			$('feed_error').innerHTML= 'Please enter your mail address.';
		field_focus('feed_mail');
		return false;
		}
	
	if (is_valid_email(feed_mail) == EMAIL_BAD_SYNTAX)
  {
   
	   $('feed_error').innerHTML = 'Please enter a valid email address, such as name@domain.com.';
    field_focus('feed_mail');
	return false;
  }
	
	if (feed_subj=='')
		{
			$('feed_error').innerHTML= 'Please enter your mail address.';
		field_focus('feed_subj');
		return false;
		}
		
		if (feed_cate=='')
		{
			$('feed_error').innerHTML= 'Please enter Category.';
		field_focus('feed_cate');
		return false;
		}
	
	if (feed_comment=='')
		{
			$('feed_error').innerHTML= 'Please enter Comment.';
		field_focus('feed_comment');
		return false;
		}
}
	
	
// close tell a friend div//
	
	function closetellafriend()
	{
	
	document.getElementById('tellfriend').style.display="none";
	
	}

