// JavaScript Document
/*window.onload = function () {

	$('form1').onsubmit = function () {
		inline_results();
		return false;	
	}
	
}

function inline_results() {
		postStr = "phonemodel="+$F('phonemodel')+"&imeino="+$F('imeino')+"&hidecnt="+$F('hidecnt')+"&selservices="+$F('selservices')+"&locktonetwork="+$F('locktonetwork')+"&comment="+$F('comment')
		cnt = $F('hidecnt')
		postStr+="&selmodel="+$F('selmodel')
		/*for (var i = 1; i < cnt;  i++)
		{
			postStr += "&imei"+i+"="+$F("imei"+i)
		}
		//alert(postStr);
		new Ajax.Updater ('userinfotable', base_url+'user/ajaxuserinfo', {method:'post', postBody: postStr });
		return false;
//	new Effect.Fade('errordiv',{duration:5});

}
function loadform(id)
{
		
	if(id==0 || id=='addn')
	{
		
		alert("please select service");
	}else
	{
		var postStr='selservices='+id	
		new Ajax.Updater('userform', base_url+'servicemanager/loaduserform', {method:'post', postBody: postStr });
	}
}
*/
function validate_first()
{
	if($('firstemail'))
	{
		if($F('firstemail')=="")
		{
			$('errordiv').innerHTML="Please enter email address";
			return false;
		}
		else if(!isValidEmail($F('firstemail')))
		{
			$('errordiv').innerHTML="Please enter valid email address";
			return false;	
		}
	}
	
}
function register_check()
{
	postStr=$F('email')+'/'+$F('uname');
	var resq=isValidEmail($F('email'))
	//postStr=resq;
	
	if(resq==true)
	{
		//location.href=base_url+'user/submitregister/'+postStr;
		new Ajax.Request("base_url+'user/submitregister/'+postStr", {method:'post', postBody: postStr , onSuccess:getvalue});
		
	}else
	{
		alert("Please Enter a valid email");
	}
}
function isValidEmail(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}
function changepass()
{
	if($('changepassdiv').style.display == 'none')
	{
		new Effect.BlindDown('changepassdiv');
		new Effect.BlindUp('coremodeldiv');
	}else
	{
		new Effect.BlindUp('changepassdiv');
		new Effect.BlindDown('coremodeldiv');
			
	}
}

function nowchangepass()
{
	var error = 'no';
	if($('txtoldpass'))
	{
		if($F('txtoldpass')=="")
		{
			new Effect.BlindDown('txtoldpasserr');
			error = 'yes';
		}
	}
	if($F('txtnewpass')=="")
	{
		new Effect.BlindDown('txtnewpasserr');
		error = 'yes';
	}else if($F('txtnewpass')!=$F('txtrepass'))
	{
		new Effect.BlindDown('txtrepassserr');
		error = 'yes';
	}
	if(error=='no')
	{
		if($('txtoldpass'))
		{
			postStr = "oldpass="+$F('txtoldpass')+"&newpass="+$F('txtnewpass')+"&txtrepass="+$F('txtrepass')				
		}else
		{
			postStr = "newpass="+$F('txtnewpass')+"&txtrepass="+$F('txtrepass')		
		}
		new Ajax.Updater('errordiv', base_url+'user/changepass', {method:'post', postBody: postStr });
		new Effect.BlindUp('changepassdiv');
		new Effect.BlindDown('coremodeldiv');
	}
}

/*************fucntion for pagination files*******************/
function pageNav(pagecount, pageno, totalrecords)
{
	var postStr = "pagecount="+pagecount+"&pageno="+pageno+"&totalrecords="+totalrecords
	new Ajax.Updater ('userinfotable_files',base_url+'user/usrcontrol_pg_files', {method:'post',postBody:postStr});
	//new Effect.BlindDown('userinfotable_files',{delay: .1, duration:1});
	return false;
}
function ajax_pagination(pagecount, pageno, totalrecords)
{
	var postStr = "pagecount="+pagecount+"&pageno="+pageno+"&totalrecords="+totalrecords
	new Ajax.Updater ('userinfotable',base_url+'user/codepagination', {method:'post',postBody:postStr});
	return false;
	
}
function searchcodes()
{
	var postStr = "searchkey="+$F('txtserch')
	new Ajax.Updater ('userinfotable',base_url+'user/searchcodes', {method:'post',postBody:postStr});
	new Effect.BlindDown('userinfotable',{delay: .1, duration:1});
	return false;
}

