function MM_openBrWindow(theURL,winName,features,checktype) 
{ //v2.0
  var docF=document.frmPage1;
  window.open(theURL + "?txtuser=" + docF.txtusername.value + "&email=" + docF.txtemail.value + "&chktype="+checktype,winName,features);
}

function UploadPop()
{
	w=window.open('../manager/akey_uploadcv.php?id=&camefromnew=1', 'myWindow','width=400,height=360');
	window.name='oldWindow';
	w.opener = window;
}

function UploadExpress()
{
        w=window.open('../manager/akey_uploadcv.php?id=&camefromnew=1&expressres=1', 'myWindow','width=400,height=360');
        window.name='oldWindow';
        w.opener = window;
}

function akey_isValidUserName(str)
{
	newStr = str.replace(/[a-z0-9.@_-]/ig, '');
	if (newStr == '')
		return true;
	else
		return false;
}

function akey_isValidEmail(stremail)
{
 	if (stremail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
		return false;
	else
		return true;
}

function akey_isValidFname(strfname)
{
	newStr = strfname.replace(/[a-z]/ig, '');
	if (newStr == '')
		return true;
	else
		return false;
}

function akey_isValidName(strfname)
{
	newStr = strfname.replace(/[a-z. ]/ig, '');
	if (newStr == '')
		return true;
	else
		return false;
}

function akey_isDigit(c)
{
		 return ((c >= "0") && (c <= "9"))
}

function akey_isInteger(iNumber)
{
	var i;
	iNumber=akey_trim(iNumber)
	if(iNumber=="")
		return false;
	for (i=0;i<iNumber.length;i++)
	{
		var c = iNumber.charAt(i);
	
		if (!akey_isDigit(c))
		{
			return false;
		}
	}
	
  	return true;
}

function akey_trim(inputString) 
{
	if (typeof inputString != "string") { return inputString; }
	
	var temp_str = '';
	temp_str = inputString.replace(/[\s]+/g,"");
	if(temp_str == '')
        	return "";	

	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") 
	{
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") 
	{
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) 
	{
	      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	}
	return retValue;
}

// returns false if input string has any space, else returns true
function akey_findSpace(strInput)
{
	var strTemp;
	strTemp = strInput.replace(/[\s]/g,"");

	if(eval(strTemp.length) == eval(strInput.length))
		return true;
	
	return false;
}

function akey_checkNumChars(eleId, maxLimit)
{
	var ele = document.getElementById(eleId);
	if (ele.value.length > maxLimit)
	{
		alert('Length of resume summary cannot be more than ' + maxLimit + ' characters.');
		ele.value = ele.value.substr(0, maxLimit);
	}
}

function akey_checkDate(day, month, year)
{
	// since jan equals one and not zero, hence thirteen elements in the array.  
	var no_of_days_in_month = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31)
	if (month >= 1 && month <= 12 && day >=  1 && day <= 31 && year >= 0)
	{ 
		//Handling february, special case. 
		if (month == 2)
		{
			if ( (year%4==0 && year%100 != 0) || year%400 == 0 )
				no_of_days_in_month[month]=29
		}

		if (day >= 1 && day <= no_of_days_in_month[month])
		{
			return true;
		} 
		else
		{
			return false;
		}

	}
	else
	{
		return false;
	}
}

function akey_checkValidSelection(formEle)
{
	var returnVal = true;

	for (var i = 0; i < formEle.length; ++i)
	{
		if (formEle[i].selected && formEle[i].value == "select")
		{
			alert("Please select a valid option.");
			formEle[i].selected = false; // deselect that option

			returnVal = false;

		}
	}

	return returnVal;
}

function akey_checkSelectionLimit(formEle, limit)
{
	var returnVal = true;

	var count = 0;
	for (var i = 0; i < formEle.length; ++ i)
	{
		if (formEle[i].selected)
		{
			if(formEle[i].value!="")
			{
				++count;
			}
			else
			{
				formEle[i].selected = false;
			}
			if (count > limit)
			{
				alert("You cannot select more than " + limit + " options!");
				returnVal = false;
				
				formEle[i].selected = false;
			}
		}
	}

	return returnVal;
}

// returns true if date 1 < date 2
function akey_checkDateRange(d1,m1,y1, d2,m2,y2)
{
	if (y1 > y2)
		return false;
	if (y1 < y2)
		return true;

	/* This length check is necessary before comparing them */
	if (m1.length == 1)
		m1 = "0" + m1;
	if (m2.length == 1)
		m2 = "0" + m2;
		
	if (m1 > m2)
		return false;
	if (m1 < m2)
		return true;

	/* This length check is necessary before comparing them */
	if (d1.length == 1)
		d1 = "0" + d1;
	if (d2.length == 1)
		d2 = "0" + d2;

	if (d1 && d2 && d1 >= d2) // if d1 & d2 are not 0, & d1 >= d2
		return false;

	return true;
}

function observerX(var1,act,script)
{
	
	// set the name of the form
        var docF=document.form1;
	// the script used to write the logs
        var url = "http://192.168.2.251/amresh/manager/akey_logmaker.php?";
        var http = getHTTPObject(); // We create the HTTP Object
	var _cookie = document.cookie;
	var _referrer = document.referrer;
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);

        var obj2,flag=0;

    while(flag<docF.elements.length)
    {
        if(docF.elements[flag].NAME==var1)
        {// resid
                obj2=docF.elements[flag];
		break;
        }
        flag++;
    }
	var rid = obj2.value;
	var _browser = browser + version;
	http.open("GET", url + "script=" + script + "&resid=" + rid + "&action="+act+ "&cookie="+_cookie + "&browser=" +_browser +"&referrer="+_referrer , true);

	http.send(null);
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.display= newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function showHideOtherOpenBox(callingDDId, openBoxId, otherString)
{
	otherString = (otherString == null) ? 'Other' : otherString;
	
	var callingDD = document.getElementById(callingDDId);
	var selI = callingDD.selectedIndex;
	if (callingDD[selI].value == otherString)
		changeObjectVisibility(openBoxId, '');
	else
		changeObjectVisibility(openBoxId, 'none');
}

function akey_checkTextLimit(eleId, lenEleId, eleLabel, maxlen)
{
	var ele = document.getElementById(eleId);
	var lenEle = document.getElementById(lenEleId);

	if (ele.value.length > maxlen) 
	{
		ele.value = ele.value.substring(0, maxlen);
//		alert('The length of ' + eleLabel + ' cannot be more than ' + maxlen + ' chars.');
		alert(eleLabel + ' can not exceed ' + maxlen + ' characters');
	}
	
	lenEle.value = maxlen - ele.value.length;
}

function akey_checkNoSelect(thisform)
{
	for(var i=0; i< thisform.options.length; i++) 
	{
		if(thisform.options[i].selected && thisform.options[i].value == "select") 
		{
			alert("Please select valid option.");
			thisform.options[i].selected = false;
			break;
		}
	}
}
/*
function akey_setCountryAreaCode(cntryDDId, currLocnDDId, cntryCodeBoxId, areaCodeBoxId)
{
	var cntryDD = document.getElementById(cntryDDId);
	var currLocnDD = document.getElementById(currLocnDDId);
	var cntryCodeBox = document.getElementById(cntryCodeBoxId);
	var areaCodeBox = document.getElementById(areaCodeBoxId);
	if (cntryDD[cntryDD.selectedIndex].value == "INDIA")
	{
		cntryCodeBox.value = "91";
		switch(currLocnDD[currLocnDD.selectedIndex].value)
		{
		case "Delhi":
			areaCodeBox.value="011";
			break;
		case "Mumbai":
			areaCodeBox.value="022";
			break;
		case "Kolkata":
			areaCodeBox.value="033";
			break;
		case "Chennai":
			areaCodeBox.value="044";
			break;
		case "Bangalore":
			areaCodeBox.value="080";
			break;
		case "Hyderabad":
			areaCodeBox.value="040";
			break;
		case "Allahabad":
			areaCodeBox.value="0532";
			break;

		default:
			areaCodeBox.value="";
		}
	}
	else
	{
		currLocnDD.value="Other";
		cntryCodeBox.value = "";
	}
}
/**/
function akey_setCountryAreaCode(cntryDDId, currLocnDDId, cntryCodeBoxId, areaCodeBoxId)
{
	
	countryCode = new Array();
	cityCode = new Array();
	
/* ****************		STD CODES FOR CITIES OF INDIA		**************** */	
	cityCode['Ahmedabad'] = "79";
	cityCode['Bangalore'] = "80";
	cityCode['Chennai'] = "44";	
	cityCode['Delhi'] = "11";
	cityCode['Hyderabad'] = "40";
	cityCode['Kolkata'] = "33";
	cityCode['Mumbai'] = "22";
	cityCode['Pune'] = "20";
/* ****************		ISD CODES		**************** */	
	countryCode["INDIA"] = "91";
/* ************************************************ */

	var cntryDD = document.getElementById(cntryDDId);
	var currLocnDD = document.getElementById(currLocnDDId);

	var cntryCodeBox = document.getElementById(cntryCodeBoxId);
	var areaCodeBox = document.getElementById(areaCodeBoxId);
	
	var selectedCountry =  cntryDD.options[cntryDD.options.selectedIndex].value;
	var selectedCity = currLocnDD.options[currLocnDD.options.selectedIndex].value;
	
	if(countryCode[selectedCountry]==null)
	{
		//if(akey_trim(cntryCodeBox.value)=="91")
			cntryCodeBox.value = "";
	}
	else
		cntryCodeBox.value = countryCode[selectedCountry];

	if(cityCode[selectedCity]==null )//&&akey_trim(areaCodeBox.value)=="")
	{
		areaCodeBox.value = "";
	}	
	else
		areaCodeBox.value = cityCode[selectedCity];
		

	if(selectedCountry!="INDIA" && selectedCountry!="select")
	{
		currLocnDD.value = "Other";
	}
	else
	if(selectedCountry=="select")
	{
		currLocnDD.value ="select";
	}
	
}

function showHideCityOpenBox(cityId, ocityId)
{
	cityDD = document.getElementById(cityId);
	
	var selI = cityDD.selectedIndex;
	if (cityDD[selI].value.match("Other") != null) // selected element contains "other", so show "ocity open box"
		changeObjectVisibility(ocityId, '');
	else
		changeObjectVisibility(ocityId, 'none');
}

// if cntry value is NOT india, then make selected value in city dd as "Other"
function akey_cntryChangedEvent(cntryVal, form_city_id, form_ocity_id)
{
	var cityEle = document.getElementById(form_city_id).options;
	
	if (cntryVal == "select")
	{
		cityEle.selectedIndex = 0;
		showHideCityOpenBox(form_city_id, form_ocity_id);
	}
	else if (cntryVal != 'INDIA')
	{
		cityEle.selectedIndex = cityEle.length - 1;
		showHideCityOpenBox(form_city_id, form_ocity_id);
	}
	else if (cntryVal == 'INDIA')
	{
		cityEle.selectedIndex = 0;
		showHideCityOpenBox(form_city_id, form_ocity_id);
	}
}

// if city value is NOT "Other", then make selected value in cntry dd as india
function akey_cityChangedEvent(cityVal,form_country_id,form_ocountry_id)
{
        if (cityVal != 'Other')
        {
                var cntryEle = document.getElementById(form_country_id);

                for (i = 0; i < cntryEle.length; ++i)
                {
                        if (cntryEle[i].value == "INDIA")
                        {
                                cntryEle.selectedIndex = i;
                                showHideOtherOpenBox(form_country_id,form_ocountry_id);
                                break;
                        }
                }
        }
}

function akey_isValidReferencePhone(iNumber)
{
	var returnval = true;
	for (i=0;i<iNumber.length;i++) {
                var c = iNumber.charAt(i);
                if (! (c == '+' || c == '-' || akey_isDigit(c))) {
                        returnval =  false;
			break;
		}
        }
	return returnval;
}


function akey_isAlphaNumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
	{
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		{
		}
		else	
		{
			return false;
		}
	}
	return true;
}

function setPointer(theRow, thePointerColor)
{
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        var theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    for (var c = 1; c < rowCellsCnt; c++) {
        theCells[c].style.backgroundColor = thePointerColor;
    }

    return true;
} // end of the 'setPointer()' function