var xmlHttp
var min=13;
var max=17;
function fontIcress() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 13;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function fontDecress() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 13;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function email(myurl)
{
	//if(varify)
	//{
	window.open("/home/emailtofriend.php?myurl="+myurl,'Email','left=100,top=100,height=600,width=600,scrollbars=no,statusbar=no,toolbars=no,resizable=no')
	/*}
	else
	{
	window.open("/home/emailtofriend.php?myurl="+myurl,'Email','left=100,top=100,height=600,width=600,scrollbars=no,statusbar=no,toolbars=no,resizable=no')

	}*/
}

function comment(val)
{
	
	var storyvalue=document.getElementById("storyvalue").value;
	var comment=document.getElementsByName("txtwrite")[0].value;
	var name=document.getElementsByName("txtname")[0].value;
	var email=document.getElementsByName("txtemail")[0].value;
	var city=document.getElementsByName("txtcity")[0].value;
	if(storyvalue!="" )
	{
		if(comment=="Enter comment")
		{
			alert("Enter comment")
			document.getElementsByName("txtwrite")[0].focus()
		}
		else if(name=="Name")
		{
			alert("Enter Name")
			document.getElementsByName("txtname")[0].focus()
		}
		else if(email=="email address")
		{
			alert("Enter email address")
			document.getElementsByName("txtemail")[0].focus()
		}
		else if(emailvalidate(email)=="")
		{
		}
		else if(city=="City")
		{
			alert("Enter City")
			document.getElementsByName("txtcity")[0].focus()
		}
		else
		{
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
			 {
			 alert ("Browser does not support HTTP Request")
			 return
			 }
			var url="/home/commentinsert.php"
			url=url+"?storyvalue="+storyvalue+"&comment="+encodeURIComponent(comment)+"&name="+name+"&email="+email+"&city="+city +"&total="+val
				//alert(url);
			url=url+"&sid="+Math.random()				
			xmlHttp.onreadystatechange=stateInsertComment
			xmlHttp.open("GET",url,true)
			xmlHttp.send(null)


		}

	}

	/*if(varify)
	{
	window.open("/home/comment.php?storyvalue="+storyvalue+"&locatiopnvalue="+categoryvalue,'Comment','left=100,top=100,height=600,width=600,scrollbars=no,statusbar=no,toolbars=no,resizable=no')
	}
else
	{
	window.open("/home/comment.php?storyvalue="+storyvalue+"&categoryvalue="+categoryvalue,'Comment','left=100,top=100,height=600,width=600,scrollbars=no,statusbar=no,toolbars=no,resizable=no')
	}*/
}

function stateInsertComment()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
		document.getElementById("allcommentinsert").innerHTML=xmlHttp.responseText
 
 } 
}

function emailvalidate(email)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			   var address = email;
			   if(reg.test(address) == false) {
				  alert('Invalid Email Address');
				  document.getElementsByName("txtemail")[0].focus()
				  return false;
			   }
}

function printpage(storyvalue,categoryvalue)
{

var x=window.open("/home/StoryPage/Print/"+categoryvalue+ "-"+storyvalue+".html");
}

function changeStar(myRating)
{
		
			
						if (myRating==1)
						{	
							document.getElementById('1').src=document.getElementById('1').src.replace('star1.gif','star2.gif');		
							document.getElementById('2').src=document.getElementById('2').src.replace('star2.gif','star1.gif');
							document.getElementById('3').src=document.getElementById('3').src.replace('star2.gif','star1.gif');
							document.getElementById('4').src=document.getElementById('4').src.replace('star2.gif','star1.gif');
							document.getElementById('5').src=document.getElementById('5').src.replace('star2.gif','star1.gif');
						
						}
					else if (myRating==2)
					{
					
						document.getElementById('1').src=document.getElementById('1').src.replace('star1.gif','star2.gif');		
						document.getElementById('2').src=document.getElementById('2').src.replace('star1.gif','star2.gif');
						document.getElementById('3').src=document.getElementById('3').src.replace('star2.gif','star1.gif');
						document.getElementById('4').src=document.getElementById('4').src.replace('star2.gif','star1.gif');
						document.getElementById('5').src=document.getElementById('5').src.replace('star2.gif','star1.gif');
					
					}
				else if (myRating==3)
					{
					
						document.getElementById('1').src=document.getElementById('1').src.replace('star1.gif','star2.gif');		
						document.getElementById('2').src=document.getElementById('2').src.replace('star1.gif','star2.gif');
						document.getElementById('3').src=document.getElementById('3').src.replace('star1.gif','star2.gif');
						document.getElementById('4').src=document.getElementById('4').src.replace('star2.gif','star1.gif');
						document.getElementById('5').src=document.getElementById('5').src.replace('star2.gif','star1.gif');
					
					}
					else if (myRating==4)
					{
					
						document.getElementById('1').src=document.getElementById('1').src.replace('star1.gif','star2.gif');		
						document.getElementById('2').src=document.getElementById('2').src.replace('star1.gif','star2.gif');
						document.getElementById('3').src=document.getElementById('3').src.replace('star1.gif','star2.gif');
						document.getElementById('4').src=document.getElementById('4').src.replace('star1.gif','star2.gif');
						document.getElementById('5').src=document.getElementById('5').src.replace('star2.gif','star1.gif');
					
					}
					else if (myRating==5)
					{
					
						document.getElementById('1').src=document.getElementById('1').src.replace('star1.gif','star2.gif');		
						document.getElementById('2').src=document.getElementById('2').src.replace('star1.gif','star2.gif');
						document.getElementById('3').src=document.getElementById('3').src.replace('star1.gif','star2.gif');
						document.getElementById('4').src=document.getElementById('4').src.replace('star1.gif','star2.gif');
						document.getElementById('5').src=document.getElementById('5').src.replace('star1.gif','star2.gif');
					
					}

			}