function addmore()
{
	cnt=document.getElementById('hidecnt').value;
	rqCredit = (parseInt(cnt)+1)*parseInt($F("txtc"));
	if (parseInt($F("ks_currCredits")) < rqCredit)
	{
		$('errordiv').innerHTML = "You do not have sufficient credits to add more IMEI."
		$('errordiv').style.display = 'block';
		new Effect.Fade('errordiv',{duration:9});
		return false;	
	}
	$('divaddmore').style.display = 'block';
	hidecredit = document.getElementById('hidecredit').value;
	newcnt1 = new Number(cnt);
	newcnt = newcnt1
	$imeival = $F('imeino');
	var arr_val = new Array();
	arr_val[0] = $imeival;
	for (var i=1; i< newcnt; i++)
	{
		arr_val[i] = document.getElementById('imeino'+i).value
	}
	newcnt++;
	str_dic = '';
	str_dic = document.getElementById('divaddmore').innerHTML
	if(document.getElementById('hidecredit').value > 1)
	{
		/*
		var arr_val = new Array();
		var tab = document.getElementById('divaddmore');
		tr = document.createElement('TR')
		td = document.createElement("TD") 
		txt = document.createElement("input")
		txt.setAttribute('type', 'text');
		txt.setAttribute('name', 'imei'+newcnt1.toString());
		txt.setAttribute('id', 'imei'+newcnt1.toString());
		txt.setAttribute('type', 'text');
		//txt = createNamedElement("input",'imei'+newcnt1.toString())
		td.appendChild(txt)
		tr.appendChild(td)
		tab.appendChild(tr)
		document.getElementById('hidecnt').value = newcnt;
			document.getElementById('hidecredit').value = hidecredit-1;*/
		if(newcnt1>1){
			//txt.setAttribute("name",'imei'+newcnt1.toString())
			//txt.setAttribute("id",'imei'+newcnt1.toString())				
			str_dic = str_dic+'<br /><input type="text" name="imeino'+newcnt1.toString()+'" id="imeino'+newcnt1.toString()+'" maxlength="15" onblur="validateimei(this.value, '+newcnt1+')"  value="">';
		}else
		{
			//txt.setAttribute("name",'imeino'+newcnt1.toString())
			//txt.setAttribute("id",'imeino'+newcnt1.toString())
			str_dic = str_dic+'<br><input type="text" name="imeino'+newcnt1.toString()+'" id="imeino'+newcnt1.toString()+'" maxlength="15" value="" onblur="validateimei(this.value, '+newcnt1+')">';
		}
			document.getElementById('hidecnt').value = newcnt;
			document.getElementById('hidecredit').value = hidecredit-1;
			document.getElementById('divaddmore').innerHTML = str_dic;
		for (var i = 1; i < arr_val.length ; i++ )
		{
			document.getElementById('imeino'+i).value = arr_val[i]
		}
		document.getElementById('imeino').value = arr_val[0]
	}else
	{
		alert("Sorry! You can not add more IMEI nos.");
	}	
}

function validateimei(id, rowid)
{
	
	//var arr_imei=new Array();
	//var result=$('imeino').value;
	
	
	//arr_imei=result.split("\n");
/*	for(i=0;i< arr_imei.length;i++)
	{
		alert(arr_imei[i])
	}*/
	
	

	var postStr = "imeicode="+id;
	var t='';
	new Ajax.Updater ('divforerror',base_url+'user/validateimei', {method:'post',postBody:postStr, onComplete:showmsg});
//	$('divforerror').style.display='block'
	return false;
}
function hideme_msg()
{
	$('divforerror').style.display='none'
	return false;
}
function hidenclear(rowid)
{
	if(rowid==0)
	{
		$('imeino').value=''	
	}else
	{	
		$('imeino'+rowid).value=''		
	}
	$('divforerror').style.display='none'
	return false;
}
function showmsg(t)
{
	if(t.responseText=='0')
	{
	}else
	{
		$('divforerror').style.display='block'
	}
}
function deleteuser(uid)
{
	if(confirm("You really want to delete this record"))
	{
		postStr="uid="+uid
		new Ajax.Updater ('registereduser',base_url+'user/deleteuser', {method:'post',postBody:postStr, onComplete:showmsg});
	//	$('divforerror').style.display='block'
		return false;
	}else
	{
		return false;
	}
}

function verifyimei(id)
{
	postStr="imeiid="+id
	new Ajax.Request(base_url+'login/verify', {method:'post',postBody:postStr});
	div = "ch"+id;
	$(div).innerHTML = "verifying";
	return false;
}
function activetemp_user(id)
{
	var postStr="tid="+id+"&value="+$F('btndelete'+id);
	new Ajax.Updater('temprecord', base_url+'user/activatetemp', {method:'post', postBody: postStr, onComplete:function(){upsuccess();}});		
}
