// JavaScript Document

function formData2QueryString(docForm) {
	var submitContent = '';
	var formElem;
	var lastElemName = '';

	for (i = 0; i < docForm.elements.length; i++) {
		formElem = docForm.elements[i];
		if(formElem.disabled) continue;
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'submit':
			case 'select-one':
				submitContent += formElem.name + '=' + escape(formElem.value) + '&'
				break;
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					submitContent += formElem.name + '=' + escape(formElem.value) + '&'
				}
				break;
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == lastElemName) {
						// Strip of end ampersand if there is one
						if (submitContent.lastIndexOf('&') == submitContent.length-1) {
							submitContent = submitContent.substr(0, submitContent.length - 1);
						}
						// Append value as comma-delimited string
						submitContent += ',' + escape(formElem.value);
					}
					else {
						submitContent += formElem.name + '=' + escape(formElem.value);
					}
					submitContent += '&';
					lastElemName = formElem.name;
				}
				break;
		}
	}
	// Remove trailing separator
	submitContent = submitContent.substr(0, submitContent.length - 1);
	return submitContent;
}

var responseText;
	        
function xmlhttpGet(strURL, strSubmit, strResultFunc,id) {
	
	        var xmlHttpReq = false;
	        // Mozilla/Safari
	    if (window.ActiveXObject) {
	                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	        }
		else if (window.XMLHttpRequest) {
	                xmlHttpReq = new XMLHttpRequest();
	                xmlHttpReq.overrideMimeType('text/xml');
	        }
	        xmlHttpReq.open('POST', strURL, true);
	        xmlHttpReq.setRequestHeader('Content-Type',
			     'application/x-www-form-urlencoded');
	        xmlHttpReq.onreadystatechange = function() {
	                if (xmlHttpReq.readyState == 4) {
	                	//performing our things
	                	responseText=xmlHttpReq.responseText;
	                	eval(strResultFunc+"(responseText,'"+id+"')")
	 
	                 }
	
	        }
	        xmlHttpReq.send(strSubmit);
	}



function hide_object(obj){
        var cell = document.getElementById(obj);
        cell.style.display = "none";
}

function show_object(obj){
        var cell = document.getElementById(obj);
        cell.style.display = "block";
}



function gwsol_contact_us(formName,divID){
	
	frm=document.getElementById (formName);
	
	hide_object('err_name');
	hide_object('err_email');
	hide_object('err_txt');
	
	ok=!(frm.name.value==""||frm.email.value.indexOf("@")==-1||frm.txt.value=="");
	
	if(frm.name.value=="") show_object('err_name');
	if(frm.email.value.indexOf("@")==-1) show_object('err_email');
	if(frm.txt.value=="") show_object('err_txt');
	
	if(ok){
	
		submit=formData2QueryString(frm);
		//alert (submit);
		xmlhttpGet("http://www.myvideo.co.za/contact.ajax.php", submit, "callback_wrapper",divID);
		
		
	}
	
}


function gwsol_send_report(formName,divID){
	frm=document.getElementById (formName);
	submit=formData2QueryString(frm);
	//alert (submit);
	xmlhttpGet("http://www.myvideo.co.za/report.ajax.php", submit, "callback_wrapper",divID);
}




function callback_wrapper(responseText,obj){
	
	cell=document.getElementById(obj);
	//alert ("obj="+obj+"; cell="+cell);
	//alert(responseText);
	cell.innerHTML=responseText;
	
	
}







function showHideObj(objToShow,objToHide){
	var obj = document.getElementById(objToShow);
	if (obj.style.display != 'block') obj.style.display = 'block';
	else obj.style.display = 'none';

	var obj2hide = document.getElementById(objToHide);
	if (obj2hide.style.display != 'none') obj2hide.style.display = 'none';
	else obj2hide.style.display = 'block';
}





function gwsol_get_last_video(vid,sessUID,divID){
	cell=document.getElementById(divID);
	cell.innerHTML='<div class="channelAjaxLoading"></div>';
	if (sessUID=='') sessUID=0;
	submit='&vid='+vid+'&sess='+sessUID;
	var file = location.pathname;
	_uacct = "UA-444621-3";
	urchinTracker(file);
	//alert ("urchinTracker("+file+")");
	//alert(submit);
	xmlhttpGet("http://www.myvideo.co.za/channel-lastvideo.ajax.php", submit, "callback_wrapper",divID);
}

function gwsol_get_last_video_Nokia(vid,sessUID,divID){
	cell=document.getElementById(divID);
	cell.innerHTML='<div class="channelAjaxLoading"></div>';
	if (sessUID=='') sessUID=0;
	submit='&vid='+vid+'&sess='+sessUID;
	var file = location.pathname;
	_uacct = "UA-444621-3";
	urchinTracker(file);
	//alert ("urchinTracker("+file+")");
	//alert(submit);
	xmlhttpGet("http://www.myvideo.co.za/channel-lastvideo.ajax_Nokia.php", submit, "callback_wrapper",divID);
}






