// JavaScript Document

 function popUpWindow(URLStr, left, top, width, height)
 {
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  
 }
 
 function trim(instr)
{
	var reFirst = /\S/;		// regular expression for first non-white char
	var reLast = /\s+$/;	// regular expression for first white char after last non-white char
	var firstChar = instr.search(reFirst);
	var lastChar = instr.search(reLast);
	
	if( lastChar == -1 ) 
		lastChar = instr.length;    	
	outstr = instr.substring( firstChar, lastChar );
	return outstr;
}

function isEmail(emailIn){
	var isEmailOk = false;
	var filter = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9-]+(\.[a-zA-Z][a-zA-Z-]+)+$/

	if(emailIn.search(filter) != -1)
		isEmailOk = true;
	if(emailIn.indexOf("..") != -1)
		isEmailOk = false;
	if(emailIn.indexOf(".@") != -1)
		isEmailOk = false;

	return isEmailOk;
} // Ends 



function validat()
{
if(document.adfrm.email.value.length<1)
 {
alert("Please Enter a valid email .");
document.adfrm.email.focus();
return false;
 }
if(!isEmail(trim(document.adfrm.email.value)))
 {
	alert("Email format is not correct. \nThe entry should be of type 'a@b.c'.");
	document.adfrm.email.focus();
	return false;
 }
return true;
}
function validate()
{
if(document.adfrm.opass.value.length<1)
{
alert("Please Enter old password .");
document.adfrm.opass.focus();
return false;
}
if(document.adfrm.npass.value.length<5)
{
alert("Please Enter new password of at least 5 digits.");
document.adfrm.npass.focus();
return false;
}
return true;
}

function vald()
{
if(document.adfrm.password.value.length<1)
{
alert("Please Enter new password of at least 5 digits.");
document.adfrm.password.focus();
return false;
}	
return true;
}


function valid()
{
if(!isEmail(trim(document.adfrm.cemail.value)))
{
	alert("Email format is not correct. \nThe entry should be of type 'a@b.c'.");
	document.adfrm.cemail.focus();
	return false;
}
if(!isEmail(trim(document.adfrm.supportemail.value)))
{
	alert("Email format is not correct. \nThe entry should be of type 'a@b.c'.");
	document.adfrm.supportemail.focus();
	return false;
}
if(!isEmail(trim(document.adfrm.paypal.value)))
{
	alert("Email format is not correct. \nThe entry should be of type 'a@b.c'.");
	document.adfrm.paypal.focus();
	return false;
}
return true;
}



