var win=null;

// OPEN POP UP WINDOW
function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random") {
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	
	if(pos=="center") { 
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	
	else if((pos!="center" && pos!="random") || pos==null) {
		LeftPosition=0;TopPosition=20
	}
	
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}


// CONFIRM DELETEION
function ConfirmChoice(section, id) {
	answer = confirm("Do you really want to delete this item?")

	// IF ANSWER IS TRUE THEN DO THE FOLLOWING
	if (section=='pdf' && answer) {
		location = "http://www.pmc-speakers.com/admin/admin_awards.php?mode=deleteAward&award_id="+ id;
	}
	
	else if (section=='show' && answer) {
		location = "http://www.pmc-speakers.com/admin/admin_shows.php?mode=deleteShow&show_id="+ id;
	}
	
	else if (section=='showImage' && answer) {
		location = "http://www.pmc-speakers.com/admin/admin_shows.php?mode=deleteShowImage&show_id="+ id;
	}
	
	else if (section=='review' && answer) {
		location = "http://www.pmc-speakers.com/admin/admin_awards.php?mode=deleteReview&award_review_id="+ id;
	}
	
	else if (section=='keyclients' && answer) {
		location = "http://www.pmc-speakers.com/admin/admin_keyclients.php?mode=deleteKeyclient&key_id="+ id;
	}
	
	else if(section=='press' && answer){
	location="http://www.pmc-speakers.com/company/press.php?mode=deletepress&pressid="+id ;	
	}
	
	else if(section=='hitlist' && answer){
		location="http://www.pmc-speakers.com/company/hitlist.php?mode=deletehitlist&hitid="+id;
	}
	
	else if(section == 'distribution' && answer){
		location="http://www.pmc-speakers.com/distribution/distribution.php?mode=deletedistribution&id="+id;

	}
	
	else if(section == 'productPDF' && answer){
		location="http://www.pmc-speakers.com/admin/admin_products.php?mode=deletePdf&pid="+id;

	}
	
	else if(section == 'productPDFDrawing' && answer){
		location="http://www.pmc-speakers.com/admin/admin_products.php?mode=deletePdfDrawing&pid="+id;

	}
	
	else if(section == 'deleteFeature' && answer){
		location="http://www.pmc-speakers.com/admin/admin_feature.php?mode=deleteFeature&feature_id="+id;

	}
	
	else if(section == 'deleteNewsletter' && answer){
		location="http://www.pmc-speakers.com/admin/admin_email.php?mode=deleteNewsletter&newsletter_id="+id;

	}
}



// CHECK CONTACT FORM 
function contactForm(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("email_title", "email_name", "email_from", "email_subject", "email_message");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Title", "Name", "Email address", "Subject", "Message");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}



// CHECK GUARANTEE FORM 
function guaranteeForm(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("product", "serial_number", "date_of_purchase", "name", "address_one", "post_code", "email", "purchased_from");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Product", "Serial number", "Date of Purchase", "Name", "Address One", "Post Code", "Email", "Purchased From");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}



// CHECK PRODUCT FORM 
function productForm(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("category", "product_title", "product_desc", "product_spec", "primary_image", "thumbnail_one", "thumbnail_two", "thumbnail_three", "thumbnail_four");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Category", "Product title", "Product description", "Product specification", "Primary image", "Thumbnail one", "Thumbnail two", "Thumbnail three", "Thumbnail four");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}