 /*  #################        HEADER INFORMATION        #####################
    ------------------------------------------------------------------------
    Purpose of page        : common functions
    Page Name              : function.js
    Version Information    : 1st version
    Output Page            : functional dependant
    Date & Time            : 30th June 2006
    Created By             : thaiguys.com team
    Modified               : 30th June 2006
    ------------------------------------------------------------------------
   #################        HEADER INFORMATION        ######################
  */

function addbookmark(pageurl,pagetitle)
  {
	         
			var agt=navigator.userAgent.toLowerCase();
			title="ThaiGuys.com=>"+pagetitle;
		    url="http://www.thaiguys.com/user/"+pageurl;
		   					
       if (agt.indexOf("firefox") != -1)
		   {
			  //if (window.sidebar)
			   // { 
				     window.sidebar.addPanel(title,url,"");
		       // }
			  
			}
			//if(navigator.vandor=="Apple")
		 
		else if (agt.indexOf("safari") != -1)

			{ 
			      alert(" Press(Apple-D) on your keyboard.");
                
			}
		else if((agt.indexOf("msie") != -1)&&(navigator.platform.indexOf('Mac')!=-1))
			{
				  alert(" Press(Apple-D) on your keyboard.");
			}
			
		 else if((agt.indexOf("msie") != -1)&&(navigator.platform.indexOf('Win')!=-1))
			{
			   //	if( window.external )
			    // { 
					 window.external.AddFavorite(url,title)
	    	    // }
		    }
		 
		 else if (agt.indexOf("netscape") != -1)
			{
				alert(" Press(Ctrl-D) on your keyboard.");
			}
		 else if (agt.indexOf("mozilla/5.0") != -1)
			{
				alert(" Press(Ctrl-D) on your keyboard.");
			}
		else if(agt.indexOf("opera") != -1)
			{
				if(window.opera && window.print)
		        { 
		           return true;
		        }
			}
			
}


function is_empty(obj, str)
{
  if ( (obj.type=="text") || (obj.type=="password") || (obj.type=="textarea") || (obj.type=="file"))
  {
    
     if(obj.value=="")
     {
	   alert('Please enter ' + str +'.');
	   obj.focus();
	   return true;
     }
  }
	
  if (obj.type=="select-one")
  {
	  if (obj.selectedIndex==0)
	  {
		  alert('Please select ' + str+ '.' );
		  obj.focus();
		  obj.select;
		  return true;
	  }
  }
  return false;
}


function isValidEmail(obj)
{
	if(!is_empty(obj, "Email")) {
		if(! echeck(obj.value) )
		{
			alert("Please enter valid Email.");
			obj.focus();
			return false;
		}
	}
	else
	{
		return false;
	}
	return true;
}

function isValidLoginId(obj)
{
	if(!is_empty(obj, "Login Id")) {
		if(! echeck(obj.value) )
		{
			alert("Please enter valid Login Id.");
			obj.focus();
			return false;
		}
	}
	else
	{
		return false;
	}
	return true;
}
/// Email Checking Pass
function echeck(str) {

   var at="@"
   var dot="."
   var lat=str.indexOf(at)
   var lstr=str.length
   var ldot=str.indexOf(dot)

   if (str.indexOf(at)==-1){
       return false
   }

   if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       return false
   }

   if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
       return false
   }

   if (str.indexOf(at,(lat+1))!=-1){
      return false
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      return false
   }

   if (str.indexOf(dot,(lat+2))==-1){
   return false
   }

   if (str.indexOf(" ")!=-1){
      return false
   }
   return true
}// End Function

function textarealimit(obj,limit)
{
	if(obj.value.length > limit)
	{
		alert("Maximum limit of textarea is "+limit);
		return true
	}

}
//removes the trailing spaces
function trim(pstrString)
{
  var intLoop=0;
  for(intLoop=0; intLoop<pstrString.length; )
  {
      if(pstrString.charAt(intLoop)==" ")
         pstrString=pstrString.substring(intLoop+1, pstrString.length);
      else
         break;
  }

  for(intLoop=pstrString.length-1; intLoop>=0; intLoop=pstrString.length-1)
  {
      if(pstrString.charAt(intLoop)==" ")
         pstrString=pstrString.substring(0,intLoop);
      else
         break;
  }
  return pstrString;
}