function validates()
{
if(!isEmail(trim(document.adfrm.nemail.value)))
{
	alert("Email format is not correct. \nThe entry should be of type 'a@b.c'.");
	document.adfrm.nemail.focus();
	return false;
}
if(document.adfrm.napass.value.length<4)
{
alert("Please Enter password of at least 4 digits.");
document.adfrm.napass.focus();
return false;

}

if(document.adfrm.napass.value.length<4)
{
alert("Please Enter password of at least 4 digits.");
document.adfrm.napass.focus();
return false;
}
if(document.adfrm.cpass.value.length<1)
{
alert("Please confirm password.");
document.adfrm.cpass.focus();
return false;
}
if(document.adfrm.cpass.value!=document.adfrm.napass.value)
{
alert("Password did not match.");
document.adfrm.cpass.focus();
return false;
}

return true;

}
var perline = 9;
var divSet = false;
var curId;
var colorLevels = Array('0', '3', '6', '9', 'C', 'F');
var colorArray = Array();
var ie = false;
function check1(){
	if (document.fonts.TEXT_FONT.value == ""){ alert("Please privide text font name");return false;
	} else if (document.fonts.TEXT_COLOR.value == ""){ alert("Please privide text font color");return false;
	} else if (document.fonts.LINK_COLOR.value == ""){ alert("Please privide link color");return false;
	} else if (document.fonts.TITLE_FONT.value == ""){ alert("Please privide title font name");return false;
	} else if (document.fonts.TITLE_COLOR.value == ""){ alert("Please privide title font color");return false;
	} else if (document.fonts.PRICE_COLOR.value == ""){ alert("Please privide price color");return false;
	} else if (document.fonts.TEXT_COLOR.value.charAt(0)!='#' || document.fonts.LINK_COLOR.value.charAt(0)!='#' || document.fonts.TITLE_COLOR.value.charAt(0)!='#' || document.fonts.PRICE_COLOR.value.charAt(0)!='#' ){ alert("Invalid color code");return false;
	}else return true;
}
function check(){
	return confirm('Are you sure you want to restore default settings ? Click OK to continue') 
}
var nocolor = 'none';
if (document.all) { ie = true; nocolor = ''; }
function getObj(id) {
if (ie) { return document.all[id]; } 
else {	return document.getElementById(id);	}
}function addColor(r, g, b) {
var red = colorLevels[r];
var green = colorLevels[g];
var blue = colorLevels[b];
addColorValue(red, green, blue);
}function addColorValue(r, g, b) {
colorArray[colorArray.length] = '#' + r + r + g + g + b + b;
}function setColor(color) {
var link = getObj(curId);
var field = getObj(curId + 'field');
var picker = getObj('colorpicker');
field.value = color;
if (color == '') {
	link.style.background = nocolor;
	link.style.color = nocolor;
	color = nocolor;
} else {
	link.style.background = color;
	link.style.color = color;
}
picker.style.display = 'none';
eval(getObj(curId + 'field').title);
}
function setDiv() {     
if (!document.createElement) { return; }
var elemDiv = document.createElement('div');
if (typeof(elemDiv.innerHTML) != 'string') { return; }
genColors();
elemDiv.id = 'colorpicker';
elemDiv.style.position = 'absolute';
elemDiv.style.display = 'none';
elemDiv.style.border = '#000000 1px solid';
elemDiv.style.background = '#FFFFFF';
elemDiv.innerHTML = '<span style="font-family:Verdana; font-size:11px;">Pick a color: ' 
	+ '(<a href="javascript:setColor(\'\');">No color</a>)<br>' 
	+ getColorTable();
document.body.appendChild(elemDiv);
divSet = true;
}     function pickColor(id) {
if (!divSet) { setDiv(); }
var picker = getObj('colorpicker');     	
if (id == curId && picker.style.display == 'block') {
	picker.style.display = 'none';
	return;
}
curId = id;
var thelink = getObj(id);
picker.style.top = getAbsoluteOffsetTop(thelink) + 20 + "px";
picker.style.left = getAbsoluteOffsetLeft(thelink) + "px";     
picker.style.display = 'block';
}    function genColors() {
addColorValue('0','0','0');
addColorValue('3','3','3');
addColorValue('6','6','6');
addColorValue('8','8','8');
addColorValue('9','9','9');                
addColorValue('A','A','A');
addColorValue('C','C','C');
addColorValue('E','E','E');
addColorValue('F','F','F');                                
for (a = 1; a < colorLevels.length; a++)
addColor(0,0,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,a,5);
for (a = 1; a < colorLevels.length; a++)
addColor(0,a,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,5,a);
for (a = 1; a < colorLevels.length; a++)
addColor(a,0,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,a,a);
for (a = 1; a < colorLevels.length; a++)
addColor(a,a,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,5,a);
for (a = 1; a < colorLevels.length; a++)
addColor(0,a,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,5,5);
for (a = 1; a < colorLevels.length; a++)
addColor(a,0,a);			
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,a,5);
return colorArray;
}function getColorTable() {
var colors = colorArray;
var tableCode = '';
tableCode += '<table border="0" cellspacing="1" cellpadding="1">';
for (i = 0; i < colors.length; i++) {
if (i % perline == 0) { tableCode += '<tr>'; }
tableCode += '<td bgcolor="#000000"><a style="outline: 1px solid #000000; color: ' 
+ colors[i] + '; background: ' + colors[i] + ';font-size: 10px;" title="' 
+ colors[i] + '" href="javascript:setColor(\'' + colors[i] + '\');">&nbsp;&nbsp;&nbsp;</a></td>';
if (i % perline == perline - 1) { tableCode += '</tr>'; }
}if (i % perline != 0) { tableCode += '</tr>'; }
tableCode += '</table>';
return tableCode;
}function relateColor(id, color) {
var link = getObj(id);
if (color == '') {
link.style.background = nocolor;
link.style.color = nocolor;
color = nocolor;
} else {
link.style.background = color;
link.style.color = color;
}
eval(getObj(id + 'field').title);
}function getAbsoluteOffsetTop(obj) {
var top = obj.offsetTop;
var parent = obj.offsetParent;
while (parent != document.body) {
top += parent.offsetTop;
parent = parent.offsetParent;
}
return top;
}function getAbsoluteOffsetLeft(obj) {
var left = obj.offsetLeft;
var parent = obj.offsetParent;
while (parent != document.body) {
left += parent.offsetLeft;
parent = parent.offsetParent;
}
return left;
}