function replaceStar(myRating)
{
			document.getElementById('1').src=document.getElementById('1').src.replace('star2.gif','star1.gif');	
			document.getElementById('2').src=document.getElementById('2').src.replace('star2.gif','star1.gif');
			document.getElementById('3').src=document.getElementById('3').src.replace('star2.gif','star1.gif');
			document.getElementById('4').src=document.getElementById('4').src.replace('star2.gif','star1.gif');
			document.getElementById('5').src=document.getElementById('5').src.replace('star2.gif','star1.gif');	
}




/*********Ajax code************/


var str_Html="";
var zero=0
	function downrelatednews()
	{ 
var count=parseInt(document.getElementById("relatednewsLast").value)+1;
		if(document.getElementById("DIV_"+count)!=null)
		{


			document.getElementById("changeRelatedNews").innerHTML="";
			document.getElementById("changeRelatedNews").innerHTML=document.getElementById("DIV_"+count).innerHTML
			document.getElementById("relatednewsLast").value=parseInt(document.getElementById("relatednewsLast").value)+1;
			//alert(document.getElementById("changeRelatedNews").className);
		}
		else
		{
			
			return false;
		}
	}

function uprelatednews()
{ //
//alert(document.getElementById("relatednewsfirstaw").value)
		var count=parseInt(document.getElementById("relatednewsLast").value)-1;
		if(document.getElementById("DIV_"+count)!=null)
		{
			document.getElementById("changeRelatedNews").innerHTML="";
			document.getElementById("changeRelatedNews").innerHTML=document.getElementById("DIV_"+count).innerHTML
			document.getElementById("relatednewsLast").value=parseInt(document.getElementById("relatednewsLast").value)-1;
		}
		else
		{

			return false;
		}
		
}




function ReadComment(storyvalue,categoryvalue)
{ 
	document.getElementById("displaycomment").style.display="block"
	var frmscroll=document.getElementById("frmdetail");
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="/home/readcomment.php"
url=url+"?storyvalue="+storyvalue
url=url+"&sid="+Math.random()
url=url+"&categoryvalue="+categoryvalue
xmlHttp.onreadystatechange=stateReadComment
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateReadComment()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 var bb=document.getElementById("allcomment").innerHTML=xmlHttp.responseText 
 } 
}


function stateReadComment()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 var bb=document.getElementById("allcomment").innerHTML=xmlHttp.responseText 
 } 
}


function like(storyvalue,likeval)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="/home/like.php"
url=url+"?storyvalue="+storyvalue+"&likeflag="+likeval
url=url+"&sid="+Math.random()				
xmlHttp.onreadystatechange=likecount
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function likecount()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	//alert(xmlHttp.responseText)
   document.getElementById("likeval").innerHTML=xmlHttp.responseText 
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function abusereports(str,newsvalue,storyvalue,categoryvalue)
{

	window.open("/home/abusereport.php?cmtid="+str+"&newsvalue="+newsvalue+"&storyvalue="+storyvalue+"&categoryvalue="+categoryvalue,'Email','left=100,top=100,height=600,width=600,scrollbars=no,statusbar=no,toolbars=no,resizable=no')
}

		
	function GetRate(val,storyvalue,categoryvalue,storyrattingIp,varify)
	{
	var x=document.getElementById('storyratting').value;
	//alert(x);
	var url;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
	if(storyrattingIp == x)
	{
	alert('Already rated!')
	return false;
	}
	else
	{
		if(varify == "location")
	{
			url="/home/storyrate.php?rate="+val+"&sid="+Math.random()+"&storyvalue="+storyvalue+"&lid="+Math.random()+"&locatiopnvalue="+categoryvalue;
	}
	else
	{
			url ="/home/storyrate.php?rate="+val+"&sid="+Math.random()+"&storyvalue="+storyvalue+"&lid="+Math.random()+"&categoryvalue="+categoryvalue;

	}
	//alert(url);
xmlHttp.onreadystatechange=stateReadRate
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

	}
}

function stateReadRate()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 document.getElementById("storyrRate").innerHTML=xmlHttp.responseText 
	 } 
}