//Validation for Phone numbers

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

 function isInteger(s)
 {
   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
 var s=stripCharsInBag(strPhone,validWorldPhoneChars);
 return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//function zipcode validations
 function validatezip(zip)
 {
	 var valid = "0123456789-";
	 var hyphencount = 0;
	 var field=zip;
	 
	 if(field.length!=5 && field.length!=10) 
	  {
	   alert("Please Enter your 5 digit or 5 digit+4 zip code.");
	   return false;
	  }
	 for(var i=0; i < field.length; i++)
	 {
	  temp = "" + field.substring(i, i+1);
	   if(temp == "-") hyphencount++;
	   if(valid.indexOf(temp) == "-1") 
		   {
			 alert("Invalid zip code.");
			 return false;
		   }
	  if((hyphencount>1) || ((field.length==10) && ""+field.charAt(5)!="-"))
	   { 
		alert("Invalid Zip code");
		return false;
	   }
	 return true;
	 }
 }

//function zipcode validations
 function validatezip1(zip)
 {
	 var valid = "0123456789-";
	 var hyphencount = 0;
	 var field=zip;
	 
	for(var i=0; i < field.length; i++)
	 {
	  temp = "" + field.substring(i, i+1);
	   if(temp == "-") hyphencount++;
	   if(valid.indexOf(temp) == "-1") 
		   {
			 alert("Invalid zip code.");
			 return false;
		   }
		if((hyphencount>1) || ((field.length>10) ))
	   { 
		alert("Invalid Zip code");
		return false;
	   }
	 return true;
	 }
 }






 //function  validate date
function testdate(day,month,year)
{ 
	 var myDayStr = day;
	 var myMonthStr = month;
	 var myYearStr = year;
	 		 
	var myMonth = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

	var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;

	/* Using form values, create a new date object
	using the setFullYear function */
	var myDate = new Date();
	myDate.setFullYear( myYearStr, myMonthStr, myDayStr );
	//alert(myDate.getMonth());
	//alert(myMonthStr);
	if ( myDate.getMonth() != myMonthStr )
	{
		 alert( 'Sorry, "' + myDateStr + '" is NOT a valid date.' );
	}
	else
	{
	  //alert( 'Congratulations! "' + myDateStr + '" IS a valid date.' );
	   return true;
	}
  
}



//perfect email validation
function emailCheck(emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Invalid email Id.Please check @ and .'s)");
alert("Invalid Email id!");

return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
alert("Invalid Email id!");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
alert("Invalid Email id!");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("The username doesn't valid.");
alert("Invalid Email id!");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
 alert("Invalid Email id!");
//alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Invalid Email id!");
//alert("The domain name does not valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("Invalid Email id!");
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2)
{
	alert("Invalid Email id!");
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}



//URL validation Script
function validateurl(urlstr)
{
document.frm.txturl.value=trim(document.frm.txturl.value);
var b=document.frm.txturl.value;
if(b.match(/^http:\/\/\w+(\.\w+)*\.(\w{2}|com|net|org|mil|int|edu|gov|info|biz|coop|aero|pro|name|museum)(\/[\w\-\.])*$/) == null)
  {
       alert("Invalid URL.");
       return false;
  }
  else
 {
	  return true;
 }
}

//RAHUL
/* Following 2 routines set the color of the input boxes */
function fnCFocus(obj) 
{
	obj.style.backgroundColor = '#f2faff';
	obj.style.borderColor = '#116aaa';
	obj.style.color = '#000000';
}

function fnCBlur(obj) 
{
	obj.style.backgroundColor = '#ffffff';
	obj.style.borderColor = '#6caad6';
	obj.style.color = '#000000';
}

function jsIsNull(obj,objname)	{   ///    Abhishek
try{
	if (trim(obj.value) == "" || trim(obj.value) == " ")	{
			output = display('EMPTY_TEXT',objname);
			//obj.style.borderColor = _ERROR_COLOR_;
			return output;
	}
			return;
	}catch(e){}
}

//functions from jsfunction.js from recs and rips
_ERROR_COLOR_ = '#86b262';
_SELECT_CRITERIA_ = 'You have not selected any criteria.';
var dateseperator = '-';
var whitespace =" \t\n\r ";




function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function changedate_todbformat(obj)
{
	arr = obj.value.split(dateseperator);
	obj.value=arr[2]+dateseperator+arr[0]+dateseperator+arr[1];
}
function newwindow(page,companyname,combo,group,extra)
{
	var cname,ccombo,group;
		cname = companyname;
	if(combo!=0)
		ccombo = combo;
	if(group!=0)
		group = group;	
	if(extra!=0)
	window.open(page+'?companygroup='+group+'companycombo='+ccombo+extra+'&selcompany='+cname,'','scrollbars=1,left=10,height=700,width=1000,top=1')
	//document.frm.submit();
}

 function pointswindow(fileName)
{
  window.open(fileName,"NewWindow","toolbar=no,left=100,top=100,width=400,height=300,resizable=yes,scrollbars=no");
}

function redirect(page,companyname,combo,group,extra)
{
	document.frm.selcompany.value=companyname;
	if(combo!=0)
		document.frm.companycombo.value=combo;
	if(group!=0)
		document.frm.companygroup.value=group;	
	if(page!=0)
	document.frm.action = page;
	if(extra!=0)
	document.frm.action += extra;
//	alert(document.frm.companycombo.value);
	document.frm.submit();
}

function isEmpty(str) {  
	return ((str == null) || (str.length == 0) || (str == " "));
}

function isWhitespace(str) {
	var i;
	var flag
	if (isEmpty(str)) return true;		
	for (i = 0; i < str.length; i++) {   
		var c = str.charAt(i);
		if (whitespace.indexOf(c) == -1)
		return false
	}	
		return true;
}

function datedifference(obj1,obj2)
{	
	//convert to mm/dd/yy  from 
	arr=obj1.split(dateseperator);
//	obj1=arr[1]+"/"+arr[0]+"/"+arr[2];
	arr=obj2.split(dateseperator);
//	obj2=arr[1]+"/"+arr[0]+"/"+arr[2];
	date1 = new Date(obj1);
	date2 = new Date(obj2);
	diff = date1 - date2;
//	alert(obj1+' '+obj2+' '+diff);
	return diff;
}

function display(statement,obj_name)	{
	switch (statement)
	{
		//statement="Check the following information \n";
		case "EMPTY_TEXT":
			//statement="Enter "+obj_name.substr(0)+".";    //eg. Enter <<text box Name>>.    Abhishek
		      statement="- "+obj_name+".";    //eg. Enter <<text box Name>>.    Preetam
			break;
		case "UNSELECTED_COMBOBOX":
			statement="Select "+obj_name.substr(0)+".";   //eg. Select <<Combo box name>>.    Abhishek
			break;			
		case "INVALID_PHONE_FAX":
			statement="- Valid "+obj_name+" ( Only numeric characters with - + ( ) ).";   //eg. Select <<Combo box name>>.    Abhishek
			break;			
				case "INVALID_PHONE":
			statement="Invalid "+obj_name+". Only numeric characters with - + ( ) allowed." ;   //eg. Select <<Combo box name>>.    Abhishek
			break;			
		case "INVALID_NUMERIC":
			statement="- Valid "+obj_name+" ( Only numeric characters ).";   //eg. Select <<Combo box name>>.    Abhishek
			break;			
		case "INVALID_EMAIL":
			statement="- Valid "+obj_name+".";   //eg. Select <<Combo box name>>.    Abhishek
			break;			
		case "INVALID_URL":
			statement="- Valid "+obj_name+".";   //eg. Select <<Combo box name>>.    Abhishek
			break;
		case "INVALID_FROM_DATE":
			statement=obj_name+" should be greater than or equal to today's date";		
			break;
		case "INVALID_TO_DATE":
			statement=obj_name+" should be greater than or equal to Dispaly from";		
			break;
		case "INVALID_FROMTO_DATE":
			statement="- Valid "+obj_name+".";   //eg. Select <<Combo box name>>.    Abhishek
			break;
		case "INVALID_INPUT":
			statement="- Valid "+obj_name+".";   //eg. Select <<Combo box name>>.    Abhishek			break;			
			break;
		case "INVALID_CONFIRMPASSWORD":
			statement="- "+obj_name+" and confirm password should be same.";
			break;
		case "INVALID_AGELIMIT":
			statement="should be grater than 18 years old";
			break;
		case "INVALID_ANNI_DATE":
			statement=obj_name+" should be greater than or equal to Birth Date";		
			break;
	    case "INVALID_FROMLEAVE_DATE":
			statement=obj_name+" should be greater than or equal to From Date";		
			break;
		case "INVALID_PHOTO_TYPE":
			statement=obj_name+" Only.jpg/.jpeg/.gif/.bmp images allowed";		
			break;

		case "BACKSLASH_DOUBLEQUOTE":
			statement = "Backslash is not allowed in "+obj_name+"."
			break;	

		default:
				alert('[Error: jfunction.js] check the display function.');
		
	}//switch
	return statement+'\n';
}
function validateURL(obj)
{
	var objValue=obj.value;
	//var characters="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáéíóñúüæoå'#!¤ Å^ Æüæå»«øØ.-#:\\_()&%$@?=^~.+/ "
	var characters="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáéíóñúüæoå#!¤Å^Æüæå»«øØ.-#:\_()&%$@?=^~.+/"
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
					lTag = 1
			}
	}
	if(lTag == 1)
		//alert("Invalid website url");
		//	document.frm[obj.name].focus();
			return false
	else
			return true

}

