// JavaScript Document

function validateRadius()
{
	if(document.zipsrcfrm.srcmiles.value>50){
		alert("The value of the Radius cannot exceed 50 Miles");
		document.zipsrcfrm.srcmiles.value='';
		document.zipsrcfrm.srcmiles.focus();
		return false;
	
	}
}



var tr;
var newid;
var rowdelobj;
function changeLinkCss(upperTab,upperLink,leftMenuTr,LeftMenuLink)
{
if(upperTab!=0)
 	document.getElementById(upperTab).className='linkboldtext1';
 if(upperLink!=0)
 	document.getElementById(upperLink).className='linkboldtext1';
 if(leftMenuTr!=0)
 	document.getElementById(leftMenuTr).className='currentlink';
if(LeftMenuLink!=0)
 	document.getElementById(LeftMenuLink).className='currentlink';
 tr = leftMenuTr;
}



/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a scomma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"];

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes";

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array();
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i]);
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i]);
tempobj.style.display="block";
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid);
if (currentfr && !window.opera){
currentfr.style.display="block";
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight){ //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false);
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe); // Bug fix line
currentfr.attachEvent("onload", readjustIframe);
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt;
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement;
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller

*/
    function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}


   
	function checkme() 
	{
		if(document.indexfrm.other.checked==true && document.indexfrm.otherissue.value=="")
		{
		   alert("Missing Options:\n\n * Other issues");
		   document.indexfrm.otherissue.focus();
		   return false;
        }
		if (document.indexfrm.termsandcondition.checked == false) 
		{
		   alert("You must agree to the terms");
		   return false;
        }
		
		else
		{
		return true;
		}
    }

	
	 function Open(pagename)
	 {
		var src =pagename
		var iframe = '<iframe id="myframe" src='+src+' scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:visible; width:100%; display:none"></iframe>'
		document.getElementById('frame2').innerHTML=iframe;
	 }	
	
	 
	 function show(id)
	{
		 document.getElementById(id).style.display = 'inline';
	}
	function hide(id)
	{
		 document.getElementById(id).style.display = 'none';
	}

function setTableforteaser (id, showOrHide) 
{
	if(showOrHide==1)
	{
	 document.getElementById(id).style.display = 'inline';
	 }
	 else
	 {
	 document.getElementById(id).style.display = 'none';
	 }
}		 

function toggleimage(str,elem)
{	
	if(str.src.indexOf("minus")!=-1) 
	{
			document.getElementById(elem).src="../images/plus.jpg";
	}
	else
	{
			document.getElementById(elem).src="../images/minus.jpg";
	}
}
/*	if(document.subscriberfrm.cbChkAll.checked){*/
function chkAllAre(){
	var cnt;
	var allchecked=true;
	cnt = document.subscriberfrm.elements.length;
	for(i=0;i<cnt;i++){
		if(document.subscriberfrm.elements[i].type == "checkbox" && document.subscriberfrm.elements[i].checked == true){
			continue;
		}
		else if(document.subscriberfrm.elements[i].type == "checkbox" && document.subscriberfrm.elements[i].checked == false){
			allchecked=false;
			break;
		}
	}
	if(allchecked==false){
		document.subscriberfrm.cbChkAll.checked=false;
	}
	else if(allchecked==true){
		alert("all checked");
		document.subscriberfrm.cbChkAll.checked=true;
	}
}

function chkAll(){
	var cnt;
	cnt = document.subscriberfrm.elements.length;
	if(document.subscriberfrm.cbChkAll.checked){
		for(i=0;i<cnt;i++){
			if(document.subscriberfrm.elements[i].type == "checkbox"){
				document.subscriberfrm.elements[i].checked = true;
			}
		}
	}
	else{
		for(i=0;i<cnt;i++){
			if(document.subscriberfrm.elements[i].type == "checkbox"){
				document.subscriberfrm.elements[i].checked = false;
			}
		}
	}
}