function validating()
{
if(document.adcat.acat.value.length<1)
{
alert("Please Enter Category Name");
document.adcat.acat.focus();
return false;
}
if(document.adfrm.avar.value.length<1)
{
alert("Please Enter Variable Name");
document.adfrm.avar.focus();
return false;
}
if(document.adfrm.aval.value.length<1)
{
alert("Please Enter Variable Value .");
document.adfrm.aval.focus();
return false;
}
return true;
}

function validater()
{
if(document.adfrm.uvar.value.length<1)
{
alert("Please Enter Variable name.");
document.adfrm.uvar.focus();
return false;
}
if(document.adfrm.uval.value.length<1)
{
alert("Please Enter Variable Value .");
document.adfrm.uval.focus();
return false;
}
return true;
}
//////////////////to check and uncheck all checkboxes
var str='';

function select_checked(form,obj)
 {
 
 	var selet=null;
	 
	if(obj.checked)
	{
	
	
	for (i = 0; i < form.elements.length; i++)
	 {
		var element = form.elements[i];
		if(element.type == 'checkbox')
		{									
			
			if(obj.name!=element.name)
			{
				element.checked=true;						
				if(str=='')
				str=element.value;
				else
				{
					var x=0;
					var temp = new Array();
					temp = str.split(',');
					
					for ( var j in temp )
					{
						if(temp[j]==element.value)
						{
							x=1;
						}
					} 
					
					if(x==0)
					str+=','+element.value;
					
				}
			}
		}
	}
	
	}
	else
	{		
		str='';
		for (i = 0; i < form.elements.length; i++)
		 {
			var element = form.elements[i];
			if (element.type == 'checkbox')
			{									
					element.checked=false;
					
			}
		}
	}
	
	}
//////////////////////////////AJAX TO manage listing in ads.php////////////////////////


 
function checks(form)
{	
    str='';
	
	 for (i = 0; i < form.elements.length; i++)
	 {
		
		
		var element = form.elements[i];
		if(element.type == 'checkbox')
		{									
			if(element.name!='checkbox2')
			{
				if(element.checked==true)
				{
					
					if(str=='')
					str+=element.value;
					else
					str+=','+element.value;
				
				}
			}
			else
			{
			element.checked=false;	
			}
		}
	
	
	}	

}

function xyz(paras)
 {
	
	//var site_path="http://project.softwaredep.com/08120K/"; 
    xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	var url="modify.php?id="+str+'&paras='+paras;
	

	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
 }
 
function stateChanged() 
{ 

    if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading")
	{ 
		//document.getElementById(active_city).innerHTML="Loading...."
	} 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	   window.location.href = window.location;
	  document.getElementById('ajax').innerHTML=xmlHttp.responseText
	} 
}



function GetXmlHttpObject(handler)
  {
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
	objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp 
  }

function homefun()
{

	if(document.home.homezoomlevel.value>20)
	{
	alert("Please see the limitation");
	document.home.homezoomlevel.focus();
	return false;
	} 
	return true;
}

function pagefun()
{

	if(document.page.pagezoomlevel.value>20)
	{
	alert("Please see the limitation");
	document.page.pagezoomlevel.focus();
	return false;
	} 
	return true;
}

function listing()
{

	if(document.list.maxpage.value.length>5)
	{
	alert("Please enter upto 5 digits");
	document.list.maxpage.focus();
	return false;
	} 
	if(document.list.maxresult.value.length>5)
	{
	alert("Please enter upto 5 digits");
	document.list.maxresult.focus();
	return false;
	} 
	return true;
}


 function checkIt(evt) {
       evt = (evt) ? evt : window.event;
       
       var charCode = (evt.which) ? evt.which : evt.keyCode;
       
       if (charCode > 31 && (charCode < 46 || charCode > 57))
       {
               status = "This field accepts numbers only."
			   alert('This field accepts numbers only');
               return false
       }
       status = ""
       return true
}


	
	
	
	
	
	
	
	
	
	
	
	
	

