
//var postLocation="pgbar.php";

var postLocation="/cgi-bin/progress.cgi";

var re = /^(\.php)|(\.sh)/;  // disallow shell scripts and php

var dofilter=true;

function check_types() {

	if(dofilter==false)

		return true;

	with(document.photo)

	{
		for(i=0 ; i < elements.length ; i++)

		{

			if(elements[i].value.match(re))

			{

				alert('Sorry ' + elements[i].value + ' is not allowed');

				return false;

			}

		}

	}

	return true;

}

function popUP(mypage, myname, w, h, scroll, titlebar)

{



	/*var winl = (screen.width - w) / 2;

	var wint = (screen.height - h) / 2;

	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'

	win = window.open(mypage, myname, winprops)

	if (parseInt(navigator.appVersion) >= 4) {

		win.window.focus();

	}*/

//document.getElementById('pbar').innerHTML = "<iframe src='http://emily.cryer.org.uk'></iframe>";
//window.frames[bar].location ='http://productphotography.com.au'+mypage
document.getElementById('bar').src ='http://onlineprintshop.com.au'+mypage;

//document.all.bar.src='http://productphotography.com.au'+mypage;
 //document.write('test..'); 
}

function postIt()

{   

	if(check_types() == false)

	{

		return false;

	}

	baseUrl = postLocation;

	sid = document.photo.sessionid.value;

	iTotal = escape("-1");

	baseUrl += "?iTotal=" + iTotal;

	baseUrl += "&iRead=0";

	baseUrl += "&iStatus=1";

	baseUrl += "&sessionid=" + sid;

	popUP(baseUrl,"Uploader",460,262,false,false);

	document.photo.submit();

}



var fileNum=1;
var imageNum = 2;
function morePhotos(f) {
var fileInput = document.getElementById('cloneMe').cloneNode(true), label = fileInput.getElementsByTagName('label')[0], input = fileInput.getElementsByTagName('input')[0], beforeMe = document.getElementById('beforeMe');

fileInput.id = '';
label.setAttribute('for', 'image' + imageNum);
while(label.lastChild) {
label.removeChild(label.lastChild);
}
if(imageNum <=12){
label.appendChild(document.createTextNode(' File ' + imageNum + ' '));
var fnum=fileNum++;
input.id = 'file' + imageNum++;  input.name = 'file[' + fnum+']';
beforeMe.parentNode.insertBefore(fileInput, beforeMe);
}
else document.getElementById('max').innerHTML='<b>Maxmin '+(1*imageNum-1)+' photos only</b>';
}

function validateOnSubmit(theForm) {
var reason = "";
    reason += validateEmail(theForm.customer_email);
	reason += validateEmpty(theForm.customer_name);
	
	
  
  if (reason != "") {
    
	document.getElementById("incorrectfield").innerHTML="<p>The yellow fields have been filled incorrectly</p>";
    return false;
  }
else {
  
  return true;
  }
}

function validateEmpty(fld) {
    var error = "";  
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The yellow field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function supperTab(d,e){
 if (e.which=='13'){
 e.preventDefault()
 d.focus();
 
 }
 if (e.keyCode=='13'){
 e.returnValue=false;
  d.focus();
 }
 }


