// JavaScript Document

   var http_request = false;
   var spanname;
   var check;
   var checkbox;
   var chkspan;
   var frmname;
   var redirectURL;
   var isLogin=0;
   var frmButtonDiv='';
   var oldHTML='';
   var copiedOrderId='';
   
   
   function makePOSTRequest(url, parameters,span,frm,redir) {
      http_request = false;
	  frmname=frm;
	  redirectURL=redir;

	  
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
	  spanname=span;   

	  spanname.innerHTML="";
      http_request.onreadystatechange = alertContents;

      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
	  return 1;
	 
   }

   function alertContents(span,frm) {
//	  alert(http_request.readyState);
//	  alert(http_request.status);

      if (http_request.readyState == 4) {
		  
         if (http_request.status == 200) {
          

		result = http_request.responseText;
		
		   	

         if(frmButtonDiv!='')
		   document.getElementById(frmButtonDiv).innerHTML=oldHTML;
		
			
 		  
 $.unblockUI();
			
	       if(redirectURL!='' && result=='')
			  document.location.href=redirectURL;
		if(result=="success")
		{
		 document.getElementById('joindiv').style.display='none';document.getElementById('confirmdiv').style.display='';
		 document.activationFrm.active_email.value=document.regfrm.member_email.value;
		
		}
		else if(result=="activation")
		{//show_tabs(indtabs,4,"tlinksactive","toplinkstxt","");
		// document.getElementById('activationError').innerHTML="You need to activate your account to proceed";
		 //document.activationFrm.active_email.value=document.loginfrm.login_email.value;
		
		}
		else
		spanname.innerHTML = result; 
		
		return 1;
		
			
         } else {
            alert('There was a problem with the request.');
			jQuery.unblockUI();
         }
      }
   }
   
 
   
   function submitFrm(frm,fields,errordiv,url,redir)
   {
		var errors='',postStr="";
	  
	  errordiv.innerHTML='';
	   //validating
	   for(i=0;i<fields.length;i++) 
	   {// errors+="Please enter "+fields[i][1]+'<br />';
	     var req=0;
		
         document.getElementById(fields[i][0]).style.borderColor="#aaaaaa";
		if(fields[i][2]==1)
		{
			div= document.getElementById(fields[i][0]+'div');
			 if(div)
	   			div.innerHTML="";
			else
			{
				//creating div
		/*		var div=document.createElement('span');
				
				div.id=fields[i][0]+'div';
				//div.innerHTML='*';
				errordiv.appendChild(div);
				jQuery("#"+fields[i][0]+'div').insertAfter("#"+fields[i][0]);
				div.className='reqdiv';
				document.getElementById(fields[i][0]).className+=' divfloatlt';
				
				*/
				//alert(document.getElementById(fields[i][0]).getParentTag());
				}
		}
		 if(fields[i][3]==1)
		 {
				//var val=document.getElementById(fields[i][0]).value
				//alert (val);
		 if((document.getElementById(fields[i][0]).value=='' || document.getElementById(fields[i][0]).value==0) && fields[i][2]==1)
		 req=1;
			}
			if(fields[i][3]==2)
			{		
		  if((document.getElementById(fields[i][0]).value=="" && fields[i][2]==1))
			  req=1;			
			}
			if(fields[i][3]==3)
			{		
			
		  if((document.getElementById(fields[i][0]).checked=="" && fields[i][2]==1))
			  req=1;		
			  fieldname=document.getElementById(fields[i][0]);
			 getSelectedRadio(document.getElementById(fields[i][0]));
			}

			if(fields[i][3]==4)
			{		

		      if(fields[i][2]==1)
			  req=validateNumber(document.getElementById(fields[i][0]).value);
				
				
				
				}
				if(req==0)
				{
		//	if(fields[i][0].indexOf('mail')!=-1 && document.getElementById(fields[i][0]).value!='')
			//req=validateEmail(document.getElementById(fields[i][0]).value);
				}
			if(req==1)
		 {   //document.getElementById(fields[i][0]).className="frmfieldbgerr";

           document.getElementById(fields[i][0]).style.borderColor="#FF0000";

		  //   document.getElementById(fields[i][0]+'div').innerHTML="*";
		     
		 errors=1;
//		 alert(errors)
		 }
		  else
		  {

		   postStr+="&"+fields[i][0]+"="+document.getElementById(fields[i][0]).value;
		  }
		   
		   }  
//			alert(errors);
		   if(errors=='')
		   {
			 // alert(postStr);
jQuery.blockUI("<div class=processingtxt>Processing request, please wait...<br /><br /></div>" ); 

		if(url!='')
		    makePOSTRequest(url,postStr,errordiv,frm,redir);
        else
		{

		  frm.submit();
		}
			if(redir!='')
		     return 1;
			else
				return errors;
		//   frm.sbut.disabled=true;
		   }
		   else if(errors=='')
		   return 1;
		 //    errordiv.innerHTML=errors;
		   //else		   	  	     
	   //submitting form	   	   	   	   	   	   	   	   	   
	   }
		
		  function validateEmail(email)
		  {
			  if(email.indexOf('@')<3 || email.indexOf('.')<3)
  			    return 1;
		  }
			  
	function validateNumber(sText)
	{
		
		if(sText=='')
		 return 1;
		 
       var ValidChars = "0123456789.";
       var IsNumber=0;
       var Char;

 
   for ( var i = 0; i < sText.length && IsNumber == 0; i++) 
      { 
      Char = sText.charAt(i); 

      if (ValidChars.indexOf(Char) == -1) 
         {

         IsNumber = 1;
         }
      }
	 
   return IsNumber;

		
		}
		

function getSelectedRadio(radioName)
{

	for (var counter = 0; counter < radioName.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (radioName[counter].checked)
alert(radioName[counter].value);
}

	
	
	
	}


function getArtWorks(category_id,div,page)
{
	ajaxAppend('listprocess.php?category_id='+category_id+'&script=artwork&page='+page+"&div="+div,'#'+div);
	
	}
	
function searchArtWorks(div,page)
{
	ajaxAppend('listprocess.php?search_date_taken_year='+document.getElementById('search_date_taken_year').options[document.getElementById('search_date_taken_year').selectedIndex].value+'&search_date_copyright_year='+document.getElementById('search_date_copyright_year').options[document.getElementById('search_date_copyright_year').selectedIndex].value+'&search_date_added_year='+document.getElementById('search_date_added_year').options[document.getElementById('search_date_added_year').selectedIndex].value+'&search_date_taken_month='+document.getElementById('search_date_taken_month').options[document.getElementById('search_date_taken_month').selectedIndex].value+'&search_date_copyright_month='+document.getElementById('search_date_copyright_month').options[document.getElementById('search_date_copyright_month').selectedIndex].value+'&search_date_added_month='+document.getElementById('search_date_added_month').options[document.getElementById('search_date_added_month').selectedIndex].value+'&script=artwork&page='+page+"&div="+div+"&search_keywords="+document.getElementById('search_keywords').value,'#'+div);
	
	}	
	
	
	
	
	
	function getZazzle(div,page)
{
	ajaxAppend('listprocess.php?&script=zazzle&page='+page+"&div="+div,'#'+div);
	
	}
	
	function addToFav(artId)
	{
		jQuery.get('listprocess.php?script=addtofav&art_id='+artId, function(html) {
			document.getElementById("bookmark").innerHTML=html;
			//alert(html);
			}); 
		
		}
