// JavaScript Document

/**********************************************************************************************
	script by team-inertia Technologies (2003 -04)
	contactus@teaminertia.com
	www.teaminertia.com		
***********************************************************************************************/

		// CHECK FOR EMPTY VALUES IN FORM
function WindowXPosition(widthX,heightX,windowName)
{
	var width = (screen.width);
	var height = (screen.height - 25);
	var centerleft = 0;
	var centertop = 0;
	var centerleft = (width/2) - (widthX/2);
	var centertop = (height/2) - (heightX/2);
	var width=widthX;
	var height=heightX;
	windowName.moveTo(centerleft,centertop);
	windowName.resizeTo(width, height);
	windowName.focus();
}

function WindowXXPosition(widthX,heightX,windowName) //same as above, only it takes %age vals as params for width n height
{
	var width = (screen.width);
	var height = (screen.height - 25);
		
	var wt = (width * widthX) / 100;
	var ht = (height * heightX) / 100;

	var centerleft = (width/2) - (wt/2);
	var centertop = (height/2) - (ht/2);

	windowName.resizeTo(wt, ht);
	windowName.moveTo(centerleft,centertop);
	windowName.focus();
}

function WindowPosition(widthX,heightX)
{
	var width = (screen.width);
	var height = (screen.height - 25);
	var centerleft = 0;
	var centertop = 0;
	var centerleft = (width/2) - (widthX/2);
	var centertop = (height/2) - (heightX/2);
	var width=widthX;
	var height=heightX;
	window.moveTo(centerleft,centertop);
	window.resizeTo(width, height);
	window.focus();
}		

		
	function submitform(f)	
	  {	  
			e=0;	 // means no error
	   
		for(i=0; i<f.elements.length; i++)    <!--- To check that data is entered in textboxes >
		 {
			if( (f.elements[i].type=="text" || f.elements[i].type=="textarea") && f.elements[i].value=="" )
		   {
			  f.elements[i].focus();
			  f.elements[i].style.color="#FF0000";
			  alert("Please enter " +f.elements[i].id+ " !!!")
			  e=1;
			  return false;	
		   }
		 }	
		
			if( e==1)
			{
				// do nothing !!!
			}
			else
			{				
				// document.x.submit();	 
				return true;
			}
		
	 }
 
 	 // CONFIRM DIALOG BOX
 	 function confirmIt(frm,msg)
	{
		if(confirm(msg))
			frm.submit();
	}
	
	// CHECK FOR NUMBERS
	 function checkNum()
	{
		var carCode = event.keyCode;
		
		if ((carCode < 48) || (carCode > 57))
		{//	alert(carCode);
			alert('Please enter Numeric Values.');
			event.cancelBubble = true;
			event.returnValue = false;
		}
	} 
 
 	// CHECK FOR DECIMAL VALUES
	 function checkNumDec()
	{
		var carCode = event.keyCode;
			
		if ( ((carCode >= 48) && (carCode <= 57)) || (carCode == 46) )
		{
			// do nothing
		}
		else
		{
			alert('Please enter only +ve numbers.');
			event.cancelBubble = true;
			event.returnValue = false;
			return;
		}
	}

	// ROUNDING DECIMAL VALUES TO TWO DIGITS
	 function checkdecimal(box) 
	{ 
	 var val = eval(box.value/1)
	 // limit to 2 dec places (rounding up, if needed) 
	 box.value = Math.round(val*100)/100  
	 
		 if((box.value=="NaN")) 
		 {
		  alert("Invalid Value");
		  box.value = "";
		  box.focus();
		 }	
	} 
	
	// Replaces oldS with newS in the string fullS  
	function replaceString(oldS,newS,fullS)
	{
		for (var i=0; i<fullS.length; i++)
			if (fullS.substring(i,i+oldS.length) == oldS)
				fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
	
		return fullS;
	}
	
	// To open a new window to change rank of parties
	function changerank(id,mode)		
	{			
		info="changerank.php?txtID="+id+"&mode1="+mode;
		window.open(info,"","menubars=0,width=500,height=550");
	}

	//To enlarge a image
	function openwinpic(pid,ht,wt)
	{
		wt=parseInt(wt)+400;
		ht=parseInt(ht)+400;	
		wtx = eval(wt);
		htx = eval(ht);
		//alert(wtx);
		//	alert(htx);
		info="pic_disp.php?id="+pid;
		window.open(info,"oy","menubars=0,scrollbars=1,width="+wtx+",height="+htx+"");	
	}
	
