// JavaScript Document
var path=location.href;
var path_grabber="http://optinaccelerator.com/contactsimporter4_1";
	//if(path.lastIndexOf("/")<path.length-1)
	path=path.substr(0,path.lastIndexOf("/"));
	
	function makeObject(){
	var x;
	if (window.ActiveXObject) {
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		x = new XMLHttpRequest();
	}
	return x;
}
var request = null;
function setrequest()
{
	var url = path_grabber+"/optin4_3_mails/importer_home.php";
	
	
	}
	
function divheight()
{
	
//var mainval =document.getElementById("mainhd").value;
var mc=document.getElementById("mainhd").value;
var id="hd"+mc;


var v=document.getElementById(id).value;

document.getElementById("mainhd").value= v;
var totalcount = document.getElementById("mainhd").value;

//document.getElementById("mainhd").value = totalcount;

var total = 400;
countedheight = eval(totalcount * 32);

if(countedheight < total)
{
total=countedheight;
}

document.getElementById("contacts").style.height=total+'px';

}

function WriteToFile(sText)
{
	alert('Line1');
var fso = new ActiveXObject("Scripting.FileSystemObject");
	alert('Line2');
var FileObject = fso.OpenTextFile("C:\\LogFile.txt", 8, true,0); // 8=append, true=create if not exist, 0 = ASCII
	alert('Line3');
FileObject.write(sText)
	alert('Line4');
FileObject.close()
	alert('Line5');
}



function getrequest()
{
	
	if(request.readyState == 1){
		
		document.getElementById('msg').innerHTML = '<div style="color:#BC0909;"><b><i>Importing Contacts, Please Wait &nbsp;&nbsp;<img src="http://listviral.com/importing.gif" align="absmiddle"></i></b></div>';
	}
	else if(request.readyState == 4)
	{
		
		var text = request.responseText;
		if(text.indexOf('<input type="checkbox" id=')>0)
		{
			document.getElementById('chk').style.display='block';
			document.getElementById('msg').innerHTML = '';
			document.getElementById('contacts').innerHTML += text;
			
			divheight();
		}
		else
		{
			document.getElementById('msg').innerHTML = text;
		}
	

	}
}
	
	function importMail()
	{
		
		var mailadd="";
		var userid="";
		var pswd="";
				
		var wholeadd = document.getElementById("useremail").value;
		pswd=document.getElementById("pass").value;
		
		userid = wholeadd.substr(0,wholeadd.indexOf("@"));
		mailadd = document.getElementById("useremail").value;
		mailadd=mailadd.substring(mailadd.indexOf("@"));
		var p = "";
		
		mailadd=mailadd.toLowerCase();
		var mailadd1 = mailadd.substring(mailadd.indexOf("@")+1);
		var lib="";
		if(mailadd=="@hotmail.com")
		{
			
			p='M';
		}
		else if(mailadd=="@gmail.com")
		{
			
						p='G';
		}
				else if(mailadd=="@yahoo.com")
		{
			
						p='Y';
					
		}
				else if(mailadd=="@aol.com")
		{
		
						p='A';
					
		}
			
			else if(mailadd=="@rediffmail.com")
		{
		
						p='R';
					
		}
		else if(mailadd=="@lycos.com")
		{
						p='L';
					
		}
		else if(mailadd=="@mail.com")
		{
		
						p='M';
		}

request=null;
	request=makeObject();
	var str ="";

str = path+"/optin_mailimporter.php?update=1&username="+userid+"&password="+pswd+"&p="+p+"&hdfield="+document.getElementById("mainhd").value;

var timestamp = new Date();
  str = str+ (str.indexOf("?") > 0 ? "&" : "?")+ "timestamp="+ timestamp.getTime();

	document.getElementById('msg').innerHTML = '<div style="color:#BC0909;"><b><i>Importing Contacts, Please Wait &nbsp;&nbsp;<img src="http://listviral.com/importing.gif" align="absmiddle"></i></b></div>';
	request.onreadystatechange = getrequest;
	
	request.open('GET',str,true);
	
	request.send(null);
	
		return false;
		}
		
function checkstep1()
{
	if(document.getElementById("username").value=="")
	{
		alert("Please enter your name first");
		return false;
	}
	else if(document.getElementById("usermail").value=="")
	{
		alert("Please enter your email first");
		return false;
	}
	
	return true;
}

function checkweber()
{
	//alert(document.form1.name.value);
	if(document.getElementById("name").value=="")
	{
		alert("Please enter your name first");
		return false;
	}
	else if(document.getElementById("from").value=="")
	{
		alert("Please enter your email first");
		return false;
	}
	
	path=path+"/Sendmail.php?username="+document.getElementById("name").value+"&usermail="+document.getElementById("from").value;
	
	document.getElementById("redirect").value=path;
	
	return true;
}


