// JavaScript Document

//-----------------------
function goback()
{window.history.back();}

//---------------
function displayform(form)
{document.getElementById(form).style.display = '';}

function hideform(form)
{document.getElementById(form).style.display = 'none';}

//----------------------
function publishedtoggle(site, id, action, productid)
{window.location = "http://174.132.129.156/~project2/administrator/details/publishedtoggle.php?site="+site+"&id="+id+"&action="+action+"&categoryid="+productid;}

//--------------------
function list(productid, target, action)
{if(productid != '' || productid != null){window.location = target+"&action="+action+"&productid="+productid;}}
////------------- for models features

function publishedtgofeatured(site, id, action, productid)
{if(action=='faqlist'){window.location = "publishedtgofeatured.php?site="+site+"&id="+id+"&action="+action+"&categoryid="+productid;}
 else{window.location = "publishedtgofeatured.php?site="+site+"&id="+id+"&action="+action+"&productid="+productid;}}

//--------------------
function list(productid, target, action)
{if(productid != '' || productid != null){window.location = target+"&action="+action+"&productid="+productid;}}

//------------------
function calculateprofit(id)
{
	profit = document.getElementById('resellerprice'+id).value - document.getElementById('superprice'+id).value;
	document.getElementById('superprofit'+id).value = profit; 
}
///// For Become models

function signintobecome(site, id, action, productid)
{if(action=='faqlist'){window.location = "signintobecome.php?site="+site+"&id="+id+"&action="+action+"&categoryid="+productid;}
 else{window.location = "signintobecome.php?site="+site+"&id="+id+"&action="+action+"&productid="+productid;}}

//--------------------
function list(productid, target, action)
{if(productid != '' || productid != null){window.location = target+"&action="+action+"&productid="+productid;}}

//------- Functions related to the importing contacts ------------
list = '';
eList = '';
state = true;

//-- moving contact from import list to list to send post --
function movecontact(email)
{
  	if(eList=='')
	{
		eList = email;
		list += email+"&nbsp;<img src=\"images/no.jpg\" width=\"15\" height=\"15\" onclick=\"removecontact('"+email+"')\"><br>";
	}
	else
	{
		eArr = eList.split(',');
		len = eArr.length;
		for(i=0; i<eArr.length; i++)
		{
			if(eArr[i] == email){state = false; break;}else{state = true;}
		}
		if(state==true)
		{
			eList = eList+","+email;
			list += email+"&nbsp;<img src=\"images/no.jpg\" width=\"15\" height=\"15\" onclick=\"removecontact('"+email+"')\"><br>";
		}
			   
	}
	document.getElementById('cpycntctlst').innerHTML = list;
}
  
//-- remove a contact from list to ready to send post --
function removecontact(email)
{
  	eArr = eList.split(',');
	eList = '';
	list = '';
	len = eArr.length;
	for(i=0; i<eArr.length; i++)
	{
		if(eArr[i] == email){continue;}
		else
		{
			if(eList=='')
			{
				eList = eArr[i];
				list += eArr[i]+"&nbsp;<img src=\"images/no.jpg\" width=\"15\" height=\"15\" onclick=\"removecontact('"+eArr[i]+"')\"><br>";
			}
			else
			{
				eList = eList+","+eArr[i];
				list += eArr[i]+"&nbsp;<img src=\"images/no.jpg\" width=\"15\" height=\"15\" onclick=\"removecontact('"+eArr[i]+"')\"><br>";
			}
		}
	}
	document.getElementById('cpycntctlst').innerHTML = list;	
}
  
//----- display importing fields if want to impor ----
function imprt_cntct()
{if(document.getElementById('y_contact')){document.getElementById('y_contact').id = "n_contact";document.getElementById('importcontact').style.display="";}else if(document.getElementById('n_contact')){document.getElementById('n_contact').id = "y_contact";document.getElementById('importcontact').style.display="none";}}
  
  //---- check for the fields for importing contacts ------
  function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmimprtcntct.txtEmail
	var passID=document.frmimprtcntct.txtPassword
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if ((passID.value==null)||(passID.value=="")){
		alert("Please Enter your Password")
		passID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