function cLook()
{
	event.srcElement.parentElement.className="mnub1";
}
function rLook()
{
	event.srcElement.parentElement.className="mnub";
}
function checkEmail(x)
{
	a=new Array();
	s=x.value;
	for(i=0; i<s.length; i++)
	{
		a[i]=s.charAt(i);
	}
	
	dot = s.indexOf(".");
	at   = s.indexOf("@");
	
	if (dot == -1 || at == -1)
	{
		x.focus()
		alert ("Email id does not exist");
		return 1;
	}

	str1=s.substring(dot+1,s.length);
	str2=s.substring(at+1, dot);
	str3=s.substring(0,at);

	if((str1.length==0)||(str2.length==0)||(str3.length==0))
	{
		x.focus()     
		alert ("Invalid email id");
		return 1;
	}

	return 0;
}
function checkcharsize(obj)
{
	alert(obj);
	str=String(obj.value);
	if(str.length>10)
	{
			str.slice(0,9);
			obj.value=str;
			return false;
	}
	return true;
}

function todayDate()
{

	oneDate=new Date();
	
	monthNames = ["January", "February", "March", "April", "May", "June",
	"July","August", "September", "October", "November", "December"];
	
	dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
	"Friday", "Saturday"];
	
	var theDay = dayNames[oneDate.getDay()];
	var theMonth = monthNames[oneDate.getMonth()];
	var theYear = oneDate.getFullYear();
	
	var greet=wish();
	str=greet + ", Today is " + theDay + ", " + theMonth + " " + oneDate.getDate() +", " + theYear;
	document.getElementById("date").innerHTML =str;

}


function wish()
{	
	oneDate=new Date();
	hrs=oneDate.getHours();
	msg="";
	if(hrs<12)
	{		
		msg="Good Morning ";
	}
	else if(hrs<16)
	{
		msg="Good Afternoon ";
	}
	else
	{
		msg="Good Evening ";
	}
	return msg;	
}

function isHex(entry) {
//validChar='0123456789ABCDEF'; // characters allowed in hex
validChar='%)>(<='; // characters allowed in hex
strlen=entry.length;          // how long is test string
if (strlen < 1) {alert('Enter Something!');return false;} // no check!
entry=entry.toUpperCase();          // in case of lowercase characters
// Now scan string for illegal characters
for (i=0; i < strlen; i++ ) {
    if (validChar.indexOf(entry.charAt(i)) < 0) {
       alert("Entry must be in hexadecimal format!");
	   document.frmcontact.name.value="";
       return false;
       }
    } // end scanning loop
alert('ok!'); 
return true;
}

function encodeMyHtml(entry) {
     encodedHtml = unescape(entry.value); 	 
	 /*
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40"); 
	 */	 
     if(entry.value != encodedHtml)
	 entry.value = "";
   } 

function checkSpace(box)
{
	var val = box.value
	var carCode = event.keyCode;
	
	if(val=="")
	{			
		if ( carCode == 32) 
		{			
			event.cancelBubble = true;
			event.returnValue = false;
			return;
		}
	}	
}

function OpenPopupForPrint(file)
{
	win = window.open(file,'Popup','width=800,height=650,scrollbars=1,resizable=1');
	WindowXPosition(800,650,win);
}

function numbersonly(e)
{
	var unicode = e.charCode ? e.charCode : e.keyCode;
	
	if( unicode != 8 && unicode!=46 && unicode!=43)   //if the key isn't the backspace key (which we should allow)
	{
		if(unicode < 48 || unicode > 57)   //if not a number
				return false;  //disable key press
		else
			return true;   // enable keypress
	}
	else
	{
		return true;   // enable keypress
	}
}
