
var hostName = 'http://www.veeyu.in';

function onLoadCommonFunction() {
	//MM_preloadImages('http://www.veeyu.in/admin_images/slide_right.jpg');
}

function popupWindow(path, where, hite, wide){
	if (window.event){ 
		window.event.returnValue = false;   
	}
	var width;
	var height;
	var imgWidth;
	var imgHeight;
	
	if (screen.width<wide){
		width=screen.width-20;
		imgWidth=width-10;
		var windowX = (screen.width-width)/2;
	}
	else{
		var windowX = (screen.width-wide)/2;
		width=wide;
	}

	if (screen.height<hite){
		height=screen.height-70;
		imgHeight=height-20;
		var windowY = (screen.height-height)/2-30;
	}
	else{
		var windowY = (screen.height-hite)/2-10;
		height=hite;
	}

	var rand_no = Math.random();
	var i = Math.round(100*Math.random());
	if(screen.height<hite || screen.width<wide){
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	else{
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=1,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	props.moveTo(windowX,windowY);
}


if(window.ActiveXObject) {
	try {
		var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e) {
		var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
} 
else {
	var oHTTP = new XMLHttpRequest();
}


/*******************************************************
For Check User Details
*******************************************************/
function checkUserName(){
	if(document.forms['userRegistration'].elements['user_name'].value==""){
		document.getElementById('textContentHTML').innerHTML = 'Please enter user name.';
		document.getElementById('theLayer').style.visibility = 'visible';	
		return false;
	}
	var userLoginName = document.forms['userRegistration'].elements['user_name'].value;
	var firstName = document.forms['userRegistration'].elements['first_name'].value;
	var lastName = document.forms['userRegistration'].elements['last_name'].value;
	
	checkUser(hostName+'/ajax_call.php?mode=check_username&user_name='+userLoginName+'&first_name='+firstName+'&last_name='+lastName+'');
}

function checkUser(page) {
	oHTTP.open("POST", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			document.getElementById('textContentHTML').innerHTML = getValue;
			document.getElementById('theLayer').style.visibility = 'visible';
		}
	}
	oHTTP.send(null);
}


function changeUsernameValue(val){
	document.forms['userRegistration'].elements['user_name'].value = val;
	hideMe(); 
	return false;
}

function totalvalue()
{
	if (document.forms['candidate'].elements['fixed_sal'].value != "")
	{
		if (document.forms['candidate'].elements['variable_sal'].value != "")
		{
		
			
		document.forms['candidate'].elements['total'].value = parseFloat (document.forms['candidate'].elements['fixed_sal'].value) + parseFloat (document.forms['candidate'].elements['variable_sal'].value);
		}
		else
		{
			document.forms['candidate'].elements['total'].value = parseFloat (document.forms['candidate'].elements['fixed_sal'].value);
		}
		var tot = document.forms['candidate'].elements['total'].value;
	}
	
	else
	{
		document.forms['candidate'].elements['total'].value  = '';
	}	
	
}
function join_totalvalue()
{
	if (document.forms['joinus'].elements['fixed_sal'].value != "")
	{
		if (document.forms['joinus'].elements['variable_sal'].value != "")
		{
		
			
		document.forms['joinus'].elements['total'].value = parseFloat (document.forms['joinus'].elements['fixed_sal'].value) + 	parseFloat (document.forms['joinus'].elements['variable_sal'].value) ;
		}
		else
		{
			document.forms['joinus'].elements['total'].value = parseFloat (document.forms['joinus'].elements['fixed_sal'].value)  ;
		}
		
	}
	else
	{
		document.forms['joinus'].elements['total'].value = '';
	}	
	
}

function apply_totalvalue()
{
	if (document.forms['apply'].elements['fixed_sal'].value != "")
	{
		if (document.forms['apply'].elements['variable_sal'].value != "")
		{
		
			
		document.forms['apply'].elements['total'].value = parseFloat (document.forms['apply'].elements['fixed_sal'].value) + 	parseFloat (document.forms['apply'].elements['variable_sal'].value) ;
		}
		else
		{
			document.forms['apply'].elements['total'].value = parseFloat (document.forms['apply'].elements['fixed_sal'].value)  ;
		}
		
	}
	else
	{
		document.forms['apply'].elements['total'].value = '';
	}	
	
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
if (num.length == 4)
{
	num = num.substring(0,num.length-(4*i+2))+'.'+
	num.substring(num.length-(4*i+2));
}
else if (num.length == 5)	
{
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
}

return (((sign)?'':'-') + num + '.' + cents);
}

function validate_for_integers(inputfield, inputevent) 
{
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	} else if (inputevent) {
		key = inputevent.which;
	} else {
		return true;
	}
	
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) ||
    		(key==9) || (key==13) || (key==27)) {
		return true;

	} else if (("0123456789").indexOf(keychar) > -1) {
		return true;
		
	} else {
		return false;
	}
}



var isNN =  (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}