//URL Validation
/*function isValidateURL(obj,msg)
{				
	var strurl= trim(obj.value);
	if (urlRegxp.test(strurl) != true)
	 {
	     alert('Unvalid URL');
	     return false;
	 }
	 else
	 	return true;
}*/


function isValidatechar(characters,obj,msg)
{
				var objValue=obj.value;
                var tmp
                var lTag
                lTag = 0
                temp = (objValue.length)
                for (var i=0;i<temp;i++)
                {
                        tmp=objValue.substring(i,i+1);
                        if(characters.indexOf(tmp)>=0)
                        {
                                lTag = 1
                                break;
                        }
                }
                if(lTag == 1)
				{
       				output = display('INVALID_EMAIL',msg)
					//obj.style.backgroundColor = _ERROR_COLOR_;//document.frm[obj.name].focus();		
                    return output;
				}				
                else
				{
			        return;
				}		
}


// function to check valid email
function IsEmail(InString) {
  //alert(InString)
	var left, right;
	if(InString.length==0) return(false);
	for(Count=0;Count<InString.length;Count++) {
		TempChar = InString.substring(Count,Count + 1);
		if("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@_-".indexOf(TempChar,0)==-1) return(false); 
	}
	if(InString.indexOf('@')< 1) return(false);
	if(InString.lastIndexOf('@')!= InString.indexOf('@')) return(false);
	left = InString.substring(0,InString.indexOf('@'));
	right = InString.substring(InString.indexOf('@') + 1,InString.length);
	if((!isDotExpression(left,0))||(!isDotExpression(right,1))) return(false);
	return(true);
}