function checkgetresponder()
{
	//alert(document.form1.name.value);
	if(document.getElementById("GRCategory2").value=="")
	{
		alert("Please enter your name first");
		return false;
	}
	else if(document.getElementById("GRCategory3").value=="")
	{
		alert("Please enter your email first");
		return false;
	}
	
	path=path+"/Sendmail.php?username="+document.getElementById("GRCategory2").value+"&usermail="+document.getElementById("GRCategory3").value;

	
	document.getElementById("confirmation").value=path;
	
	return true;
}

function checkshoppingcart()
{
	if(document.getElementById("Name").value=="")
	{
		alert("Please enter your name first");
		return false;
	}
	else if(document.getElementById("Email1").value=="")
	{
		alert("Please enter your email first");
		return false;
	}
	path=path+"/Sendmail.php?username="+document.getElementById("Name").value+"&usermail="+document.getElementById("Email1").value;

	document.getElementById("ARThankyouURL").value=path;
	return true;
}
function checkstep11()
{
	var flage=true;
	if(document.form1.username.value=="")
	{
		alert("Please enter your name first");
		flage=false;
	}
	else if(document.form1.usermail.value=="")
	{
		alert("Please enter your email first");
		flage=false;
	}
	if(flage==true)
	{
		flage=false;
		if(document.form1.sub1!=null) 
		{
			flage=document.form1.sub1.checked;
		}
		if(document.form1.sub2!=null&&flage!=true)
		{
			flage=document.form1.sub2.checked;
		}
		if(document.form1.sub3!=null&&flage!=true)
		{
			flage=document.form1.sub3.checked;
		}
		if(document.form1.sub4!=null&&flage!=true)
		{
			flage=document.form1.sub4.checked;
		}
		if(flage==false)
			alert("Please check at least one option");
	}
	return flage;
}


function checkfriend()
{
	var num=document.getElementById("numfriend").value;
	var req=document.getElementById("reqfriend").value;
	
	var imported = document.getElementById("mainhd").value;
	
	if(document.form1.username.value=="")
	{
		alert("Please Enter your Name");
		return false;
	}
	else if(document.form1.useremail.value=="")
	{
		alert("Please Enter your email address");
		return false;
	}
	else if(document.form1.subject.value=="")
	{
		alert("Please Enter email subject");
		return false;
	}
	else if(document.form1.message.value=="")
	{
		alert("Please Enter email message");
		return false;
	}
	else if(num>0)
	{
		var counter=0;
		for(i=0;i<imported;i++)
		{
			if(document.getElementById('chk'+i).checked==true)
			{
			counter++;
			}
		}
			
		for(i=0;i<num;i++)
		{
			if(counter>=req)
			{
				break;
			}
			
			var id="name"+i;
			var emailid="email"+i;
			if(document.getElementById(id).value==""||document.getElementById(emailid).value=="")
			{
				alert("Please fill friend Name and Email address");
				document.getElementById(id).focus();
				return false;
			}
			counter++;
		}
		return true;
	}	
}


var counter=0;

	function checkboxreq(chk)
	{
		var num=document.getElementById("numfriend").value;
		counter1=0;
		for(i=0;i<num;i++)
		{
			
			var id="name"+i;
			var emailid="email"+i;
			if(document.getElementById(emailid).value!="")
			{
				counter1++;
			}
			
		}
		
		if(chk.checked)
		{
				var limitedfriends=document.getElementById("limitedfriend").value;
				var globlecount =document.getElementById("mainhd").value;
				var req=document.getElementById("reqfriend").value;

				if(limitedfriends>0)
				{
					var condition = counter+counter1;
					if(condition>=limitedfriends)
					{
						alert("It's limited to only  "+limitedfriends+"  friends");
						chk.checked=false;
						return false;
					}
					else
					{
					counter++;
					}
				}
		}
		else 
		{
			counter--;
	   }
	return false;
	}

function checkall()
{

var totalcount =document.getElementById("mainhd").value;

for(i=0; i<totalcount;i++)
{
	
	document.getElementById('chk'+i).checked=true;
}
return false;
}

function pageredirect()
{
	var url=document.getElementById("thankpage").value;
	var uname=document.getElementById("username").value;
	url=url+"?Uname="+uname;
	location.href=url;
}

function uncheckall()
{
var totalcount =document.getElementById("mainhd").value;
for(i=0; i<totalcount;i++)
{
document.getElementById('chk'+i).checked=false;
}
return false;

}