function chkAllsubscriberSearchfrm(){
	var cnt;
	cnt = document.subscriberSearchfrm.elements.length;
	if(document.subscriberSearchfrm.cbChkAll.checked){
		for(i=0;i<cnt;i++){
			if(document.subscriberSearchfrm.elements[i].type == "checkbox" && document.subscriberSearchfrm.elements[i].name== "subscriberId[]"){
				document.subscriberSearchfrm.elements[i].checked = true;
			}
		}
	}
	else{
		for(i=0;i<cnt;i++){
			if(document.subscriberSearchfrm.elements[i].type == "checkbox"){
				document.subscriberSearchfrm.elements[i].checked = false;
			}
		}
	}
}
function chkAlladvertiselistfrm(){
	var cnt;
	cnt = document.advertiselistfrm.elements.length;
	if(document.advertiselistfrm.cbChkAll.checked){
		for(i=0;i<cnt;i++){
			if(document.advertiselistfrm.elements[i].type == "checkbox" && document.subscriberSearchfrm.elements[i].name== "adIsd[]"){
				document.advertiselistfrm.elements[i].checked = true;
			}
		}
	}
	else{
		for(i=0;i<cnt;i++){
			if(document.advertiselistfrm.elements[i].type == "checkbox"){
				document.advertiselistfrm.elements[i].checked = false;
			}
		}
	}
}
function toggleDiv(theEvent,id,flagit)
{

/*soumik*/
		menuobj = document.getElementById(id);
		if( !menuobj ) {
			alert( "Did you forget to define a <div>?" );
			return;
		}

		menuobj.contentwidth = menuobj.offsetWidth;
		menuobj.contentheight = menuobj.offsetHeight;


		/* Figure out where the event occurred */
		var menuX;
		var menuY;
		if( window.offsetParent ) {
			menuX = window.offsetParent.offsetLeft + theEvent.clientX;
			menuY = window.offsetParent.offsetTop + theEvent.clienty;
		} else {
			menuX = theEvent.clientX;
			menuY = theEvent.clientY;
		}


			menuX += document.body.scrollLeft;
			menuY += document.body.scrollTop;


		// Find out how close the mouse is to the corner of the window
		var rightedge  = menuX + menuobj.contentwidth;
		var bottomedge = menuY + menuobj.contentheight;

		if (rightedge > document.body.clientWidth) {
			menuX -= menuobj.contentwidth;
			menuobj.style.textAlign = "right";
		} else {
			menuobj.style.textAlign = "left";
		}

		/*if (bottomedge > document.body.clientHeight) {
			menuY -= menuobj.contentheight;
		}*/

		
		menuobj.style.top = menuY + "px";
		menuobj.style.left = menuX + "px";
		menuobj.style.visibility = "visible";

	if (flagit=="1")
	{
		if (document.layers) document.layers[''+id+''].visibility = "show"
		else if (document.all) document.all[''+id+''].style.visibility = "visible"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "Visible"
	}
	else if (flagit=="0")
	{
		if (document.layers) document.layers[''+id+''].visibility = "hide"
		else if (document.all) document.all[''+id+''].style.visibility = "hidden"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
}

function handleHttpResponse()
{
	if (http.readyState == 4)
	{
		 if (http.responseText.indexOf('invalid') == -1)
		 {
			  // Use the XML DOM to unpack the city and state data
			 var xmlDocument = http.responseText;
			 if(http.responseText != '')
			 {
				 	insRow(http.responseText);
			 }
			 else alert("Rating Name already exists.");
			 
		 }
	} 
}
function DelhandleHttpResponse()
{
	if (http.readyState == 4)
	{
		 if (http.responseText.indexOf('invalid') == -1)
		 {
			  // Use the XML DOM to unpack the city and state data
			 var xmlDocument = http.responseText;
			if(http.responseText == '')
			 {
				 	alert("Record is deleted");
					deleteRow(rowdelobj);
			 }
			 else alert("Rating Name already exists.");
			 
		 }
	} 
}

function getHTTPObject()
{
  var xmlhttp;
	try
	{
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			xmlhttp = new XMLHttpRequest();
		}
	 
	} 
	catch (e)
	{
	  xmlhttp = false;
	}
   return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
function chkalphanumeric(objValue)
{
	var charpos = objValue.value.search("[^A-Za-z0-9]"); 
	var strError='';
	if(objValue.value.length > 0 &&  charpos >= 0) 
	{ 
		if(!strError || strError.length ==0) 
		{ 
		  strError = objValue.name +": Only alpha-numeric characters allowed "; 
		}//if 
		alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
		return false; 
	}//if 
}

function zip_val(e,form,zip_val)
{ 
	
	var unicode = e.charCode? e.charCode : e.keyCode;

	if (unicode!=8 && unicode !=9)
	{ 	var len= zip_val.length + 1;
		//if the key isn't the backspace,Tab key (which we should allow)
		if (unicode<48||unicode>57) //if not a number
			return false; //disable key press
	}
}

function phonenumbersonly(e)
{

	var unicode=e.charCode? e.charCode : e.keyCode;

	if (unicode!=8 && unicode !=9 && unicode != 43 && unicode !=45)
	{ 	
		//if the key isn't the backspace,Tab key (which we should allow)
		if (unicode<48||unicode>57) //if not a number
			return false; //disable key press
	}
}


function addtitle()
{
	if(document.ratingfrm.title.value == '')
	{
			
		alert("Enter the title ");
		return false;
	}
	else if(document.ratingfrm.title.value.indexOf(' ') == '')
	{
		alert("space not allowed in front of the title ");
		return false;
	}
	else if(chkalphanumeric(document.ratingfrm.title) == false)
	{
		return false;
	}
	else
	{
		http.open("GET", 'changerating_controller.php?title='+document.ratingfrm.title.value , true);
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
		
	}
}

function deltitle(obj,delid,msg)
{
	if(confirm(msg))
	{
		rowdelobj = obj;
		http.open("GET", 'changerating_controller.php?delid='+delid , true);
		http.onreadystatechange = DelhandleHttpResponse;
		http.send(null);
		
	}
}

function deleteRow(r)
{
	var i=r.parentNode.parentNode.rowIndex
	document.getElementById('myTable').deleteRow(i)
}


