/**
 *	Common JavaScript
 * 	Created by Peter
 * 	Npedia Technologies 
 * 
 * */
function submitVal()
{
	if (document.getElementById("name").value=="")
	{
		alert("Enter your Name");
		document.getElementById("name").focus();
		return false;
	}
	if (document.getElementById("friend").value=="")
	{
		alert("Enter Friend Name");
		document.getElementById("friend").focus();
		return false;
	}
	if (document.getElementById("email").value=="")
	{
		alert("Enter Friend Email");
		document.getElementById("email").focus();
		return false;
	}
	if (echeck(document.getElementById("email").value)==false){
				document.getElementById("email").focus();
		return false;
	}
return true;
	
}

function nospaces(t){
	if(t.value.match(/[\s]{1,}/gi))	{
		alert('Sorry, you are not allowed to enter any spaces');
		t.value=t.value.replace(/[\s]{1,}/gi, '');
	}
}

/**
 * Relpace String , Only Allowed Number And Hypen ----Peter
 * */
function caps(v){
	v.value = v.value.replace(/([^0-9-])/g,"");
}


/**
 * Text Limit -- Peter
 * */
function textLimit(field, maxlen) {
	if (field.value.length > maxlen + 1)
	alert('Maximum Allowed '+maxlen+' letter');
	if (field.value.length > maxlen)
	field.value = field.value.substring(0, maxlen);
} 

/**
 * Email validation --- Peter
 * */

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 popup(mylink, windowname, height, width)
{
var height, width;
height=height;
width=width;
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
   //status = 1; 
//menubar = 0; 
//scrollbars = 1; 
//window.open("/","windowName","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=500");
window.open(href, windowname, 'width='+width+',height='+height+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
return false;
}

function check_ddl(val,id)
{
if(document.getElementById(id).checked == true) {
document.getElementById(val).disabled=false;
document.getElementById('Image26').disabled=false;
} else {
document.getElementById(val).disabled=true;
document.getElementById('Image26').disabled=true;
}
}

function check_ddl2(val,id){
if(document.getElementById(id).checked == true) {
document.getElementById('Image26').disabled=false;
} else {
document.getElementById('Image26').disabled=true;
}
}

var article = [];
var i;
function loadselection(topicId)
{
var strcookie=readCookie("featurecookie");
var i;
if (strcookie)
{
splitstrcookie = strcookie.split("-dl-");
for (i=0;i<=splitstrcookie.length-2;i++)
{
article[splitstrcookie[i]]=1;

document.getElementById(splitstrcookie[i]).checked=true;
}
}

}

function loadcookie(articleId)
{
if (document.getElementById(articleId).checked==true)
{
article[articleId]=1;
}
else if (document.getElementById(articleId).checked==false)
{
article[articleId]=0;
}
}

function savecookie()
{
var strsavecookie="";
for(i in article)
{
if (article[i]==1)
{
strsavecookie=strsavecookie+i+"dl";
}
}
createCookie("featuresavecookie",strsavecookie,1);
}
function savealert()
{
window.location.replace('ac-features_article.php');
alert("Feature articles saved successfully");
}


function readCookie(name) 
{
        var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
            {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value,days)
{
	if (days) 
        {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// End Feature article

// Placement Location
function savealert2()
{
window.location.replace('ac-placement_location.php');
//alert("Placement Location saved successfully");
}

function loadplacementcookie(articleId)
{
alert(document.getElementById(articleId).selected==true);
if (document.getElementById(articleId).selected==true)
{
alert(document.getElementById(articleId));
}
else if (document.getElementById(articleId).checked==false)
{

}

}

/**
 * Placement Location --- Peter
 * */


var xmlHttp;
function placementlocation(pos,artid,topid)
{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ac-placement_location_dbcheck.php";
url=url+"?pos="+pos+"&artid="+artid+"&topid="+topid;

	xmlHttp.onreadystatechange=function()
	{
	if(xmlHttp.readyState==4){
		var response=xmlHttp.responseText;
		strindexarr=response.split("-test-");
		
		loadindex(strindexarr[0],strindexarr[1],1);
	 }
	}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}




/**
 * Login Validation --- Peter
 * 
 * */

function loginValidation(){
	
	var user = document.getElementById('login-user').value;
	var pass = document.getElementById('login-pass').value;
	
	if(user==false){
		alert("Please enter your username");
		document.getElementById('login-user').focus();
		return false;
		
	}
	if(pass==false){
		alert("Please enter your password");
		document.getElementById('login-pass').focus();
		return false;
	}
	
	
}
function loadindex(strarticle,strlocation,test_var)
{
//alert(strarticle);
clearall();
	var strarticlearr;
	var i;
	if(strarticle!="")
	{	
	//alert(strarticle);
	
		strarticlearr=strarticle.split("-dl-");
		strindexarr=strlocation.split("-dl-");
//alert(strarticlearr.length);
		for(i=0;i<strarticlearr.length-1;i++)
		{		
		//alert(strarticlearr[i]);
			if(strarticlearr[i] != 0)
			{
				document.getElementById(strarticlearr[i]).value=strindexarr[i];
				if(test_var==0)
				{
				document.getElementById('loc'+strarticlearr[i]).value=strindexarr[i];
				}				
			}
		}
	}

}

function clearall()
{
for(i=0; i<document.placement.elements.length; i++)
{ 
if(document.placement.elements[i].type=="select-one")
{
if(document.placement.elements[i].id!="topic")
{
document.placement.elements[i].value="0";
}
}
}
}