function formatMoney(num, fractionsOk, withComma) 
{ 
  var n = ''; 
  var sNum; 
  var sep = withComma? ',' : ''; 
  var sSign=(num<0?'-':''); 
  if(fractionsOk) 
   sNum = formatnumber2(Math.abs(num), 2, -1) 
  else 
   sNum = Math.abs(num).toFixed(2); 
  for (var i = sNum.indexOf('.') - 3; i > 0; i -= 3) 
   n = sNum.substring(0, i) + sep + sNum.substring(i); 
  if(n!='') 
   return sSign+n 
  else 
   return sSign+sNum; 
} 
/*  
  formatnumber2: Formats a number with the indicated number of minimum digits following 
  the decimal point by adding extra 0's. Rounds off digits that exceed the 
  maxDigitsAfterDecimal parameter. If maxDigitsAfterDecimal==-1, then the function does 
  not round off any digits. 
*/ 
function formatnumber2(expression, minDigitsAfterDecimal, maxDigitsAfterDecimal) 
{ 
  var sReturn; 
  var vReturn; 
  var vValue; 
  var sPadding = ''; 
  var sSign = ''; 
  if(expression.toString().length==0) 
  { 
   vValue = 0; 
  } else if(!(isNaN(expression))) { 
   if(expression < 0) 
     sSign = '-'; 
   vValue = Math.abs(expression); 
  } else { 
   vValue = 0; 
  } 
  vReturn = vValue.toString().split('.'); 
  if(minDigitsAfterDecimal > 0) 
  { 
   for(i=0; i<minDigitsAfterDecimal; i++) 
     sPadding += '0'; 
   if(vReturn.length==1) 
   { 
     vReturn[1] = sPadding; 
   } else if(vReturn[1].length < minDigitsAfterDecimal) { 
     vReturn[1] = (vReturn[1] + sPadding).substr(0, minDigitsAfterDecimal); 
   } else { 
     if((vReturn[1].length > maxDigitsAfterDecimal) && (maxDigitsAfterDecimal!= -1)) 
     { 
      vReturn[1] = (Math.round(parseFloat(vReturn[1].substr(0,maxDigitsAfterDecimal+1))/10)).toString(); 
      //if the first digit(s) after the decimal point was a 0, it will have been lost in 
      //the above conversion. This while loop adds back any such 0 characters. 
      while(vReturn[1].length<maxDigitsAfterDecimal) 
        vReturn[1]='0'+vReturn[1]; 
      if(vReturn[1].length > maxDigitsAfterDecimal) 
      { 
        vReturn[0] = (parseInt(vReturn[0]) + 1).toString(); 
        vReturn[1] = sPadding; 
      } 
     } 
   } 
   if((vValue < 1) && (vValue!= 0) && (vReturn[0]!= '0')) 
     sReturn = '0' + vReturn[0] + '.' + vReturn[1]; 
   else 
     sReturn = vReturn[0] + '.' + vReturn[1]; 
  } else { 
   if(vReturn.length == 1) 
   { 
     if((vValue < 1) && (vValue!= 0)) 
     { 
      sReturn = '0' + (vReturn[0]); 
     } else { 
      sReturn = (vReturn[0]); 
     } 
   } else { 
     if((vReturn[1].length > maxDigitsAfterDecimal) && (maxDigitsAfterDecimal!= -1)) 
      vReturn[1] = (Math.round(parseFloat(vReturn[1].substr(0,maxDigitsAfterDecimal+1))/10)).toString(); 
     if((vValue < 1) && (vValue!= 0)) 
      sReturn = '0' + vReturn[0] + '.' + vReturn[1]; 
     else 
      sReturn = vReturn[0] + '.' + vReturn[1]; 
   } 
  } 
  return sSign + sReturn; 
}

function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
//alert(unicode);
if ((unicode!=8) && (unicode!=37) && (unicode!=39) && (unicode!=46)){ //if the key isn't the backspace, left arrow, right arrow key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}

function checkThis(field, e) {
	
    var val = field.value;
    
    var dotpos = 0;
    var founddot = 0;
    for (var i=0; i<val.length; i++) {
    	
    	if (val.charAt(i) == '.') {
        	founddot++;
            dotpos = i;
        }        
                
    }
    
    var unicode=e.charCode? e.charCode : e.keyCode
	//alert(unicode);
    
	if ((unicode!=8) && (unicode!=37) && (unicode!=39) && (unicode!=46)){ //if the key isn't the backspace, left arrow, right arrow key (which we should allow)
    	if (unicode<48||unicode>57) { //if not a number
    		return false; //disable key press
        }
        else {
        	
            if ((founddot == 0) && (val.length >= 2)){
                return false;
            }
            
        }
    } else {
    	if (unicode==46) {
        	if (founddot > 0) {
        		return false; //disable key press
            }            
        }
    } 
    
}

function convertThis(field, fractionsOk, withComma) {
	var val = field.value;
    
    var formatnum = formatMoney(val, fractionsOk, withComma);
    field.value = formatnum;
}


function calcTotal(formname, fractionsOk, withComma) {
	var val1 = document.forms[formname].elements['fixed_sal'].value;
    var val2 = document.forms[formname].elements['variable_sal'].value;
    
    var num = (val1*1) + (val2*1);
    //alert(num);
	var formatnum = formatMoney(num, fractionsOk, withComma);
    document.forms[formname].elements['total'].value = formatnum;
}