function isDotExpression(InString,NeedsDot) {
	var dots,index,tmpNeedDot;
	dots=0;
	for(index=0;index<InString.length;index++) {
		if(InString.substring(index,index+1)==".") {
		if((index==0)||(index==InString.length-1)) return(false);
			dots ++;
			if(dots>1)tmpNeedDot=1;
			else tmpNeedDot=0;
			if(!isDotExpression(InString.substring(0,index),tmpNeedDot)) return(false);	
		}      
	}
	if((NeedsDot==1)&&(dots<1)) return (false);
	if(InString.length < dots * 2+1) return (false);
	return (true);
}


function sendemail()
{
	//Email.location.href= '../includes/mail.php';
	window.open('../includes/mail1.php','mail','width=400,height=200,left=300,top=250');
}

function IsEmailValid(obj,msg)
{
if(get = isValidatechar("\"'~`!#$%^&*()+=|\\:;<>,?/{}[]",obj,"E-mail address ( ''~`!#$%^&*()+=|\\:;<>,?/{}[]' not allowed )"))
	return get;
var lEmailId=obj.value;        var c1;        var c2;        var c3;        var c4;        var c5;        var c6;        var varlast;
        emlchar =lEmailId //.value;
        emlchar = emlchar.toLowerCase() ;
       /* if(trimstr(lEmailId)==-1) {
                return false;
        }*/

        c1 = emlchar.indexOf("@");
        c2 = emlchar.indexOf(".");
        c3 = occurs("@", lEmailId) ;
        c4 = emlchar.indexOf("-");
        c5 = occurs(" ", lEmailId) ;
        varlast = emlchar.lastIndexOf(".");
        //alert (emlchar.length);
        //alert (varlast);
                if (varlast+1 == emlchar.length ){
                        c6 = 0;
        }

// Explanation..
// c1== -1        @ must be present
// c2== -1        . must be present
// c1== 0        @ cannot come as first character
// c2== 0        . cannot come as first character
// c1==c2-1        @. back-to-back not allowed
// c1==c2+1        .@ back-to-back not allowed
// c3!=1        @ can occur only once
// (c4 != -1 && c4 < c1)                if hyphen present & comes before @ not allowed
// (c4 != -1 && c4 == emlchar.length-1) if hyphen present & comes as a last character not allowed

        if (c1==-1 || c2==-1 || c1== 0 || c2==0 || c1==c2-1 || c1==c2+1 || c3!=1 || (c4 != -1 && c4 == emlchar.length-1) || c5 >= 0 || c6 == 0)
        {
               // lEmailId.focus();
				output = display('INVALID_EMAIL',msg);
				//document.frm[obj.name].focus();		
				//obj.style.backgroundColor = _ERROR_COLOR_;
                return output;
        }

        if (emlchar.length < 5 || c1==emlchar.length - 1 || c2==emlchar.length - 1 )
        {
                //lEmailId.focus();
				output = display('INVALID_EMAIL',msg);
				//obj.style.backgroundColor = _ERROR_COLOR_;//document.frm[obj.name].focus();		
                return output;
        }

        tmpStr = "0123456789_-abcdefghijklmnopqrstuvwxyz" ;
        cnt = 0;
        i = emlchar.indexOf(".", cnt);

        while (true) {
                ch1 = emlchar.charAt(i-1) ;
                ch2 = emlchar.charAt(i+1) ;
                if (tmpStr.indexOf(ch1) == -1 || tmpStr.indexOf(ch2) == -1)
				{
      					output = display('INVALID_EMAIL',msg);
						//obj.style.backgroundColor = _ERROR_COLOR_;//document.frm[obj.name].focus();		
				        return output;
				}
                cnt = cnt + 1 ;
                i = emlchar.indexOf(".", cnt);
                if (i == -1)
                        break;
        }

        return;
}

