// JavaScript Fucntions

//Author: PdQ

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function countWordsTitle(s) {
  var words = s.split(/\s+/);
  document.insert.wordcount1.value = words.length;
}

function countWordsDescription(s) {
  var words = s.split(/\s+/);
  document.insert.wordcount2.value = words.length;
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
	cntfield.value = maxlimit - field.value.length;
}

function confirmAction() {
    return confirm("By clicking I DO NOT agree all uploaded material and details entered up to this point will be deleted. \n\n If you are happy to do this then please click OK, otherwise click Cancel to resume the upload process.")
}

function ajaxsubmit(myImage) {
	
	if(window.XMLHttpRequest) {
			req = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	try
	{
	var radioLength = document.forms['voteform'].elements['voteforme'].length;

	for(var i = 0; i < radioLength; i++) {
			if(document.forms['voteform'].elements['voteforme'][i].checked) {
				voteVal = document.forms['voteform'].elements['voteforme'][i].value;
			}
		}
	
  	var imageID = myImage;
	var voteCode = document.getElementById('txtCode').value
	
	//alert(voteVal)
	//document.getElementById("votewaiting").style.display = 'block'; 
	
	req.open("GET", "savevote.asp?imageName="+imageID+"&imageVote="+voteVal+"&imageCode="+voteCode+"&imageVerify=W100T", true);
	req.onreadystatechange = triggered;
	req.send(null);
	
	} catch(e) {
		   //alert('doesnt work');
	}
  }
  
function triggered() { 
        if ((req.readyState == 4) && (req.status == 200)) {
				//document.getElementById("votewaiting").style.display = 'none'; 
				var totalstring = req.responseText.split("|")
				
				if (totalstring[0] == 'Thank you for rating this') {
				document.getElementById("starscore").innerHTML = totalstring[1]
				document.getElementById("votepanel").innerHTML = totalstring[0]; 
				document.getElementById("votestarholder").style.display = 'none'; 
				document.getElementById("voterightitle").style.display = 'none'; 
				} else {
				//document.getElementById("voteresponse").innerHTML = req.responseText; 
				alert(req.responseText)
				}
        }
}

