// JavaScript Document

var arrA = new Array();
	
function showCompany(qnum)
{				
	var coname = window.prompt("In Which Company Interview you faced this Question?", "");	

	if( coname.length >= 2 )
	{
		document.location.href = '/classes/question.php?repeat&qnum='+qnum+'&comname='+coname;
	}
	else
	{
		alert("Please Enter Company Name");
		showCompany(qnum);
	}
	
}							


function EmailSelected()
{				
	if(arrA.length > 0)
	{
		var myemail = window.prompt("Please Enter Your E-MAIL ID to Receive Answers", "");
		var isValid = checkEmail(myemail); 
		
		if(isValid)
		{
			document.location.href = '/classes/email.php?abe&qnum='+arrA+'&myemail='+myemail+'&type=q';
		}	
	}
	else
	{
		alert("You didn\'t Selected any Question(s) to Receive Answers!!");
	}
		
}												


function checkEmail(elem) {
    
	var str = elem;	
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Enter Valid e-mail Address");
		EmailSelected();
        return false;
    } else {
        return true;
    }
}				



function addToList(val)
{			
	if(!isExisted(val))
	{
		arrA.push(val);		
	}	
} 



function isExisted(val)
{	
	for(i = 0; i <= arrA.length; i++)
	{
		if(arrA[i] == val)
		{			
			arrA.splice(i, 1);
			return 1;
		}
	}	
return 0;
}


function AnswerSelected()
{			
	if(arrA.length > 0 )
	{		
		document.uqaform.qarr.value = arrA;
		document.uqaform.qpath.value = location.href;
		document.uqaform.submit();
	}
	else
	{
		alert("You didn\'t Selected any Question(s) to Answer!!");
	}
}