/*function datedifference(obj1,obj2)
{
	date1 = new Date(obj1.value);
	date2 = new Date(obj2.value);
	diff = date1 - date2;
	return diff;
}*/

/*
FUNCTION CHECKS FOR NUMERIC DATA
Description:
			Fuction for checkin all numeric characters 
			so if the string contains characters from this set ,this function will return true
			else
			it will return false and call Display() fn for genetrating error message.
Paramters:	1: obj : form object		
			2: msg : control name which will be displayed at the time of error . 
*/
function jsIsAllNumeric(obj,msg)
{
				var objValue=obj.value;
                        lTempLength = objValue.length
                        lTempCounter = 0
                        lTempString = trim(objValue)
                        flag = false

                        do
                        {
                        if(lTempString.charAt(lTempCounter) == " ")
                        {
                                flag = false
                                break
                        }
                        else if(lTempString.charAt(lTempCounter) > 0 || lTempString.charAt(lTempCounter) < 9)
                                flag = true
                        else
                                {
                                        flag = false
                                        break
                                }
                                lTempCounter = lTempCounter + 1
                        }
                        while(lTempCounter <= lTempLength)

                        if(flag == true)
                                return;
                        else
						{
	                  			output = display('INVALID_NUMERIC',msg);
								//obj.style.backgroundColor = _ERROR_COLOR_;								
								return output;
						}		
}


/*
FUNCTION CHECKS FOR VALID PHONE NO.	
Description:
			Phone no or fax can contains all numeric characters with + - ( )
			so if the string contains characters from this set ,this function will return true
			else
			it will return false and call Display() fn for genetrating error message.
Paramters:	1: obj : form object		
			2: msg : control name which will be displayed at the time of error . 
*/
function jsValidatePhoneFax(obj,msg)
{
				var objValue=obj.value;
				//alert(objValue);
                var characters=" -()+1234567890"
                var tmp
                var lTag
                lTag = 0
                temp = (objValue.length)
                for (var i=0;i<temp;i++)
                {
                        tmp=objValue.substring(i,i+1)
                        if (characters.indexOf(tmp)==-1)
                        {
                                lTag = 1
                        }
                }
                if(lTag == 1)
				{
					 output = display('INVALID_PHONE',msg);
					 	alert(output);
						//obj.style.backgroundColor = _ERROR_COLOR_;//document.frm[obj.name].focus();		
                        return output;
				}		
                else
                        return ;
}

/*function fnCFocus(obj) { // abhishek
		obj.style.borderColor = '#86b262';
}// function */

function jsHasBackSlash_DoubleQuote(obj,objname)	{    /// Abhishek
//	if (obj.value.indexOf ("\\") > -1 ||  obj.value.indexOf ("\"")> -1) 	{		
	if (obj.value.indexOf ("\\") > -1 ) 	{		
			output = display('BACKSLASH_DOUBLEQUOTE',objname);
			//obj.style.backgroundColor = _ERROR_COLOR_;
		return output;
	}
	return;
}

function jsIsNull(obj,objname)	{   ///    Abhishek
try{
	if (trim(obj.value) == "" || trim(obj.value) == " ")	{
			output = display('EMPTY_TEXT',objname);
			//obj.style.borderColor = _ERROR_COLOR_;
			return output;
	}
			return;
	}catch(e){}
}

function jsIsNullTinyText(obj,objname)	{   
	if (trim(tinyMCE.getContent()) == "" || trim(tinyMCE.getContent()) == " ")	{
			output = display('EMPTY_TEXT',objname);
			obj.style.borderColor = _ERROR_COLOR_;
			return output;
	}
			return;
}

function change_date(obj)
{
	// from  mm dd yy to yy mm dd 
	arr = obj.value.split("/");
	obj.value = arr[2]+"-"+arr[0]+"-"+arr[1];	
	return;
}

function jsIsComboUnselected(obj,objname)	{  
	if (trim(obj.value) == "" || trim(obj.value) == " " || trim(obj.value) == "0" || trim(obj.value) == 0)	{
			output = display('UNSELECTED_COMBOBOX',objname);
			//obj.style.backgroundColor = _ERROR_COLOR_;
			return output;
	}
			return;			
}

function trim(pstrString)
{
        var intLoop=0;
        for(intLoop=0; intLoop<pstrString.length; )
        {
			if(pstrString.charAt(intLoop)==" ")
				pstrString=pstrString.substring(intLoop+1, pstrString.length);
			else
				break;
        }

        for(intLoop=pstrString.length-1; intLoop>=0; intLoop=pstrString.length-1)
        {
                if(pstrString.charAt(intLoop)==" ")
                        pstrString=pstrString.substring(0,intLoop);
                else
                        break;
        }
        return pstrString;
}

function occurs(ch, fieldname) {
        cnt         = 0
        flag        = 0
        for (i=0; i < fieldname.length; ++i) {
                if (fieldname.substring(i,i+1) == ch) {
                        cnt = cnt + 1 ;
                        flag= 1;
                }
        }
        if (flag == 1)
                return (cnt) ;
        else
                return (-1) ;
}

function jsChangeCity(value)
{
	document.frm.cmbcity.length = 1;
	index = 1;
	for(i=0;i<cityarray.length;i++)
	{
		if(cityarray[i][2] == value)
			document.frm.cmbcity.options[index++] = new Option(cityarray[i][1],cityarray[i][0]);
	}
}

 function isValidFirstDate(firstyr,firstmn,firstdt,secyr,secmn,secdt) {
   if(firstyr < secyr)
   {
     return false;
   }
     else if (firstyr > secyr)
     {
       return true;
     }
     else if (firstyr==secyr)
     {
			if(firstmn<secmn)
			{
			   return false;
			}
			else if (firstmn > secmn)
			{
				return true;
			}
            else
			{
			  if(firstdt < secdt)
			  {
				return false;
			  }
			  else if (firstdt >= secdt)
			  {
				return true;
			  }
        }//same month
    }//else yr same
}//Function To check whether First Greater Than Secojnd Ends Here

function isValidatePhone(phone)
{
	
				var objValue=phone;
                        lTempLength = objValue.length
                        lTempCounter = 0
                        lTempString = trim(objValue)
                        flag = false

                        do
                        {
                        if(lTempString.charAt(lTempCounter) == " ")
                        {
                                flag = false
                                break
                        }
                        else if(lTempString.charAt(lTempCounter) > 0 || lTempString.charAt(lTempCounter) < 9)
                                flag = true
                        else
                                {
                                        flag = false
                                        break
                                }
                                lTempCounter = lTempCounter + 1
                        }
                        while(lTempCounter <= lTempLength)

						return flag;
}


function jsFormsubmit(val)
{
	document.write("<form name='frmgen' method='post'>");
	document.write("<input type='hidden' name='lvid' value="+val+">");
	document.write("</form>");

	document.frmgen.action = "leave.php";
	document.frmgen.submit();
}

function jsFormsubmit1(val,filename)
{
	
	document.write("<form name='frmgen' method='post'>");
	document.write("<input type='hidden' name='genvar' value="+val+">");
	document.write("</form>");
	document.frmgen.action = filename;
	document.frmgen.submit();
	
}


function fneditnews(pagename,id,val)
{
    eval("document.frm."+id+".value="+val+";");
    document.frm.action=pagename+".php";
    document.frm.submit();
}

function fndeletenews(id)
{
  if (confirm("Do you want to delete the record?"))
	{
	   document.frm.page_action.value="newsdelete";
	   document.frm.delid.value=id;	
	   document.frm.submit();
	}
}

function fnchangestatus(status,id)
{
	if(status==1)
	{
	 if (!confirm("Do you want to deactivate the record?"))
	  return false;
	}
	else
	{
	 if (!confirm("Do you want to activate the record?"))
	   return false;
	}
	if(status==1)
		var changedstatus=0;
	else
		var changedstatus=1;
	document.frm.delid.value=id;	
	document.frm.hidstatus.value=changedstatus;	
	document.frm.page_action.value="newsstatus";
	document.frm.submit();

}
function CheckBlank(objname,alertmsg)
{
	for(var i=1;1;i++)
	{
		try
		{ 
			var obj = document.getElementById(objname+i);
			//alert(obj.id);
			if(obj.value=="")
			{
				alertMessage += "-"+alertmsg;
				obj.focus();
			}
		}
		catch(e)
		{
			break;
		}
	}
}

function openNewWindow(fileName)
{
  window.open(fileName,"NewWindow","toolbar=no,left=100,top=100,width=570,height=360,resizable=yes,scrollbars=yes");
}


function IsValidUsername(sText)
{
   var ValidChars="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
   var charflag=true;
   var Char; 
   for (i = 0; i < sText.value.length; i++) 
   { 
      Char = sText.value.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
              charflag = false;
   }
   return charflag;
    
   }

/*function ChkUrl(obj)
{
	s=obj.value;
	if(s.substr(0,11)!="http://www.")
			return false;
	else
		return true;
}*/
function showresult(file,page,querystring){
	if(querystring.length> 1) 	{
		if (querystring.indexOf("&page") >1)
				querystring = querystring.substr(0,querystring.indexOf("&page"));
		document.frm.action+="?"+querystring;
	}				
	document.frm.pageno.value=page;
	document.frm.submit();
	}


function CheckURL(obj)
{
	url=obj.value;

	var v = new RegExp(); 
	v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
	if(!v.test(url))
		return false;
	else
		return true;

}

function CreateBookmark() 
{ 
	title = "Recs & Rips.com";   
	// Blogger - Replace with <$BlogItemTitle$>   
	// MovableType - Replace with <$MTEntryTitle$> 
	url = "http://www.recsandrips.com";  
	// Blogger - Replace with <$BlogItemPermalinkURL$>   
	// MovableType - Replace with <$MTEntryPermalink$>  
	// WordPress - <?php bloginfo('url'); ?>	
	
	if (window.sidebar) 
	{ // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title, url,"");	
	} else 
	if( window.external ) 
	{ // IE Favorite		
		window.external.AddFavorite( url, title); 
	} else 
	if(window.opera && window.print) 
	{ // Opera Hotlist		
		return true; 
	} 
}

function getFileType(str)
	{
	  
		if(str.match(".gif")||str.match(".jpeg")||str.match(".jpg"))
				{
			      return true;
				}
		else 
	   	{
			   return false;
			}

 }

function getResumeType(str)
{
	if(str.match(".pdf")||str.match(".doc")||str.match(".txt")||str.match(".rtf"))
	{
		return true;
	}
	else 
	{
		return false;
	}
}


function checknumeric(obj)
{
	var str;
	var id=parseInt(obj.value);
	if(isNaN(id))
		return true;
	else
		return false;
}


function openUploadFiles()
{
	//alert("Coming Soon...!!!");
//	return false;
			obj = document.frm;	
			flgchk=obj.flg_local_main.value;	
			if(flgchk==0)
			{
			file_path=obj.cgi_path.value;
			}
			
			else{
			if (obj.purl.value=='www')
			{
				file_path=obj.cgi_path.value;
			}
			else	file_path=obj.cgi_path.value;
			}
			//alert(file_path);
			//file_path=obj.
			newwindow = window.open(file_path, 'Upload', 'resizable=no,scrollbars=yes,screenX=0,screenY=0,menubar=no,status=no,width=500,height=340,left=440,top=250,dependent');
			return ;
	
}

function openUploadFiles2(txtid)
{
	//alert("Coming Soon...!!!");
//	return false;
			obj = document.frm;	
			flgchk=obj.flg_local_main.value;	
			if(flgchk==0)
			{
			file_path=obj.cgi_path.value;
			}
			
			else{
			if (obj.purl.value=='www')
			{
				file_path=obj.cgi_path.value;
			}
			else	file_path=obj.cgi_path.value;
			}
			
			newwindow = window.open(file_path, 'Upload', 'resizable=no,scrollbars=yes,screenX=0,screenY=0,menubar=no,status=no,width=500,height=340,left=440,top=250,dependent');
			return ;
	
}


function openUploadFiles3()
{
	//alert("Coming Soon...!!!");
//	return false;
			obj = document.frm;	
			flgchk=obj.flg_local_main.value;	
			if(flgchk==0)
			{
			file_path=obj.cgi_path3.value;
			}
			
			else{
			if (obj.purl.value=='www')
			{
				file_path=obj.cgi_path3.value;
			}
			else	file_path=obj.cgi_path3.value;
			}
			//alert(file_path);
			
			//file_path=obj.
			newwindow = window.open(file_path, 'Upload', 'resizable=no,scrollbars=yes,screenX=0,screenY=0,menubar=no,status=no,width=500,height=340,left=440,top=250,dependent');
			return ;
	
}


//URL Validation
function isValidateURL(obj,msg)
{				
	var urlRegxp =   /^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|[a-zA-Z]{2,7})(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;%\$#\=~_\-]+))*$/; 
	
	var strurl= trim(obj.value);
	if (urlRegxp.test(strurl) != true)
	 {
	     alert('Invalid URL');
	     return false;
	 }
	 else
	 	return true;
}
//check special character
function IsValidUsername(sText)
{
   var ValidChars="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
   var charflag=true;
   var Char; 
   for (i = 0; i < sText.value.length; i++) 
   { 
      Char = sText.value.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
              charflag = false;
   }
   return charflag;
}

function isValidDateDiff(smalldate,bigdate)
{
  var smalldatearr =smalldate.split("-");
  var bigdatearr   =bigdate.split("-");  
      
  if((parseInt(bigdatearr[2])) > (parseInt(smalldatearr[2],10)))
     return true;
  else if((parseInt(bigdatearr[2],10)) == (parseInt(smalldatearr[2],10)))
  {
  	if((parseInt(bigdatearr[0],10)) > (parseInt(smalldatearr[0],10)))
  	 	  return true;
  	else if((parseInt(bigdatearr[0],10)) == (parseInt(smalldatearr[0],10)))
  	{	
       if((parseInt(bigdatearr[1],10)) >= (parseInt(smalldatearr[1],10)))    
     				return true;
    		else 
    			  return false;   
     }
     else
     	 return false;
  }  
  else
  		return false;
}

function IsDateGreater(newdt)
{
	var datearr =newdt.split("-");
	thedate = new Date();
		y=parseInt(datearr[2]);
		m=parseInt(datearr[0]);
		d=parseInt(datearr[1]);
		thedate.setFullYear(y,m-1,d);
		today=new Date();
		if(thedate > today)
			return false;
		else
			return true;	
}

function IsDateLess(newdt)
{
	var datearr =newdt.split("-");
	thedate = new Date();
		y=parseInt(datearr[2]);
		m=parseInt(datearr[0]);
		d=parseInt(datearr[1]);
		thedate.setFullYear(y,m-1,d);
		today=new Date();
		if(thedate < today)
			return false;
		else
			return true;	

}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}